Skip to content

Commit

Permalink
fix: resolve review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dalechyn committed Jan 19, 2024
1 parent cee685a commit 134e3b7
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 29 deletions.
17 changes: 0 additions & 17 deletions packages/core/src/actions/account/public/get-base-asset.ts

This file was deleted.

36 changes: 36 additions & 0 deletions packages/core/src/actions/account/public/get-base-token.ts
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')
}
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
}
12 changes: 6 additions & 6 deletions packages/core/src/clients/decorators/account-public.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CosmWasmClient } from '@cosmjs/cosmwasm-stargate'
import { getAccountBaseAddressesFromApi } from '../../actions/account/public/get-account-base-addresses-from-api'
import { getBaseAsset } from '../../actions/account/public/get-base-asset'
import { getBaseToken } from '../../actions/account/public/get-base-token'
import { getManagerQueryClientFromApi } from '../../actions/account/public/get-manager-query-client-from-api'
import { getModuleAddress } from '../../actions/account/public/get-module-address'
import { getModules } from '../../actions/account/public/get-modules'
Expand All @@ -17,9 +17,9 @@ export type AccountPublicActions = {
getAccountBaseAddresses(
...args: SliceFirstThree<Parameters<typeof getAccountBaseAddressesFromApi>>
): ReturnType<typeof getAccountBaseAddressesFromApi>
getBaseAsset(
...args: SliceFirstThree<Parameters<typeof getBaseAsset>>
): ReturnType<typeof getBaseAsset>
getBaseToken(
...args: SliceFirstThree<Parameters<typeof getBaseToken>>
): ReturnType<typeof getBaseToken>
getManagerQueryClientFromApi(
...args: SliceFirst<Parameters<typeof getManagerQueryClientFromApi>>
): ReturnType<typeof getManagerQueryClientFromApi>
Expand Down Expand Up @@ -62,8 +62,8 @@ export function accountPublicActions(
apiUrl,
...args,
),
getBaseAsset: (...args) =>
getBaseAsset(accountId, cosmWasmClient, apiUrl, ...args),
getBaseToken: (...args) =>
getBaseToken(accountId, cosmWasmClient, apiUrl, ...args),
getManagerQueryClientFromApi: () =>
getManagerQueryClientFromApi(accountId, cosmWasmClient, apiUrl),
getModuleAddress: (...args) =>
Expand Down

0 comments on commit 134e3b7

Please sign in to comment.