Skip to content

Commit

Permalink
refactor(wallet-mobile): drop legacy fetch token info
Browse files Browse the repository at this point in the history
  • Loading branch information
stackchain committed Sep 12, 2024
1 parent 56c9ac9 commit 0ec075a
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 214 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,16 @@ import {SearchProvider} from '../../../../../../Search/SearchContext'
import {SwapFormProvider} from '../../../../../common/SwapFormProvider'
import {SelectBuyTokenFromListScreen} from './SelectBuyTokenFromListScreen'

storiesOf('Swap Select Token To Buy', module)
.add('initial', () => {
return (
<WalletManagerProviderMock wallet={mocks.wallet}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectBuyTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
.add('loading tokenInfo', () => {
const loading = {
...mocks.wallet,
fetchTokenInfo: mocks.fetchTokenInfo.loading,
}
return (
<WalletManagerProviderMock wallet={loading}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectBuyTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
storiesOf('Swap Select Token To Buy', module).add('initial', () => {
return (
<WalletManagerProviderMock wallet={mocks.wallet}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectBuyTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,16 @@ import {SearchProvider} from '../../../../../../Search/SearchContext'
import {SwapFormProvider} from '../../../../../common/SwapFormProvider'
import {SelectSellTokenFromListScreen} from './SelectSellTokenFromListScreen'

storiesOf('Swap Select Token To Sell', module)
.add('initial', () => {
return (
<WalletManagerProviderMock wallet={mocks.wallet}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectSellTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
.add('loading tokenInfo', () => {
const loading = {
...mocks.wallet,
fetchTokenInfo: mocks.fetchTokenInfo.loading,
}
return (
<WalletManagerProviderMock wallet={loading}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectSellTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
storiesOf('Swap Select Token To Sell', module).add('initial', () => {
return (
<WalletManagerProviderMock wallet={mocks.wallet}>
<SearchProvider>
<SwapProvider swapManager={mockSwapManager}>
<SwapFormProvider>
<SelectSellTokenFromListScreen />
</SwapFormProvider>
</SwapProvider>
</SearchProvider>
</WalletManagerProviderMock>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,3 @@ storiesOf('AssetList', module)
</QueryClientProvider>
)
})
.add('loading', () => {
return (
<QueryClientProvider client={new QueryClient()}>
<WalletManagerProviderMock wallet={{...mocks.wallet, fetchTokenInfo: () => new Promise(() => undefined)}}>
<AssetList assets={mocks.tokenEntries} onSelect={action('onSelect')} />
</WalletManagerProviderMock>
</QueryClientProvider>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const makeCardanoWallet = (
const appApi = AppApi.appApiMaker({baseUrl: networkManager.legacyApiBaseUrl})

// legacy
const {BACKEND, NETWORK_CONFIG, PRIMARY_TOKEN, PRIMARY_TOKEN_INFO, TOKEN_INFO_SERVICE} = constants
const {NETWORK_CONFIG, PRIMARY_TOKEN} = constants

return class CardanoWallet implements YoroiWallet {
readonly id: string
Expand Down Expand Up @@ -1083,12 +1083,6 @@ export const makeCardanoWallet = (
return legacyApi.getPoolInfo(request, networkManager.legacyApiBaseUrl)
}

fetchTokenInfo(tokenId: string) {
return tokenId === '' || tokenId === 'ADA' || tokenId === '.' || tokenId === this.portfolioPrimaryTokenInfo.id
? Promise.resolve(PRIMARY_TOKEN_INFO)
: legacyApi.getTokenInfo(tokenId, `${TOKEN_INFO_SERVICE}/metadata`, BACKEND)
}

async fetchFundInfo(): Promise<FundInfoResponse> {
return legacyApi.getFundInfo(networkManager.legacyApiBaseUrl, this.isMainnet)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Balance} from '@yoroi/types'

import {DefaultAsset} from '../../../types'
import {COIN_TYPE, COINS_PER_UTXO_WORD, KEY_DEPOSIT, MINIMUM_UTXO_VAL, POOL_DEPOSIT} from '../common'

Expand Down Expand Up @@ -65,21 +63,6 @@ export const NETWORK_CONFIG = {
COINS_PER_UTXO_WORD,
} as const

export const PRIMARY_TOKEN_INFO: Balance.TokenInfo = {
kind: 'ft',
id: '.',
name: 'ADA',
description: 'Cardano',
icon: '',
group: '',
ticker: 'ADA',
fingerprint: '',
decimals: 6,
image: '',
symbol: '₳',
metadatas: {},
} as const

export const PRIMARY_TOKEN: DefaultAsset = {
identifier: '.',
networkId: CHAIN_NETWORK_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Balance} from '@yoroi/types'

import {DefaultAsset} from '../../../types'
import {COIN_TYPE, COINS_PER_UTXO_WORD, KEY_DEPOSIT, MINIMUM_UTXO_VAL, POOL_DEPOSIT} from '../common'

Expand Down Expand Up @@ -66,21 +64,6 @@ export const NETWORK_CONFIG = {
COINS_PER_UTXO_WORD,
} as const

export const PRIMARY_TOKEN_INFO: Balance.TokenInfo = {
id: '.',
name: 'TADA',
description: 'Cardano',
fingerprint: '',
kind: 'ft',
group: '',
icon: '',
ticker: 'TADA',
image: '',
decimals: 6,
symbol: '₳',
metadatas: {},
} as const

export const PRIMARY_TOKEN: DefaultAsset = {
identifier: '.',
networkId: CHAIN_NETWORK_ID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import {Balance} from '@yoroi/types'

import {DefaultAsset} from '../../../types'
import {COIN_TYPE, COINS_PER_UTXO_WORD, KEY_DEPOSIT, MINIMUM_UTXO_VAL, POOL_DEPOSIT} from '../common'

Expand Down Expand Up @@ -64,21 +62,6 @@ export const NETWORK_CONFIG = {
COINS_PER_UTXO_WORD,
} as const

export const PRIMARY_TOKEN_INFO: Balance.TokenInfo = {
id: '.',
name: 'TADA',
description: 'Cardano',
fingerprint: '',
kind: 'ft',
group: '',
icon: '',
ticker: 'TADA',
image: '',
decimals: 6,
symbol: '₳',
metadatas: {},
} as const

export const PRIMARY_TOKEN: DefaultAsset = {
identifier: '.',
networkId: CHAIN_NETWORK_ID,
Expand Down
4 changes: 1 addition & 3 deletions apps/wallet-mobile/src/yoroi-wallets/cardano/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
TxMetadata as TxMetadataType,
UnsignedTx as UnsignedTxType,
} from '@emurgo/yoroi-lib'
import {App, Balance, HW, Network, Portfolio, Wallet} from '@yoroi/types'
import {App, HW, Network, Portfolio, Wallet} from '@yoroi/types'
import {BigNumber} from 'bignumber.js'

import {WalletEncryptedStorage} from '../../kernel/storage/EncryptedStorage'
Expand Down Expand Up @@ -161,7 +161,6 @@ export interface YoroiWallet {
get confirmationCounts(): Record<string, null | number>
fetchTipStatus(): Promise<TipStatusResponse>
fetchTxStatus(request: TxStatusRequest): Promise<TxStatusResponse>
fetchTokenInfo(tokenId: string): Promise<Balance.TokenInfo>

// Utxos
utxos: Array<RawUtxo>
Expand Down Expand Up @@ -240,7 +239,6 @@ const yoroiWalletKeys: Array<keyof YoroiWallet> = [
'confirmationCounts',
'fetchTipStatus',
'fetchTxStatus',
'fetchTokenInfo',

// Other
'subscribe',
Expand Down
83 changes: 1 addition & 82 deletions apps/wallet-mobile/src/yoroi-wallets/mocks/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import {Observable} from 'rxjs'

import {buildPortfolioTokenManagers} from '../../features/Portfolio/common/helpers/build-token-managers'
import {buildNetworkManagers} from '../../features/WalletManager/network-manager/network-manager'
import {fallbackTokenInfo, toTokenInfo, utf8ToHex} from '../cardano/api/utils'
import * as HASKELL_SHELLEY_TESTNET from '../cardano/constants/testnet/constants'
import {toTokenInfo, utf8ToHex} from '../cardano/api/utils'
import {CHIMERIC_ACCOUNT, PRIMARY_TOKEN, STAKING_KEY_INDEX} from '../cardano/constants/testnet/constants'
import {CardanoTypes, YoroiWallet} from '../cardano/types'
import {
Expand Down Expand Up @@ -163,10 +162,6 @@ const wallet: YoroiWallet = {
throw new Error('not implemented: signRawTx')
},
getAllUtxosForKey: () => Promise.resolve([]),
fetchTokenInfo: (tokenId: string) => {
action('fetchTokenInfo')(tokenId)
return Promise.resolve(tokenInfos[tokenId] ?? fallbackTokenInfo(tokenId))
},
fetchPoolInfo: (...args: unknown[]) => {
action('fetchPoolInfo')(...args)
return Promise.resolve({[stakePoolId]: poolInfoAndHistory} as StakePoolInfosAndHistories)
Expand Down Expand Up @@ -546,80 +541,6 @@ const submitTransaction = {
},
}

const fetchTokenInfo = {
success: {
nft: async (...args: unknown[]): Promise<Balance.TokenInfo> => {
action('fetchTokenInfo')(...args)
return nft
},
randomNft: async (...args: unknown[]): Promise<Balance.TokenInfo> => {
action('fetchTokenInfo')(...args)
const allNfts = generateManyNfts()
return allNfts[Math.floor(Math.random() * allNfts.length)]
},
ft: async (...args: unknown[]): Promise<Balance.TokenInfo> => {
action('fetchTokenInfo')(...args)
return {
kind: 'ft',
description: 'WingRiders testnet wUSDC token.',
id: '648823ffdad1610b4162f4dbc87bd47f6f9cf45d772ddef661eff198.7755534443',
name: 'wUSDC',
fingerprint: 'asset1n3weea8202dpev06tshdvhe9xd6f9jcqldpc2q',
image: 'https://picsum.photos/40',
icon: 'https://picsum.photos/40',
group: '648823ffdad1610b4162f4dbc87bd47f6f9cf45d772ddef661eff198',
ticker: 'WUSDC',
decimals: 3,
symbol: undefined,
metadatas: {
mintFt: {
decimals: 3,
icon: '',
url: 'https://wallet-testnet.nu.fi',
description: 'WingRiders testnet wUSDC token.',
ticker: 'WUSDC',
version: '1',
},
},
}
},
ftNoImage: async (...args: unknown[]): Promise<Balance.TokenInfo> => {
action('fetchTokenInfo')(...args)
return {
kind: 'ft',
description: 'WingRiders testnet wUSDC token.',
id: '648823ffdad1610b4162f4dbc87bd47f6f9cf45d772ddef661eff198.7755534443',
name: 'wUSDC',
fingerprint: 'asset1n3weea8202dpev06tshdvhe9xd6f9jcqldpc2q',
image: '',
icon: '',
group: '648823ffdad1610b4162f4dbc87bd47f6f9cf45d772ddef661eff198',
ticker: 'WUSDC',
decimals: 3,
symbol: undefined,
metadatas: {
mintFt: {
decimals: 3,
icon: '',
url: 'https://wallet-testnet.nu.fi',
description: 'WingRiders testnet wUSDC token.',
ticker: 'WUSDC',
version: '1',
},
},
}
},
},
loading: async (...args: unknown[]) => {
action('fetchTokenInfo')(...args)
return new Promise(() => null) as unknown as Balance.TokenInfo
},
error: async (...args: unknown[]) => {
action('fetchTokenInfo')(...args)
return Promise.reject(new Error('storybook error message'))
},
}

const tokenEntries: Array<CardanoTypes.TokenEntry> = [
{
identifier: '698a6ea0ca99f315034072af31eaac6ec11fe8558d3f48e9775aab9d.7444524950',
Expand Down Expand Up @@ -660,7 +581,6 @@ const balances: Balance.Amounts = {
}

const tokenInfos: Record<string, Balance.TokenInfo> = {
'.': HASKELL_SHELLEY_TESTNET.PRIMARY_TOKEN_INFO,
'698a6ea0ca99f315034072af31eaac6ec11fe8558d3f48e9775aab9d.7444524950': toTokenInfo({
networkId: 300,
identifier: '698a6ea0ca99f315034072af31eaac6ec11fe8558d3f48e9775aab9d.7444524950',
Expand Down Expand Up @@ -922,7 +842,6 @@ export const mocks = {
txid,
getTransactions,
fetchPoolInfo,
fetchTokenInfo,
createUnsignedTx,
createDelegationTx,
createWithdrawalTx,
Expand Down

0 comments on commit 0ec075a

Please sign in to comment.