From 8fd75958c3afa930d7e9cfd81c1b9563a20de200 Mon Sep 17 00:00:00 2001 From: William Swanson Date: Thu, 21 Dec 2023 18:54:26 -0800 Subject: [PATCH] Make `WalletListResult` a union type --- src/actions/DeepLinkingActions.ts | 4 +- src/actions/PaymentProtoActions.tsx | 9 ++-- src/actions/ScanActions.tsx | 5 ++- src/components/FioAddress/FioActionSubmit.tsx | 5 ++- src/components/modals/TransferModal.tsx | 10 +++-- src/components/modals/WalletListModal.tsx | 45 +++++++++++-------- .../scenes/CreateWalletAccountSelectScene.tsx | 5 ++- src/components/scenes/CryptoExchangeScene.tsx | 4 +- .../scenes/Fio/FioAddressRegisterScene.tsx | 5 ++- .../FioAddressRegisterSelectWalletScene.tsx | 5 ++- .../scenes/Fio/FioDomainRegisterScene.tsx | 5 ++- .../FioDomainRegisterSelectWalletScene.tsx | 5 ++- .../scenes/Fio/FioRequestListScene.tsx | 5 ++- .../scenes/Loans/LoanCreateScene.tsx | 11 ++--- .../scenes/Loans/LoanDashboardScene.tsx | 6 ++- .../scenes/Loans/LoanManageScene.tsx | 18 ++++---- src/components/scenes/RequestScene.tsx | 5 ++- src/components/scenes/SendScene2.tsx | 4 +- src/components/scenes/WcConnectScene.tsx | 5 ++- src/components/themed/TransactionListTop.tsx | 6 +-- src/components/tiles/AddressTile2.tsx | 6 +-- .../edgeProvider/EdgeProviderServer.tsx | 7 ++- src/plugins/gui/RewardsCardPlugin.tsx | 5 +-- src/plugins/gui/amountQuotePlugin.ts | 2 +- src/plugins/gui/fiatPlugin.tsx | 6 +-- src/plugins/gui/fiatPluginTypes.ts | 9 ++-- 26 files changed, 112 insertions(+), 90 deletions(-) diff --git a/src/actions/DeepLinkingActions.ts b/src/actions/DeepLinkingActions.ts index 9f7460b1c90..4cef5e5218a 100644 --- a/src/actions/DeepLinkingActions.ts +++ b/src/actions/DeepLinkingActions.ts @@ -155,7 +155,7 @@ export async function handleLink(navigation: NavigationBase, dispatch: Dispatch, case 'azteco': { if (!allWalletsLoaded) return false const result = await pickWallet({ account, assets: [{ pluginId: 'bitcoin' }], navigation, showCreateWallet: true }) - if (result == null) { + if (result?.type !== 'wallet') { // pickWallet returning undefined means user has no matching wallet. // This should never happen. Even if the user doesn't have a bitcoin wallet, they will be presented with // the option to create one. @@ -235,7 +235,7 @@ export async function handleLink(navigation: NavigationBase, dispatch: Dispatch, } // User backed out of choosing a wallet - if (walletListResult.walletId == null) return true + if (walletListResult.type !== 'wallet') return true const widUri = matchingWalletIdsAndUris.find(({ walletId }) => walletId === walletListResult.walletId) if (widUri == null) { diff --git a/src/actions/PaymentProtoActions.tsx b/src/actions/PaymentProtoActions.tsx index db0d9ed6e93..310d4f059c9 100644 --- a/src/actions/PaymentProtoActions.tsx +++ b/src/actions/PaymentProtoActions.tsx @@ -158,14 +158,13 @@ export async function launchPaymentProto(navigation: NavigationBase, account: Ed selectedWallet = wallet selectedCurrencyCode = currencyCode } else { - const walletListResult = await pickWallet({ account, assets: paymentAssets, navigation }) - if (walletListResult == null) { + const result = await pickWallet({ account, assets: paymentAssets, navigation }) + if (result?.type !== 'wallet') { throw new PaymentProtoError('NoPaymentOption', { text: paymentCurrencies.join(', ') }) } - - const { walletId } = walletListResult + const { walletId, currencyCode } = result selectedWallet = currencyWallets[walletId ?? ''] - selectedCurrencyCode = walletListResult.currencyCode + selectedCurrencyCode = currencyCode } if (selectedWallet == null) return diff --git a/src/actions/ScanActions.tsx b/src/actions/ScanActions.tsx index 19319f24d48..5dcb06531dc 100644 --- a/src/actions/ScanActions.tsx +++ b/src/actions/ScanActions.tsx @@ -96,8 +96,9 @@ export const doRequestAddress = async (navigation: NavigationBase, account: Edge await Airship.show(bridge => ( - )).then(async ({ walletId, currencyCode }) => { - if (walletId != null && currencyCode != null) { + )).then(async result => { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result const { currencyWallets } = account const wallet = currencyWallets[walletId] diff --git a/src/components/FioAddress/FioActionSubmit.tsx b/src/components/FioAddress/FioActionSubmit.tsx index a646b51a618..e698d2a490d 100644 --- a/src/components/FioAddress/FioActionSubmit.tsx +++ b/src/components/FioAddress/FioActionSubmit.tsx @@ -119,8 +119,9 @@ class FioActionSubmitComponent extends React.Component { Airship.show(bridge => ( )) - .then(({ walletId, currencyCode }: WalletListResult) => { - if (walletId && currencyCode) { + .then(result => { + if (result?.type === 'wallet') { + const { walletId } = result this.props.currencyWallets[walletId] && this.setState({ paymentWallet: this.props.currencyWallets[walletId] }, () => { this.setBalance() diff --git a/src/components/modals/TransferModal.tsx b/src/components/modals/TransferModal.tsx index 23a85520623..efefba84cf4 100644 --- a/src/components/modals/TransferModal.tsx +++ b/src/components/modals/TransferModal.tsx @@ -50,10 +50,11 @@ export const TransferModal = ({ account, bridge, depositOrSend, navigation }: Pr Airship.clear() }) const handleSend = useHandler(async () => { - const { walletId, tokenId } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId != null) { + if (result?.type === 'wallet') { + const { walletId, tokenId } = result navigation.push('send2', { walletId, tokenId, hiddenFeaturesMap: { scamWarning: false } }) } Airship.clear() @@ -61,11 +62,12 @@ export const TransferModal = ({ account, bridge, depositOrSend, navigation }: Pr const handleReceive = useHandler(async () => { Airship.clear() - const { walletId, tokenId } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId != null) { + if (result?.type === 'wallet') { + const { walletId, tokenId } = result await dispatch(selectWalletToken({ navigation, walletId, tokenId })) navigation.navigate('request', {}) } diff --git a/src/components/modals/WalletListModal.tsx b/src/components/modals/WalletListModal.tsx index b02960c5d56..fe084861593 100644 --- a/src/components/modals/WalletListModal.tsx +++ b/src/components/modals/WalletListModal.tsx @@ -14,7 +14,7 @@ import { config } from '../../theme/appConfig' import { useSelector } from '../../types/reactRedux' import { NavigationBase } from '../../types/routerTypes' import { BooleanMap, EdgeAsset } from '../../types/types' -import { getCurrencyCode, isKeysOnlyPlugin } from '../../util/CurrencyInfoHelpers' +import { getCurrencyCode, getTokenId, isKeysOnlyPlugin } from '../../util/CurrencyInfoHelpers' import { CustomAsset } from '../data/row/CustomAssetRow' import { PaymentMethodRow } from '../data/row/PaymentMethodRow' import { Airship, showError } from '../services/AirshipInstance' @@ -28,18 +28,20 @@ import { WalletList } from '../themed/WalletList' import { WalletListCurrencyRow } from '../themed/WalletListCurrencyRow' import { ButtonsModal } from './ButtonsModal' -export interface WalletListResult { - currencyCode?: string - tokenId?: string - walletId?: string - - // Wyre buy/sell - isBankSignupRequest?: boolean - fiatAccountId?: string - - // Custom asset selection - customAsset?: CustomAsset -} +export type WalletListResult = + | { + type: 'wallet' + walletId: string + tokenId: string | undefined + /** @deprecated Use tokenId instead */ + currencyCode: string + } + | { type: 'wyre'; fiatAccountId: string } + | { type: 'bankSignupRequest' } + | { type: 'custom'; customAsset?: CustomAsset } + // User cancelled. + // This is consistent with other modals that return `T | undefined`: + | undefined interface Props { bridge: AirshipBridge @@ -123,16 +125,20 @@ export function WalletListModal(props: Props) { // #region Handlers const handleCancel = useHandler(() => { - bridge.resolve({}) + bridge.resolve(undefined) }) const handlePaymentMethodPress = useHandler((fiatAccountId: string) => () => { - bridge.resolve({ fiatAccountId }) + bridge.resolve({ type: 'wyre', fiatAccountId }) }) const handleWalletListPress = useHandler((walletId: string, currencyCode: string, tokenId?: string, customAsset?: CustomAsset) => { if (walletId === '') { handleCancel() showError(lstrings.network_alert_title) - } else bridge.resolve({ walletId, currencyCode, customAsset, tokenId }) + } else if (customAsset != null) { + bridge.resolve({ type: 'custom', customAsset }) + } else if (walletId != null && currencyCode != null) { + bridge.resolve({ type: 'wallet', walletId, currencyCode, tokenId }) + } }) const handleSearchClear = useHandler(() => { setSearchText('') @@ -153,7 +159,7 @@ export function WalletListModal(props: Props) { }} /> )) - if (result === 'continue') await bridge.resolve({ isBankSignupRequest: true }) + if (result === 'continue') await bridge.resolve({ type: 'bankSignupRequest' }) }) // #endregion Handlers @@ -280,7 +286,7 @@ export const pickWallet = async ({ headerTitle?: string navigation: NavigationBase showCreateWallet?: boolean -}): Promise => { +}): Promise => { const { currencyWallets } = account const walletIdMap: BooleanMap = {} @@ -315,7 +321,8 @@ export const pickWallet = async ({ if (assets != null && matchingAssets.length === 1 && Object.keys(walletIdMap).length === 1) { // Only one matching wallet and asset. Auto pick the wallet const [walletId, currencyCode] = Object.keys(walletIdMap)[0].split(':') - return { walletId, currencyCode } + const tokenId = getTokenId(account, currencyWallets[walletId].currencyInfo.pluginId, currencyCode) + return { type: 'wallet', walletId, currencyCode, tokenId } } else { const walletListResult = await Airship.show(bridge => ( { Airship.show(bridge => ( )) - .then(async ({ walletId, currencyCode }: WalletListResult) => { - if (walletId && currencyCode) { + .then(async result => { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result dispatch({ type: 'WALLET_ACCOUNT_ACTIVATION_ESTIMATE_ERROR', data: '' }) setWalletId(walletId) const createdWalletInstance = await handleRenameAndReturnWallet() diff --git a/src/components/scenes/CryptoExchangeScene.tsx b/src/components/scenes/CryptoExchangeScene.tsx index 5bf8849725b..5ea88db5878 100644 --- a/src/components/scenes/CryptoExchangeScene.tsx +++ b/src/components/scenes/CryptoExchangeScene.tsx @@ -281,8 +281,8 @@ export class CryptoExchangeComponent extends React.Component { /> )) .then(async result => { - const { walletId, currencyCode } = result - if (walletId != null && currencyCode != null) { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result await this.props.onSelectWallet(walletId, currencyCode, whichWallet) } }) diff --git a/src/components/scenes/Fio/FioAddressRegisterScene.tsx b/src/components/scenes/Fio/FioAddressRegisterScene.tsx index fa5d359b5b8..958a600215c 100644 --- a/src/components/scenes/Fio/FioAddressRegisterScene.tsx +++ b/src/components/scenes/Fio/FioAddressRegisterScene.tsx @@ -295,8 +295,9 @@ export class FioAddressRegister extends React.Component { selectFioWallet = async () => { await Airship.show(bridge => ( - )).then(({ walletId, currencyCode }: WalletListResult) => { - if (walletId && currencyCode) { + )).then(result => { + if (result?.type === 'wallet') { + const { walletId } = result this.handleFioWalletChange(walletId) } }) diff --git a/src/components/scenes/Fio/FioAddressRegisterSelectWalletScene.tsx b/src/components/scenes/Fio/FioAddressRegisterSelectWalletScene.tsx index 0cb761fede9..ea67fbe6c90 100644 --- a/src/components/scenes/Fio/FioAddressRegisterSelectWalletScene.tsx +++ b/src/components/scenes/Fio/FioAddressRegisterSelectWalletScene.tsx @@ -120,10 +120,11 @@ export class FioAddressRegisterSelectWallet extends React.Component { const { supportedAssets } = this.state - const { walletId, currencyCode } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId && currencyCode) { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result this.setState({ paymentWallet: { id: walletId, currencyCode } }) } } diff --git a/src/components/scenes/Fio/FioDomainRegisterScene.tsx b/src/components/scenes/Fio/FioDomainRegisterScene.tsx index a8423b71119..aaf340530d2 100644 --- a/src/components/scenes/Fio/FioDomainRegisterScene.tsx +++ b/src/components/scenes/Fio/FioDomainRegisterScene.tsx @@ -182,10 +182,11 @@ export class FioDomainRegister extends React.PureComponent { } selectFioWallet = async () => { - const { walletId, currencyCode } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId && currencyCode) { + if (result?.type === 'wallet') { + const { walletId } = result this.handleFioWalletChange(walletId) } } diff --git a/src/components/scenes/Fio/FioDomainRegisterSelectWalletScene.tsx b/src/components/scenes/Fio/FioDomainRegisterSelectWalletScene.tsx index 400d40daaf0..bd4ddfce317 100644 --- a/src/components/scenes/Fio/FioDomainRegisterSelectWalletScene.tsx +++ b/src/components/scenes/Fio/FioDomainRegisterSelectWalletScene.tsx @@ -105,10 +105,11 @@ class FioDomainRegisterSelectWallet extends React.PureComponent { const { supportedAssets } = this.state - const { walletId, currencyCode } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId && currencyCode) { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result this.setState({ paymentWallet: { id: walletId, currencyCode } }) } } diff --git a/src/components/scenes/Fio/FioRequestListScene.tsx b/src/components/scenes/Fio/FioRequestListScene.tsx index 50cfcc89f68..a32f4ade8aa 100644 --- a/src/components/scenes/Fio/FioRequestListScene.tsx +++ b/src/components/scenes/Fio/FioRequestListScene.tsx @@ -376,10 +376,11 @@ class FioRequestList extends React.Component { const tokenId = getTokenId(account, pluginId, tokenCode) const allowedAssets = [{ pluginId, tokenId }] - const { walletId, currencyCode } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId && currencyCode) { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result onSelectWallet(walletId, currencyCode) await this.sendCrypto(selectedFioPendingRequest, walletId, currencyCode) } diff --git a/src/components/scenes/Loans/LoanCreateScene.tsx b/src/components/scenes/Loans/LoanCreateScene.tsx index 3871672f6e4..cd508e69156 100644 --- a/src/components/scenes/Loans/LoanCreateScene.tsx +++ b/src/components/scenes/Loans/LoanCreateScene.tsx @@ -250,23 +250,24 @@ export const LoanCreateScene = (props: Props) => { filterActivation /> )) - .then(async ({ walletId, currencyCode, isBankSignupRequest, fiatAccountId }) => { - if (isBankSignupRequest) { + .then(async result => { + if (result?.type === 'bankSignupRequest') { // Open bank plugin for new user signup navigation.navigate('pluginView', { plugin: guiPlugins.wyre, deepPath: '', deepQuery: {} }) - } else if (fiatAccountId != null) { + } else if (result?.type === 'wyre') { + const { fiatAccountId } = result // Set a hard-coded intermediate AAVE loan destination asset (USDC) to // use for the bank sell step that comes after the initial loan setDestBankId(fiatAccountId) setDestWallet(borrowEngineWallet) setDestTokenId(hardDestTokenAddr) - } else if (walletId != null && currencyCode != null) { + } else if (result?.type === 'wallet') { + const { walletId, currencyCode, tokenId } = result const selectedWallet = wallets[walletId] - const tokenId = getTokenId(account, selectedWallet.currencyInfo.pluginId, currencyCode) if (isSrc) { setSrcWalletId(walletId) setSrcTokenId(tokenId) diff --git a/src/components/scenes/Loans/LoanDashboardScene.tsx b/src/components/scenes/Loans/LoanDashboardScene.tsx index eb59bfff812..b6c91bfdf63 100644 --- a/src/components/scenes/Loans/LoanDashboardScene.tsx +++ b/src/components/scenes/Loans/LoanDashboardScene.tsx @@ -98,7 +98,7 @@ export const LoanDashboardScene = (props: Props) => { const allowedAssets = SUPPORTED_WALLET_PLUGIN_IDS.map(pluginId => ({ pluginId })) // Only show the wallet picker if the user owns more than one polygon wallet. - const { walletId: newWalletId } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( { excludeWalletIds={Object.keys(loanAccountsMap)} /> )) - newLoanWallet = newWalletId == null ? null : currencyWallets[newWalletId] + if (result?.type === 'wallet') { + newLoanWallet = currencyWallets[result.walletId] + } } else if (hardPluginWalletIds.length === 1) { // If the user owns one polygon wallet, auto-select that wallet for the loan creation newLoanWallet = currencyWallets[hardPluginWalletIds[0]] diff --git a/src/components/scenes/Loans/LoanManageScene.tsx b/src/components/scenes/Loans/LoanManageScene.tsx index 9a16a3eb4bb..ac3681a1123 100644 --- a/src/components/scenes/Loans/LoanManageScene.tsx +++ b/src/components/scenes/Loans/LoanManageScene.tsx @@ -369,24 +369,26 @@ export const LoanManageSceneComponent = (props: Props) => { filterActivation /> )) - .then(async ({ walletId, currencyCode, isBankSignupRequest, fiatAccountId: wyreAccountId, customAsset }) => { - if (isBankSignupRequest) { + .then(async result => { + if (result?.type === 'bankSignupRequest') { // Open bank plugin for new user signup navigation.navigate('pluginView', { plugin: guiPlugins.wyre, deepPath: '', deepQuery: {} }) - } else if (customAsset != null) { - setSelectedAsset({ wallet: borrowEngineWallet, tokenId: hardAllowedDebtAssets[0].tokenId, customAsset: customAsset }) - } else if (wyreAccountId != null) { - const paymentMethod = bankAccountsMap[wyreAccountId] + } else if (result?.type === 'custom') { + const { customAsset } = result + setSelectedAsset({ wallet: borrowEngineWallet, tokenId: hardAllowedDebtAssets[0].tokenId, customAsset }) + } else if (result?.type === 'wyre') { + const { fiatAccountId } = result + const paymentMethod = bankAccountsMap[fiatAccountId] // Set a hard-coded intermediate AAVE loan destination asset (USDC) to // use for the bank sell step that comes after the initial loan setSelectedAsset({ wallet: borrowEngineWallet, tokenId: hardDebtTokenId, paymentMethod }) - } else if (walletId != null && currencyCode != null) { + } else if (result?.type === 'wallet') { + const { walletId, tokenId } = result const selectedWallet = wallets[walletId] - const tokenId = getTokenId(account, selectedWallet.currencyInfo.pluginId, currencyCode) setSelectedAsset({ wallet: selectedWallet, tokenId }) } }) diff --git a/src/components/scenes/RequestScene.tsx b/src/components/scenes/RequestScene.tsx index e405a8f6dff..f7d13513231 100644 --- a/src/components/scenes/RequestScene.tsx +++ b/src/components/scenes/RequestScene.tsx @@ -244,8 +244,9 @@ export class RequestSceneComponent extends React.Component { handleOpenWalletListModal = () => { const { account } = this.props Airship.show(bridge => ) - .then(async ({ walletId, currencyCode }: WalletListResult) => { - if (walletId && currencyCode) { + .then(async result => { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result const wallet = account.currencyWallets[walletId] const tokenId = getTokenId(account, wallet.currencyInfo.pluginId, currencyCode) await this.props.onSelectWallet(this.props.navigation, walletId, tokenId) diff --git a/src/components/scenes/SendScene2.tsx b/src/components/scenes/SendScene2.tsx index 20bb10130b8..feee5513769 100644 --- a/src/components/scenes/SendScene2.tsx +++ b/src/components/scenes/SendScene2.tsx @@ -380,8 +380,8 @@ const SendComponent = (props: Props) => { const handleWalletPress = useHandler(() => { Airship.show(bridge => ) - .then((result: WalletListResult) => { - if (result.walletId == null || result.currencyCode == null) { + .then(result => { + if (result?.type !== 'wallet') { return } setWalletId(result.walletId) diff --git a/src/components/scenes/WcConnectScene.tsx b/src/components/scenes/WcConnectScene.tsx index 91e09d77f4f..d8eadcf7e38 100644 --- a/src/components/scenes/WcConnectScene.tsx +++ b/src/components/scenes/WcConnectScene.tsx @@ -82,10 +82,11 @@ export const WcConnectScene = (props: Props) => { } const handleWalletListModal = useHandler(async () => { - const { walletId, currencyCode } = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - if (walletId && currencyCode) { + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result const wallet = account.currencyWallets[walletId] const tokenId = getTokenId(account, wallet.currencyInfo.pluginId, currencyCode) await dispatch(selectWalletToken({ navigation, walletId, tokenId })) diff --git a/src/components/themed/TransactionListTop.tsx b/src/components/themed/TransactionListTop.tsx index d8fd18dd54a..1bab761ffea 100644 --- a/src/components/themed/TransactionListTop.tsx +++ b/src/components/themed/TransactionListTop.tsx @@ -166,9 +166,9 @@ export class TransactionListTopComponent extends React.PureComponent(bridge => ) - .then((result: WalletListResult) => { - const { currencyCode, walletId } = result - if (walletId != null && currencyCode != null) { + .then(result => { + if (result?.type === 'wallet') { + const { currencyCode, walletId } = result const wallet = account.currencyWallets[walletId] if (wallet == null) return const tokenId = getTokenId(account, wallet.currencyInfo.pluginId, currencyCode) diff --git a/src/components/tiles/AddressTile2.tsx b/src/components/tiles/AddressTile2.tsx index 46ddd646ca3..71bd0b07042 100644 --- a/src/components/tiles/AddressTile2.tsx +++ b/src/components/tiles/AddressTile2.tsx @@ -221,9 +221,9 @@ export const AddressTile2 = React.forwardRef((props: Props, ref: React.Forwarded excludeWalletIds={[coreWallet.id]} /> )) - .then(async walletList => { - const { walletId } = walletList - if (walletId == null) return + .then(async result => { + if (result?.type !== 'wallet') return + const { walletId } = result const wallet = currencyWallets[walletId] // Prefer segwit address if the selected wallet has one diff --git a/src/controllers/edgeProvider/EdgeProviderServer.tsx b/src/controllers/edgeProvider/EdgeProviderServer.tsx index 130c9ffb466..8aeeb89e710 100644 --- a/src/controllers/edgeProvider/EdgeProviderServer.tsx +++ b/src/controllers/edgeProvider/EdgeProviderServer.tsx @@ -102,12 +102,12 @@ export class EdgeProviderServer implements EdgeProviderMethods { throw new Error('No allowed assets specified') } - const selectedWallet = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) + if (result?.type === 'wallet') { + const { walletId, currencyCode } = result - const { walletId, currencyCode } = selectedWallet - if (walletId && currencyCode) { this._selectedWallet = account.currencyWallets[walletId] if (this._selectedWallet == null) throw new Error(`Missing wallet for walletId`) const chainCode = this._selectedWallet.currencyInfo.currencyCode @@ -139,7 +139,6 @@ export class EdgeProviderServer implements EdgeProviderMethods { } return returnCurrencyCode } - throw new Error(lstrings.user_closed_modal_no_wallet) } diff --git a/src/plugins/gui/RewardsCardPlugin.tsx b/src/plugins/gui/RewardsCardPlugin.tsx index 32e7c3ae9e7..78176da588b 100644 --- a/src/plugins/gui/RewardsCardPlugin.tsx +++ b/src/plugins/gui/RewardsCardPlugin.tsx @@ -136,7 +136,6 @@ export const makeRewardsCardPlugin: FiatPluginFactory = async params => { const showNewCardEnterAmount = async (walletListResult: FiatPluginWalletPickerResult) => { const { walletId, currencyCode, tokenId } = walletListResult - if (walletId == null || currencyCode == null) return const wallet = account.currencyWallets[walletId] if (wallet == null) return await showUi.showError(new Error(`Missing wallet with ID ${walletId}`)) @@ -230,12 +229,12 @@ export const makeRewardsCardPlugin: FiatPluginFactory = async params => { } const showNewCardWalletListModal = async () => { - const walletListResult: FiatPluginWalletPickerResult = await showUi.walletPicker({ + const result = await showUi.walletPicker({ headerTitle: lstrings.select_wallet_to_purchase_card_title, allowedAssets, showCreateWallet: false }) - await showNewCardEnterAmount(walletListResult) + if (result != null) await showNewCardEnterAmount(result) } const showWelcome = async () => { diff --git a/src/plugins/gui/amountQuotePlugin.ts b/src/plugins/gui/amountQuotePlugin.ts index 9e27eaf01a5..89b56bdd708 100644 --- a/src/plugins/gui/amountQuotePlugin.ts +++ b/src/plugins/gui/amountQuotePlugin.ts @@ -146,8 +146,8 @@ export const amountQuoteFiatPlugin: FiatPluginFactory = async (params: FiatPlugi showCreateWallet: direction === 'buy' }) + if (walletListResult == null) return const { walletId, currencyCode, tokenId } = walletListResult - if (walletId == null || currencyCode == null) return const coreWallet = account.currencyWallets[walletId] const currencyPluginId = coreWallet.currencyInfo.pluginId diff --git a/src/plugins/gui/fiatPlugin.tsx b/src/plugins/gui/fiatPlugin.tsx index db1232c94d1..17e15d59545 100644 --- a/src/plugins/gui/fiatPlugin.tsx +++ b/src/plugins/gui/fiatPlugin.tsx @@ -89,12 +89,12 @@ export const executePlugin = async (params: { if (Platform.OS === 'ios') await SafariView.show({ url: params.url }) else await CustomTabs.openURL(params.url) }, - walletPicker: async (params): Promise => { + walletPicker: async (params): Promise => { const { headerTitle, allowedAssets, showCreateWallet } = params - const walletListResult = await Airship.show(bridge => ( + const result = await Airship.show(bridge => ( )) - return walletListResult + if (result?.type === 'wallet') return result }, showError: async (e: Error): Promise => showError(e), listModal: async (params: FiatPluginListModalParams): Promise => { diff --git a/src/plugins/gui/fiatPluginTypes.ts b/src/plugins/gui/fiatPluginTypes.ts index 72cccb475e9..0421ffa9271 100644 --- a/src/plugins/gui/fiatPluginTypes.ts +++ b/src/plugins/gui/fiatPluginTypes.ts @@ -96,9 +96,10 @@ export interface FiatPluginOpenExternalWebViewParams { } export interface FiatPluginWalletPickerResult { - walletId?: string - tokenId?: string - currencyCode?: string + walletId: string + tokenId: string | undefined + /** @deprecated Use tokenId instead */ + currencyCode: string } export interface FiatPluginUi { @@ -107,7 +108,7 @@ export interface FiatPluginUi { showToastSpinner: (message: string, promise: Promise) => Promise openWebView: (params: FiatPluginOpenWebViewParams) => Promise openExternalWebView: (params: FiatPluginOpenExternalWebViewParams) => Promise - walletPicker: (params: { headerTitle: string; allowedAssets?: EdgeAsset[]; showCreateWallet?: boolean }) => Promise + walletPicker: (params: { headerTitle: string; allowedAssets?: EdgeAsset[]; showCreateWallet?: boolean }) => Promise showError: (error: Error) => Promise listModal: (params: FiatPluginListModalParams) => Promise enterAmount: (params: AppParamList['guiPluginEnterAmount']) => void