-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
29 deletions.
There are no files selected for viewing
17 changes: 0 additions & 17 deletions
17
packages/core/src/actions/account/public/get-base-asset.ts
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
packages/core/src/actions/account/public/get-base-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' | ||
import { CW20Token, NativeToken } from 'src/utils' | ||
import { VersionControlTypes } from '../../../codegen/abstract' | ||
import { getProxyQueryClientFromApi } from './get-proxy-query-client-from-api' | ||
|
||
function hasNativeField(base_asset: any): base_asset is { native: string } { | ||
return (base_asset as { native: string }).native !== undefined | ||
} | ||
|
||
function hasCw20Field(base_asset: any): base_asset is { cw20: string } { | ||
return (base_asset as { cw20: string }).cw20 !== undefined | ||
} | ||
|
||
export async function getBaseToken( | ||
accountId: VersionControlTypes.AccountId, | ||
cosmWasmClient: CosmWasmClient, | ||
apiUrl: string, | ||
) { | ||
const proxyQueryClient = await getProxyQueryClientFromApi( | ||
accountId, | ||
cosmWasmClient, | ||
apiUrl, | ||
) | ||
const { base_asset } = await proxyQueryClient.baseAsset() | ||
if (hasNativeField(base_asset)) | ||
return { | ||
denom: base_asset.native, | ||
type: 'native', | ||
} as const satisfies NativeToken | ||
if (hasCw20Field(base_asset)) | ||
return { | ||
address: base_asset.cw20, | ||
type: 'cw20', | ||
} as const satisfies CW20Token | ||
throw new Error('Invalid base asset') | ||
} |
9 changes: 3 additions & 6 deletions
9
packages/core/src/actions/account/public/get-module-address.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,19 @@ | ||
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate' | ||
import { | ||
ManagerQueryClient, | ||
VersionControlTypes, | ||
} from '../../../codegen/abstract' | ||
import { VersionControlTypes } from '../../../codegen/abstract' | ||
import { getManagerQueryClientFromApi } from './get-manager-query-client-from-api' | ||
|
||
export async function getModuleAddress( | ||
accountId: VersionControlTypes.AccountId, | ||
cosmWasmClient: CosmWasmClient, | ||
apiUrl: string, | ||
...params: Parameters<typeof ManagerQueryClient.prototype.moduleAddresses> | ||
id: string, | ||
) { | ||
const managerQueryClient = await getManagerQueryClientFromApi( | ||
accountId, | ||
cosmWasmClient, | ||
apiUrl, | ||
) | ||
const { modules } = await managerQueryClient.moduleAddresses(...params) | ||
const { modules } = await managerQueryClient.moduleAddresses({ ids: [id] }) | ||
|
||
return modules[0]?.[1] ?? null | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters