diff --git a/src/__tests__/components/ExchangeQuoteComponent.test.tsx b/src/__tests__/components/ExchangeQuoteComponent.test.tsx index c16b564e5d0..f607c4f3061 100644 --- a/src/__tests__/components/ExchangeQuoteComponent.test.tsx +++ b/src/__tests__/components/ExchangeQuoteComponent.test.tsx @@ -96,7 +96,6 @@ describe('ExchangeQuote', () => { return { transaction: { blockHeight: 500000, - tokenId: null, currencyCode: 'BTC', date: 1524476980, deviceDescription: 'iphone12', diff --git a/src/__tests__/components/TransactionListRow.test.tsx b/src/__tests__/components/TransactionListRow.test.tsx index d9c8e054212..41fa87575ad 100644 --- a/src/__tests__/components/TransactionListRow.test.tsx +++ b/src/__tests__/components/TransactionListRow.test.tsx @@ -49,7 +49,6 @@ describe('TransactionListRow', () => { transaction={{ blockHeight: 10, currencyCode: 'BTC', - tokenId: null, date: 123456789, nativeAmount: '-100001', isSend: true, diff --git a/src/__tests__/modals/AccelerateTxModal.test.tsx b/src/__tests__/modals/AccelerateTxModal.test.tsx index 5d4369f983b..561bc8508d1 100644 --- a/src/__tests__/modals/AccelerateTxModal.test.tsx +++ b/src/__tests__/modals/AccelerateTxModal.test.tsx @@ -24,7 +24,6 @@ describe('AccelerateTxModalComponent', () => { replacedTx={{ blockHeight: 0, currencyCode: 'BTC', - tokenId: null, date: 0, isSend: true, memos: [], @@ -40,7 +39,6 @@ describe('AccelerateTxModalComponent', () => { acceleratedTx={{ blockHeight: 0, currencyCode: 'BTC', - tokenId: null, date: 0, isSend: true, memos: [], diff --git a/src/__tests__/modals/AdvancedDetailsCard.test.tsx b/src/__tests__/modals/AdvancedDetailsCard.test.tsx index 3c7a2e15295..920aa72cb84 100644 --- a/src/__tests__/modals/AdvancedDetailsCard.test.tsx +++ b/src/__tests__/modals/AdvancedDetailsCard.test.tsx @@ -13,7 +13,6 @@ describe('AdvancedDetailsCard', () => { transaction={{ blockHeight: 0, currencyCode: 'BCH', - tokenId: null, date: 0, isSend: true, memos: [], diff --git a/src/__tests__/scenes/CryptoExchangeQuoteScene.test.tsx b/src/__tests__/scenes/CryptoExchangeQuoteScene.test.tsx index dfe1a2056a7..ef39927fadb 100644 --- a/src/__tests__/scenes/CryptoExchangeQuoteScene.test.tsx +++ b/src/__tests__/scenes/CryptoExchangeQuoteScene.test.tsx @@ -107,7 +107,6 @@ describe('CryptoExchangeQuoteScreenComponent', () => { transaction: { blockHeight: 500000, currencyCode: 'BTC', - tokenId: null, date: 1524476980, deviceDescription: 'iphone12', isSend: false, diff --git a/src/__tests__/scenes/TransactionDetailsScene.test.tsx b/src/__tests__/scenes/TransactionDetailsScene.test.tsx index e2e8577b5bd..8a03c261862 100644 --- a/src/__tests__/scenes/TransactionDetailsScene.test.tsx +++ b/src/__tests__/scenes/TransactionDetailsScene.test.tsx @@ -74,7 +74,6 @@ describe('TransactionDetailsScene', () => { { undefined) if (parsedUri != null) { - const { tokenId } = parsedUri + const { tokenId = null } = parsedUri matchingWalletIdsAndUris.push({ currencyCode: parsedUri.currencyCode, walletId: wallet.id, parsedUri, tokenId }) } } @@ -251,7 +251,7 @@ export async function handleLink(navigation: NavigationBase, dispatch: Dispatch, } async function launchAzteco(navigation: NavigationBase, edgeWallet: EdgeCurrencyWallet, uri: string): Promise { - const address = await edgeWallet.getReceiveAddress() + const address = await edgeWallet.getReceiveAddress({ tokenId: null }) const response = await fetch(`${uri}${address.publicAddress}`) if (response.ok) { showToast(lstrings.azteco_success) diff --git a/src/actions/ScanActions.tsx b/src/actions/ScanActions.tsx index 789804860d1..21b75eb93ea 100644 --- a/src/actions/ScanActions.tsx +++ b/src/actions/ScanActions.tsx @@ -175,7 +175,7 @@ export function handleWalletUris( fioAddress?: string ): ThunkAction> { return async (dispatch, getState) => { - const { legacyAddress, metadata, minNativeAmount, nativeAmount, publicAddress, uniqueIdentifier, tokenId } = parsedUri + const { legacyAddress, metadata, minNativeAmount, nativeAmount, publicAddress, uniqueIdentifier, tokenId = null } = parsedUri const currencyCode: string = parsedUri.currencyCode ?? wallet.currencyInfo.currencyCode // Coin operations diff --git a/src/actions/WalletActions.tsx b/src/actions/WalletActions.tsx index 7de566d7574..e444d1c3011 100644 --- a/src/actions/WalletActions.tsx +++ b/src/actions/WalletActions.tsx @@ -95,7 +95,7 @@ function selectEOSWallet(navigation: NavigationBase, walletId: string, currencyC currencyInfo: { currencyCode, pluginId } } = wallet const walletName = name ?? '' - const { publicAddress } = await wallet.getReceiveAddress() + const { publicAddress } = await wallet.getReceiveAddress({ tokenId: null }) if (publicAddress !== '') { // already activated diff --git a/src/actions/WalletListActions.tsx b/src/actions/WalletListActions.tsx index 644f2097057..fe48e0184ed 100644 --- a/src/actions/WalletListActions.tsx +++ b/src/actions/WalletListActions.tsx @@ -60,7 +60,7 @@ const getFirstCurrencyAddress = async (currencyCode: string, getState: GetState) }) if (walletId) { const wallet = edgeWallets[walletId] - return (await wallet.getReceiveAddress()).publicAddress + return (await wallet.getReceiveAddress({ tokenId: null })).publicAddress } // Wallet Creation @@ -79,7 +79,7 @@ const getFirstCurrencyAddress = async (currencyCode: string, getState: GetState) const wallet = await showFullScreenSpinner(lstrings.wallet_list_referral_link_currency_loading, createWallet) logActivity(`Create Wallet (wallet list): ${account.username} -- ${createWalletTypes.walletType} -- ${defaultIsoFiat ?? ''}`) - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) return receiveAddress.publicAddress } diff --git a/src/actions/WalletListMenuActions.tsx b/src/actions/WalletListMenuActions.tsx index ce7afb02844..e896d3b2776 100644 --- a/src/actions/WalletListMenuActions.tsx +++ b/src/actions/WalletListMenuActions.tsx @@ -98,7 +98,7 @@ export function walletListMenuAction( if (tokenId == null) { if (fioAddress) { additionalMsg = lstrings.fragmet_wallets_delete_fio_extra_message_mobile - } else if (wallet.currencyInfo.metaTokens.length > 0) { + } else if (Object.keys(wallet.currencyConfig.allTokens).length > 0) { additionalMsg = lstrings.fragmet_wallets_delete_eth_extra_message } } else { diff --git a/src/components/icons/CryptoIcon.tsx b/src/components/icons/CryptoIcon.tsx index 593cbcdb496..44c5a91ee9f 100644 --- a/src/components/icons/CryptoIcon.tsx +++ b/src/components/icons/CryptoIcon.tsx @@ -50,7 +50,7 @@ const CryptoIconComponent = (props: Props) => { if (pluginId == null) return null // Get Currency Icon URI - const icon = getCurrencyIconUris(pluginId, tokenId ?? undefined) + const icon = getCurrencyIconUris(pluginId, tokenId) const source = { uri: mono ? icon.symbolImageDarkMono : icon.symbolImage } // Return Currency logo from the edge server diff --git a/src/components/scenes/Fio/FioAddressRegisterScene.tsx b/src/components/scenes/Fio/FioAddressRegisterScene.tsx index 7ba36be8876..a1f0a39a47c 100644 --- a/src/components/scenes/Fio/FioAddressRegisterScene.tsx +++ b/src/components/scenes/Fio/FioAddressRegisterScene.tsx @@ -92,7 +92,7 @@ export class FioAddressRegister extends React.Component { checkFreeAddress = async () => { try { const { fioPlugin } = this.props - const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings.freeAddressRef) + const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings?.freeAddressRef) if (publicDomains.findIndex((publicDomain: FioPublicDomain) => publicDomain.free) > -1) { this.setState({ showFreeAddressLink: true }) } @@ -105,7 +105,7 @@ export class FioAddressRegister extends React.Component { getPublicDomains = async () => { const { fioPlugin } = this.props try { - const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings.fallbackRef) + const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings?.fallbackRef) const publicDomainsConverted = publicDomains // @ts-expect-error .sort(publicDomain => (publicDomain.domain === FIO_DOMAIN_DEFAULT.name ? -1 : 1)) @@ -149,7 +149,7 @@ export class FioAddressRegister extends React.Component { if (!fioWallets.length) return if (!selectedWallet) return const publicKey = selectedWallet.publicWalletInfo.keys.publicKey - const url = `${fioPlugin.currencyInfo.defaultSettings.fioAddressRegUrl}${fioPlugin.currencyInfo.defaultSettings.freeAddressRef}?publicKey=${publicKey}` + const url = `${fioPlugin.currencyInfo.defaultSettings?.fioAddressRegUrl}${fioPlugin.currencyInfo.defaultSettings?.freeAddressRef}?publicKey=${publicKey}` try { await openLink(url) } catch (e: any) { diff --git a/src/components/scenes/Fio/FioConnectWalletConfirmScene.tsx b/src/components/scenes/Fio/FioConnectWalletConfirmScene.tsx index 08a3d1a10c3..d44bbc7a531 100644 --- a/src/components/scenes/Fio/FioConnectWalletConfirmScene.tsx +++ b/src/components/scenes/Fio/FioConnectWalletConfirmScene.tsx @@ -53,7 +53,7 @@ export class FioConnectWalletConfirm extends React.Component { walletId: wallet.id, tokenCode: wallet.currencyCode, chainCode: wallet.chainCode, - publicAddress: (await wallet.edgeWallet.getReceiveAddress()).publicAddress + publicAddress: (await wallet.edgeWallet.getReceiveAddress({ tokenId: null })).publicAddress })) let publicAddresses = await Promise.all(promiseArray) @@ -70,7 +70,7 @@ export class FioConnectWalletConfirm extends React.Component { walletId: wallet.id, tokenCode: wallet.currencyCode, chainCode: wallet.chainCode, - publicAddress: (await wallet.edgeWallet.getReceiveAddress()).publicAddress + publicAddress: (await wallet.edgeWallet.getReceiveAddress({ tokenId: null })).publicAddress })) publicAddresses = await Promise.all(promiseArray) diff --git a/src/components/scenes/Fio/FioCreateHandleScene.tsx b/src/components/scenes/Fio/FioCreateHandleScene.tsx index e56e41e49e1..81b239e5cf9 100644 --- a/src/components/scenes/Fio/FioCreateHandleScene.tsx +++ b/src/components/scenes/Fio/FioCreateHandleScene.tsx @@ -112,7 +112,7 @@ export const FioCreateHandleScene = (props: Props) => { body: JSON.stringify({ address: fioAccountName, referralCode: freeRegRefCode, - publicKey: (await wallet.getReceiveAddress()).publicAddress, + publicKey: (await wallet.getReceiveAddress({ tokenId: null })).publicAddress, redirectUrl: '', apiToken: freeRegApiToken }) diff --git a/src/components/scenes/Fio/FioNameConfirmScene.tsx b/src/components/scenes/Fio/FioNameConfirmScene.tsx index 0defdff64b8..11319eaa7bc 100644 --- a/src/components/scenes/Fio/FioNameConfirmScene.tsx +++ b/src/components/scenes/Fio/FioNameConfirmScene.tsx @@ -54,14 +54,14 @@ class FioNameConfirm extends React.PureComponent { const response = await fioPlugin.otherMethods.buyAddressRequest( { address: fioName, - referralCode: fioPlugin.currencyInfo.defaultSettings.defaultRef, + referralCode: fioPlugin.currencyInfo.defaultSettings?.defaultRef, publicKey: ownerPublicKey }, true ) if (response.error) { if (response.errorCode && response.errorCode === ONE_FREE_ADDRESS_PER_DOMAIN_ERROR && response.code === 400) { - const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings.fallbackRef) + const publicDomains = await fioPlugin.otherMethods.getDomains(fioPlugin.currencyInfo.defaultSettings?.fallbackRef) // @ts-expect-error const domainExists = publicDomains.find(domain => domain.domain === fioName.split(FIO_ADDRESS_DELIMITER)[1]) if (domainExists && !domainExists.free) { diff --git a/src/components/scenes/Fio/FioRequestConfirmationScene.tsx b/src/components/scenes/Fio/FioRequestConfirmationScene.tsx index 55e703a67eb..5c1b6fab323 100644 --- a/src/components/scenes/Fio/FioRequestConfirmationScene.tsx +++ b/src/components/scenes/Fio/FioRequestConfirmationScene.tsx @@ -115,7 +115,7 @@ export class FioRequestConfirmationConnected extends React.Component fioAddress === fioAddressFrom) - const { publicAddress } = await edgeWallet.getReceiveAddress() + const { publicAddress } = await edgeWallet.getReceiveAddress({ tokenId: null }) if (walletAddress && fioPlugin) { const { fioWallet } = walletAddress diff --git a/src/components/scenes/MigrateWalletCalculateFeeScene.tsx b/src/components/scenes/MigrateWalletCalculateFeeScene.tsx index 69b7744d1c9..aa07f49b5b2 100644 --- a/src/components/scenes/MigrateWalletCalculateFeeScene.tsx +++ b/src/components/scenes/MigrateWalletCalculateFeeScene.tsx @@ -153,7 +153,7 @@ const MigrateWalletCalculateFeeComponent = (props: Props) => { const assetPromises = bundle.map((asset, i) => { return async () => { - const publicAddress = SPECIAL_CURRENCY_INFO[pluginId].dummyPublicAddress ?? (await wallet.getReceiveAddress()).publicAddress + const publicAddress = SPECIAL_CURRENCY_INFO[pluginId].dummyPublicAddress ?? (await wallet.getReceiveAddress({ tokenId: null })).publicAddress const spendInfo: EdgeSpendInfo = { tokenId: asset.tokenId, spendTargets: [{ publicAddress }], diff --git a/src/components/scenes/MigrateWalletCompletionScene.tsx b/src/components/scenes/MigrateWalletCompletionScene.tsx index b502db5838e..320757619c0 100644 --- a/src/components/scenes/MigrateWalletCompletionScene.tsx +++ b/src/components/scenes/MigrateWalletCompletionScene.tsx @@ -125,7 +125,7 @@ const MigrateWalletCompletionComponent = (props: Props) => { // Change old wallet name if (createdNewWallet) await oldWallet.renameWallet(`${oldWalletName}${lstrings.migrate_wallet_old_fragment}`) - const addressInfo = await newWallet.getReceiveAddress() + const addressInfo = await newWallet.getReceiveAddress({ tokenId: null }) const newPublicAddress = addressInfo.segwitAddress ?? addressInfo.publicAddress const tokenItems = bundle.filter((pair: any): pair is MigrateWalletTokenItem => pair.tokenId != null) diff --git a/src/components/scenes/RequestScene.tsx b/src/components/scenes/RequestScene.tsx index d80f8751151..4f0071edcc7 100644 --- a/src/components/scenes/RequestScene.tsx +++ b/src/components/scenes/RequestScene.tsx @@ -127,7 +127,7 @@ export class RequestSceneComponent extends React.Component { if (wallet == null) return if (isKeysOnlyPlugin(wallet.currencyInfo.pluginId)) return - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) const addresses: AddressInfo[] = [] // Handle segwitAddress diff --git a/src/components/scenes/WcConnectScene.tsx b/src/components/scenes/WcConnectScene.tsx index c10bdc8853d..fbd8c9af93b 100644 --- a/src/components/scenes/WcConnectScene.tsx +++ b/src/components/scenes/WcConnectScene.tsx @@ -63,7 +63,7 @@ export const WcConnectScene = (props: Props) => { }, [proposal]) useAsyncEffect(async () => { - const r = await wallet.getReceiveAddress() + const r = await wallet.getReceiveAddress({ tokenId: null }) setWalletAddress(r.publicAddress) }, [wallet]) diff --git a/src/components/themed/ExplorerCard.tsx b/src/components/themed/ExplorerCard.tsx index 6d89aef3848..b732e6ea103 100644 --- a/src/components/themed/ExplorerCard.tsx +++ b/src/components/themed/ExplorerCard.tsx @@ -34,7 +34,7 @@ export const ExplorerCard = (props: Props) => { // const handlePress = useHandler(async () => { - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) const url = sprintf(addressExplorer, receiveAddress.publicAddress) await Linking.openURL(url) }) diff --git a/src/components/themed/TransactionListRow.tsx b/src/components/themed/TransactionListRow.tsx index 2cb1d4058d2..ca4cd7492b4 100644 --- a/src/components/themed/TransactionListRow.tsx +++ b/src/components/themed/TransactionListRow.tsx @@ -20,6 +20,7 @@ import { lstrings } from '../../locales/strings' import { getDisplayDenomination, getExchangeDenomination } from '../../selectors/DenominationSelectors' import { useSelector } from '../../types/reactRedux' import { NavigationBase } from '../../types/routerTypes' +import { getWalletTokenId } from '../../util/CurrencyInfoHelpers' import { DECIMAL_PRECISION, decimalOrZero, diff --git a/src/components/themed/TransactionListTop.tsx b/src/components/themed/TransactionListTop.tsx index 14c94caaec8..3e34d663b86 100644 --- a/src/components/themed/TransactionListTop.tsx +++ b/src/components/themed/TransactionListTop.tsx @@ -1,5 +1,5 @@ import { add, gt, mul, round } from 'biggystring' -import { EdgeAccount, EdgeBalances, EdgeCurrencyWallet, EdgeDenomination, EdgeTokenId } from 'edge-core-js' +import { EdgeAccount, EdgeBalanceMap, EdgeCurrencyWallet, EdgeDenomination, EdgeTokenId } from 'edge-core-js' import * as React from 'react' import { ActivityIndicator, TouchableOpacity, View } from 'react-native' import { AirshipBridge } from 'react-native-airship' @@ -57,7 +57,7 @@ interface OwnProps { interface StateProps { account: EdgeAccount - balanceMap: EdgeBalances + balanceMap: EdgeBalanceMap currencyCode: string displayDenomination: EdgeDenomination exchangeDenomination: EdgeDenomination diff --git a/src/components/tiles/AddressTile2.tsx b/src/components/tiles/AddressTile2.tsx index 257287b82b3..c668620968a 100644 --- a/src/components/tiles/AddressTile2.tsx +++ b/src/components/tiles/AddressTile2.tsx @@ -98,7 +98,7 @@ export const AddressTile2 = React.forwardRef((props: Props, ref: React.Forwarded fioAddress = address.toLowerCase() address = publicAddress } catch (e: any) { - if (!e.code || e.code !== fioPlugin.currencyInfo.defaultSettings.errorCodes.INVALID_FIO_ADDRESS) { + if (!e.code || e.code !== fioPlugin.currencyInfo.defaultSettings?.errorCodes.INVALID_FIO_ADDRESS) { setLoading(false) return showError(e) } @@ -227,7 +227,7 @@ export const AddressTile2 = React.forwardRef((props: Props, ref: React.Forwarded const wallet = currencyWallets[walletId] // Prefer segwit address if the selected wallet has one - const { segwitAddress, publicAddress } = await wallet.getReceiveAddress() + const { segwitAddress, publicAddress } = await wallet.getReceiveAddress({ tokenId: null }) const address = segwitAddress != null ? segwitAddress : publicAddress await changeAddress(address) }) diff --git a/src/controllers/edgeProvider/EdgeProviderServer.tsx b/src/controllers/edgeProvider/EdgeProviderServer.tsx index 5c22c53805b..a492b59c72c 100644 --- a/src/controllers/edgeProvider/EdgeProviderServer.tsx +++ b/src/controllers/edgeProvider/EdgeProviderServer.tsx @@ -152,7 +152,7 @@ export class EdgeProviderServer implements EdgeProviderMethods { const wallet = this._selectedWallet if (wallet == null) throw new Error('No selected wallet') - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) if (options.metadata != null) { receiveAddress.metadata = options.metadata } @@ -167,7 +167,7 @@ export class EdgeProviderServer implements EdgeProviderMethods { const { currencyConfig, currencyInfo, fiatCurrencyCode } = wallet const { currencyCode } = tokenId == null ? currencyInfo : currencyConfig.allTokens[tokenId] const walletName = getWalletName(wallet) - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) const icons = getCurrencyIconUris(wallet.currencyInfo.pluginId, tokenId) const returnObject: WalletDetails = { @@ -426,7 +426,7 @@ export class EdgeProviderServer implements EdgeProviderMethods { const wallet = this._selectedWallet if (wallet == null) throw new Error('No selected wallet') - const { publicAddress } = await wallet.getReceiveAddress() + const { publicAddress } = await wallet.getReceiveAddress({ tokenId: null }) const signedMessage = await wallet.signMessage(message, { otherParams: { publicAddress } }) console.log(`signMessage public address:***${publicAddress}***`) console.log(`signMessage signedMessage:***${signedMessage}***`) @@ -555,7 +555,6 @@ export function getReturnCurrencyCode(allowedCurrencyCodes: string[] | undefined function cleanTx(tx: EdgeTransaction): EdgeTransaction { const newTx: EdgeTransaction = { - tokenId: tx.tokenId, blockHeight: tx.blockHeight, confirmations: tx.confirmations, currencyCode: tx.currencyCode, diff --git a/src/controllers/edgeProvider/types/edgeProviderCleaners.ts b/src/controllers/edgeProvider/types/edgeProviderCleaners.ts index 7ead4782ea0..897b7718489 100644 --- a/src/controllers/edgeProvider/types/edgeProviderCleaners.ts +++ b/src/controllers/edgeProvider/types/edgeProviderCleaners.ts @@ -11,7 +11,7 @@ import { WalletDetails } from './edgeProviderTypes' -const asEdgeMetadata = asObject({ +const asEdgeMetadata = asObject({ amountFiat: asOptional(asNumber), bizId: asOptional(asNumber), category: asOptional(asString), @@ -45,10 +45,9 @@ const asEdgeMemo = asObject({ }) const asEdgeTransaction = asObject({ - tokenId: asEdgeTokenId, walletId: asString, + tokenId: asEdgeTokenId, currencyCode: asString, - tokenId: asOptional(asString, null), // Amounts: nativeAmount: asString, diff --git a/src/hooks/useWalletConnect.tsx b/src/hooks/useWalletConnect.tsx index a94bfab3781..cc6d29eaf05 100644 --- a/src/hooks/useWalletConnect.tsx +++ b/src/hooks/useWalletConnect.tsx @@ -119,7 +119,7 @@ export function useWalletConnect(): WalletConnect { const chainId = SPECIAL_CURRENCY_INFO[wallet.currencyInfo.pluginId].walletConnectV2ChainId if (chainId == null) return - const address = await wallet.getReceiveAddress() + const address = await wallet.getReceiveAddress({ tokenId: null }) const supportedNamespaces = getSupportedNamespaces(chainId, address.publicAddress) // Check that we support all required methods @@ -238,7 +238,7 @@ export const getAccounts = async (currencyWallets: { [walletId: string]: EdgeCur const chainId = SPECIAL_CURRENCY_INFO[wallet.currencyInfo.pluginId].walletConnectV2ChainId if (chainId == null) continue - const address = await currencyWallets[walletId].getReceiveAddress() + const address = await currencyWallets[walletId].getReceiveAddress({ tokenId: null }) const account = `${chainId.namespace}:${chainId.reference}:${address.publicAddress}` map.set(account, walletId) } diff --git a/src/plugins/borrow-plugins/plugins/aave/AaveBorrowEngineFactory.ts b/src/plugins/borrow-plugins/plugins/aave/AaveBorrowEngineFactory.ts index 2c295357f04..72bf2978c9f 100644 --- a/src/plugins/borrow-plugins/plugins/aave/AaveBorrowEngineFactory.ts +++ b/src/plugins/borrow-plugins/plugins/aave/AaveBorrowEngineFactory.ts @@ -38,7 +38,7 @@ export interface BorrowEngineBlueprint { export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => { return async (wallet: EdgeCurrencyWallet): Promise => { const { aaveNetwork, asTokenContractAddress } = blueprint - const walletAddress = (await wallet.getReceiveAddress()).publicAddress + const walletAddress = (await wallet.getReceiveAddress({ tokenId: null })).publicAddress const REFERRAL_CODE = 0 // No referral code is used for AAVE contract calls const INTEREST_RATE_MODE = 2 // Only variable is supported for now @@ -218,11 +218,11 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => const token = getToken(tokenId) const tokenAddress = getTokenAddress(token) - const spenderAddress = (await wallet.getReceiveAddress()).publicAddress + const spenderAddress = (await wallet.getReceiveAddress({ tokenId: null })).publicAddress const asset = tokenAddress const amount = BigNumber.from(nativeAmount) - const onBehalfOf = fromWallet === wallet ? spenderAddress : (await fromWallet.getReceiveAddress()).publicAddress + const onBehalfOf = fromWallet === wallet ? spenderAddress : (await fromWallet.getReceiveAddress({ tokenId: null })).publicAddress const tokenContract = await aaveNetwork.makeTokenContract(tokenAddress) const gasPrice = await aaveNetwork.provider.getGasPrice() @@ -282,7 +282,7 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => // Anything above the current collateral amount will be automatically // converted to the MAX_AMOUNT in order to withdraw all collateral. const contractTokenAmount = BigNumber.from(gt(nativeAmount, collateral.nativeAmount) ? MAX_AMOUNT : request.nativeAmount) - const to = (await toWallet.getReceiveAddress()).publicAddress + const to = (await toWallet.getReceiveAddress({ tokenId: null })).publicAddress const gasPrice = await aaveNetwork.provider.getGasPrice() @@ -319,7 +319,7 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => const asset = tokenAddress const amount = BigNumber.from(nativeAmount) - const onBehalfOf = (await fromWallet.getReceiveAddress()).publicAddress + const onBehalfOf = (await fromWallet.getReceiveAddress({ tokenId: null })).publicAddress const gasPrice = await aaveNetwork.provider.getGasPrice() @@ -360,7 +360,7 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => // nativeAmount can't be zero if (nativeAmount === '0') throw new Error('BorrowEngine: repay request contains no nativeAmount.') - const fromAddress = (await fromWallet.getReceiveAddress()).publicAddress + const fromAddress = (await fromWallet.getReceiveAddress({ tokenId: null })).publicAddress const debtToken = getToken(tokenId) const debtTokenAddress = getTokenAddress(getToken(tokenId)) @@ -393,7 +393,7 @@ export const makeAaveBorrowEngineFactory = (blueprint: BorrowEngineBlueprint) => // Build ParaSwap swap info // Cap the amount to swap at the debt amount const amountToSwap = amountToCover.mul(100 + PARASWAP_SLIPPAGE_PERCENT).div(100) - const chainId = fromWallet.currencyInfo.defaultSettings.otherSettings.chainParams.chainId + const chainId = fromWallet.currencyInfo.defaultSettings?.otherSettings.chainParams.chainId const paraswap = new ParaSwap(chainId, 'https://apiv5.paraswap.io') const priceRoute = await paraswap.getRate(collateralTokenAddress, debtTokenAddress, amountToSwap.toString(), fromAddress, SwapSide.BUY, { partner: 'aave', diff --git a/src/plugins/gui/providers/banxaProvider.ts b/src/plugins/gui/providers/banxaProvider.ts index 8171fffde72..ea44a6d294f 100644 --- a/src/plugins/gui/providers/banxaProvider.ts +++ b/src/plugins/gui/providers/banxaProvider.ts @@ -468,7 +468,7 @@ export const banxaProvider: FiatProviderFactory = { expirationDate: new Date(Date.now() + 50000), approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise => { const { showUi, coreWallet } = approveParams - const receiveAddress = await coreWallet.getReceiveAddress() + const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null }) const bodyParams: any = { payment_method_id: paymentObj?.id ?? '', diff --git a/src/plugins/gui/providers/bityProvider.ts b/src/plugins/gui/providers/bityProvider.ts index faa187f49c7..fa3c5409588 100644 --- a/src/plugins/gui/providers/bityProvider.ts +++ b/src/plugins/gui/providers/bityProvider.ts @@ -251,7 +251,7 @@ const approveBityQuote = async ( if (orderData.message_to_sign != null) { const { body } = orderData.message_to_sign - const { publicAddress } = await wallet.getReceiveAddress() + const { publicAddress } = await wallet.getReceiveAddress({ tokenId: null }) const signedMessage = await wallet.signMessage(body, { otherParams: { publicAddress } }) const signUrl = baseUrl + orderData.message_to_sign.signature_submission_url const request = { @@ -409,7 +409,7 @@ export const bityProvider: FiatProviderFactory = { // Bity only checks SEPA info format validity. // Home address and KYC is only required for sell. - const cryptoAddress = (await coreWallet.getReceiveAddress()).publicAddress + const cryptoAddress = (await coreWallet.getReceiveAddress({ tokenId: null })).publicAddress await showUi.sepaForm({ headerTitle: lstrings.sepa_form_title, diff --git a/src/plugins/gui/providers/moonpayProvider.ts b/src/plugins/gui/providers/moonpayProvider.ts index 1536c6b7f63..029adb8b586 100644 --- a/src/plugins/gui/providers/moonpayProvider.ts +++ b/src/plugins/gui/providers/moonpayProvider.ts @@ -249,7 +249,7 @@ export const moonpayProvider: FiatProviderFactory = { expirationDate: new Date(Date.now() + 8000), approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise => { const { coreWallet, showUi } = approveParams - const receiveAddress = await coreWallet.getReceiveAddress() + const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null }) const url = new URL('https://buy.moonpay.com?', true) const queryObj: MoonpayWidgetQueryParams = { apiKey, diff --git a/src/plugins/gui/providers/paybisProvider.ts b/src/plugins/gui/providers/paybisProvider.ts index bf36c5389b4..cc3410624ff 100644 --- a/src/plugins/gui/providers/paybisProvider.ts +++ b/src/plugins/gui/providers/paybisProvider.ts @@ -456,7 +456,7 @@ export const paybisProvider: FiatProviderFactory = { paymentTypes, approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise => { const { coreWallet, showUi } = approveParams - const receiveAddress = await coreWallet.getReceiveAddress() + const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null }) let bodyParams if (direction === 'buy') { diff --git a/src/plugins/gui/providers/simplexProvider.ts b/src/plugins/gui/providers/simplexProvider.ts index eb13e932c2f..99e54292e06 100644 --- a/src/plugins/gui/providers/simplexProvider.ts +++ b/src/plugins/gui/providers/simplexProvider.ts @@ -315,7 +315,7 @@ export const simplexProvider: FiatProviderFactory = { expirationDate: new Date(Date.now() + 8000), approveQuote: async (approveParams: FiatProviderApproveQuoteParams): Promise => { const { showUi, coreWallet } = approveParams - const receiveAddress = await coreWallet.getReceiveAddress() + const receiveAddress = await coreWallet.getReceiveAddress({ tokenId: null }) const data = { ts: Math.floor(Date.now() / 1000), diff --git a/src/plugins/stake-plugins/currency/tronStakePlugin.ts b/src/plugins/stake-plugins/currency/tronStakePlugin.ts index caf78f1d4f4..fd0d9194e54 100644 --- a/src/plugins/stake-plugins/currency/tronStakePlugin.ts +++ b/src/plugins/stake-plugins/currency/tronStakePlugin.ts @@ -161,7 +161,7 @@ export const makeTronStakePlugin = async (): Promise => { const resource = policy.rewardAssets[0].internalCurrencyCode ?? policy.rewardAssets[0].currencyCode const spendTargets = [ { - publicAddress: (await wallet.getReceiveAddress()).publicAddress + publicAddress: (await wallet.getReceiveAddress({ tokenId: null })).publicAddress } ] @@ -326,7 +326,7 @@ const fetchChangeQuoteV1 = async (request: ChangeQuoteRequest): Promise { - const { publicAddress } = await this.wallet.getReceiveAddress() + const { publicAddress } = await this.wallet.getReceiveAddress({ tokenId: null }) return publicAddress } diff --git a/src/reducers/scenes/SettingsReducer.ts b/src/reducers/scenes/SettingsReducer.ts index 9e8177a241b..6bb84f6aca5 100644 --- a/src/reducers/scenes/SettingsReducer.ts +++ b/src/reducers/scenes/SettingsReducer.ts @@ -54,7 +54,7 @@ export const settingsLegacy = (state: SettingsState = initialState, action: Acti // @ts-expect-error newState.denominationSettings[pluginId][currencyCode] = currencyInfo.denominations[0] } - for (const token of currencyInfo.metaTokens) { + for (const token of currencyInfo.metaTokens ?? []) { const tokenCode = token.currencyCode // @ts-expect-error newState.denominationSettings[pluginId][tokenCode] = token.denominations[0] diff --git a/src/types/types.ts b/src/types/types.ts index 9956749d7f0..718ccb5a417 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -322,14 +322,14 @@ export interface AppConfig { */ export interface WalletListItem { key: string + tokenId: EdgeTokenId + walletId: string // `token` will be set for token rows: token?: EdgeToken - tokenId: EdgeTokenId // The wallet will be present once it loads: wallet?: EdgeCurrencyWallet - walletId: string } export interface EdgeAsset { diff --git a/src/util/FioAddressUtils.ts b/src/util/FioAddressUtils.ts index a2f65445a28..4be789c3d35 100644 --- a/src/util/FioAddressUtils.ts +++ b/src/util/FioAddressUtils.ts @@ -198,7 +198,7 @@ const isWalletConnected = async ( return true } } - const receiveAddress = await wallet.getReceiveAddress() + const receiveAddress = await wallet.getReceiveAddress({ tokenId: null }) if (connectedAddress === receiveAddress.publicAddress) return true } catch (e: any) { // @@ -469,14 +469,17 @@ export const checkPubAddress = async (fioPlugin: EdgeCurrencyConfig, fioAddress: const { public_address: publicAddress } = await fioPlugin.otherMethods.getConnectedPublicAddress(fioAddress.toLowerCase(), chainCode, tokenCode) return publicAddress } catch (e: any) { - if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings.errorCodes.INVALID_FIO_ADDRESS) { - throw new FioError(lstrings.fio_error_invalid_address, fioPlugin.currencyInfo.defaultSettings.errorCodes.INVALID_FIO_ADDRESS) + if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings?.errorCodes.INVALID_FIO_ADDRESS) { + throw new FioError(lstrings.fio_error_invalid_address, fioPlugin.currencyInfo.defaultSettings?.errorCodes.INVALID_FIO_ADDRESS) } - if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_ADDRESS_IS_NOT_EXIST) { - throw new FioError(lstrings.send_fio_request_error_addr_not_exist, fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_ADDRESS_IS_NOT_EXIST) + if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_ADDRESS_IS_NOT_EXIST) { + throw new FioError(lstrings.send_fio_request_error_addr_not_exist, fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_ADDRESS_IS_NOT_EXIST) } - if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_ADDRESS_IS_NOT_LINKED) { - throw new FioError(sprintf(lstrings.err_address_not_linked_title, tokenCode), fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_ADDRESS_IS_NOT_LINKED) + if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_ADDRESS_IS_NOT_LINKED) { + throw new FioError( + sprintf(lstrings.err_address_not_linked_title, tokenCode), + fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_ADDRESS_IS_NOT_LINKED + ) } throw new Error(lstrings.fio_connect_wallets_err) } @@ -615,7 +618,7 @@ export const checkIsDomainPublic = async (fioPlugin: EdgeCurrencyConfig, domain: try { isDomainPublic = fioPlugin.otherMethods ? await fioPlugin.otherMethods.isDomainPublic(domain) : false } catch (e: any) { - if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_DOMAIN_IS_NOT_EXIST) { + if (e.labelCode && e.labelCode === fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_DOMAIN_IS_NOT_EXIST) { throw new Error(lstrings.fio_get_reg_info_domain_err_msg) } @@ -679,7 +682,7 @@ export const getRegInfo = async ( } // todo: temporary commented to use fallback referral code by default. // const referralCode = isFallback ? fioPlugin.currencyInfo.defaultSettings.fallbackRef : fioPlugin.currencyInfo.defaultSettings.defaultRef - const reqResult = await buyAddressRequest(fioPlugin, fioAddress, fioPlugin.currencyInfo.defaultSettings.fallbackRef, selectedWallet, activationCost) + const reqResult = await buyAddressRequest(fioPlugin, fioAddress, fioPlugin.currencyInfo.defaultSettings?.fallbackRef, selectedWallet, activationCost) return { ...reqResult, feeValue @@ -717,7 +720,7 @@ export const getDomainRegInfo = async ( throw new Error(lstrings.fio_get_fee_err_msg) } - const reqResult = await buyAddressRequest(fioPlugin, fioDomain, fioPlugin.currencyInfo.defaultSettings.defaultRef, selectedWallet, activationCost) + const reqResult = await buyAddressRequest(fioPlugin, fioDomain, fioPlugin.currencyInfo.defaultSettings?.defaultRef, selectedWallet, activationCost) return { ...reqResult, feeValue @@ -781,12 +784,12 @@ const buyAddressRequest = async ( } } catch (e: any) { const errorMessages = { - [fioPlugin.currencyInfo.defaultSettings.errorCodes.INVALID_FIO_ADDRESS]: lstrings.fio_error_invalid_address, - [fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_DOMAIN_IS_NOT_EXIST]: lstrings.fio_get_reg_info_domain_err_msg, - [fioPlugin.currencyInfo.defaultSettings.errorCodes.FIO_DOMAIN_IS_NOT_PUBLIC]: lstrings.fio_address_register_domain_is_not_public, - [fioPlugin.currencyInfo.defaultSettings.errorCodes.SERVER_ERROR]: lstrings.fio_get_reg_info_err_msg, - [fioPlugin.currencyInfo.defaultSettings.errorCodes.ALREADY_SENT_REGISTRATION_REQ_FOR_DOMAIN]: lstrings.fio_get_reg_info_already_sent_err_msg, - [fioPlugin.currencyInfo.defaultSettings.errorCodes.ALREADY_REGISTERED]: lstrings.fio_address_register_screen_not_available + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.INVALID_FIO_ADDRESS]: lstrings.fio_error_invalid_address, + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_DOMAIN_IS_NOT_EXIST]: lstrings.fio_get_reg_info_domain_err_msg, + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.FIO_DOMAIN_IS_NOT_PUBLIC]: lstrings.fio_address_register_domain_is_not_public, + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.SERVER_ERROR]: lstrings.fio_get_reg_info_err_msg, + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.ALREADY_SENT_REGISTRATION_REQ_FOR_DOMAIN]: lstrings.fio_get_reg_info_already_sent_err_msg, + [fioPlugin.currencyInfo.defaultSettings?.errorCodes.ALREADY_REGISTERED]: lstrings.fio_address_register_screen_not_available } if (e.labelCode && errorMessages[e.labelCode]) { throw new Error(errorMessages[e.labelCode]) diff --git a/src/util/fake/fakeBtcInfo.ts b/src/util/fake/fakeBtcInfo.ts index 5c4536cb5dd..4959123cc20 100644 --- a/src/util/fake/fakeBtcInfo.ts +++ b/src/util/fake/fakeBtcInfo.ts @@ -39,9 +39,5 @@ export const btcCurrencyInfo: EdgeCurrencyInfo = { // Explorers: blockExplorer: 'https://blockchair.com/bitcoin/block/%s', addressExplorer: 'https://blockchair.com/bitcoin/address/%s', - transactionExplorer: 'https://blockchair.com/bitcoin/transaction/%s', - - // Images: - symbolImage: ``, - symbolImageDarkMono: `` + transactionExplorer: 'https://blockchair.com/bitcoin/transaction/%s' } diff --git a/src/util/fake/fakeCurrencyPlugin.ts b/src/util/fake/fakeCurrencyPlugin.ts index ee3afce862b..b490d672128 100644 --- a/src/util/fake/fakeCurrencyPlugin.ts +++ b/src/util/fake/fakeCurrencyPlugin.ts @@ -84,7 +84,7 @@ class FakeCurrencyEngine { progress: 0, txs: {} } - this.enabledTokens = currencyInfo.metaTokens.map(token => token.currencyCode) + this.enabledTokens = currencyInfo.metaTokens?.map(token => token.currencyCode) ?? [] this.enabledTokensMap = this.enabledTokens.reduce((prev, token) => { return { ...prev, [token]: true } }, {}) @@ -97,7 +97,7 @@ class FakeCurrencyEngine { } private _getCurrencyCode(tokenId: EdgeTokenId): string { - for (const token of this.currencyInfo.metaTokens) { + for (const token of this.currencyInfo.metaTokens ?? []) { const { currencyCode, contractAddress } = token const tId = contractAddress?.toLowerCase().replace('0x', '') if (tId === tokenId) { @@ -132,7 +132,7 @@ class FakeCurrencyEngine { return { ...prev, [currencyCode]: nativeBalance } } - const metaToken = this.currencyInfo.metaTokens.find(token => token.currencyCode === currencyCode) + const metaToken = this.currencyInfo.metaTokens?.find(token => token.currencyCode === currencyCode) if (metaToken == null) throw new Error(`Invalid token ${currencyCode}`) const nativeBalance = mul(balance, metaToken.denominations[0].multiplier) return { ...prev, [currencyCode]: nativeBalance } @@ -260,13 +260,13 @@ class FakeCurrencyEngine { // Addresses: async getFreshAddress(opts: EdgeTokenIdOptions): Promise { - return { publicAddress: this.currencyInfo.defaultSettings.publicAddress } + return { publicAddress: this.currencyInfo.defaultSettings?.publicAddress } } async addGapLimitAddresses(addresses: string[]): Promise {} async isAddressUsed(address: string): Promise { - return address === this.currencyInfo.defaultSettings.publicAddress + return address === this.currencyInfo.defaultSettings?.publicAddress } // Spending: @@ -284,14 +284,13 @@ class FakeCurrencyEngine { // Check the balances: if (lt(this.getBalance({ tokenId }), total)) { - return await Promise.reject(new InsufficientFundsError()) + return await Promise.reject(new InsufficientFundsError({ tokenId })) } const currencyCode = this._getCurrencyCode(tokenId) // TODO: Return a high-fidelity transaction return { blockHeight: 0, - tokenId: null, currencyCode, date: defaultTx.date, feeRateUsed: { fakePrice: 0 }, diff --git a/src/util/stakeUtils.ts b/src/util/stakeUtils.ts index 482f638a6e4..171d22bbf81 100644 --- a/src/util/stakeUtils.ts +++ b/src/util/stakeUtils.ts @@ -65,7 +65,7 @@ export const getAllocationLocktimeMessage = (allocation: PositionAllocation) => * Returns the icon uris of stake and reward assets. */ export const getPolicyIconUris = ( - { metaTokens, pluginId }: EdgeCurrencyInfo, + { metaTokens = [], pluginId }: EdgeCurrencyInfo, stakePolicy: StakePolicy ): { stakeAssetUris: string[]; rewardAssetUris: string[] } => { const stakeAssetNames = getAssetCurrencyCodes(stakePolicy, 'stakeAssets')