Skip to content

Commit

Permalink
[FIX] paypro handling and show all wallets in confirm view
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbazan7 committed Feb 15, 2024
1 parent 71a3d7c commit c51233f
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 102 deletions.
23 changes: 2 additions & 21 deletions src/navigation/wallet/screens/send/SendTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,37 +396,18 @@ const SendTo = () => {
GetInvoiceCurrency(currencyAbbreviation).toLowerCase(),
chain,
);
const OptSelected = payProOptions.paymentOptions.find(
(option: PayProPaymentOption) => option.selected,
);

let selected: PayProPaymentOption | undefined;
if (OptSelected) {
if (invoiceCurrency === OptSelected.currency) {
selected = OptSelected;
} else {
logger.warn(
'PayPro opt selected (v3) and wallet selected network/coin mismatch',
);
return Promise.resolve({
isValid: false,
invalidReason: 'invalidCurrency',
});
}
} else {
selected = payProOptions.paymentOptions.find(
const selected: PayProPaymentOption | undefined = payProOptions.paymentOptions.find(
(option: PayProPaymentOption) =>
invoiceCurrency === option.currency,
);
}

if (selected) {
const isValid = dispatch(checkCoinAndNetwork(selected, true));
if (isValid) {
return Promise.resolve({isValid: true, invalidReason: undefined});
} else {
logger.warn(
'PayPro (v4) and wallet selected network/coin mismatch',
'PayPro and wallet selected network/coin invalid',
);
return Promise.resolve({
isValid: false,
Expand Down
182 changes: 101 additions & 81 deletions src/store/wallet/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ import {
} from '../../../utils/helper-methods';
import {WALLET_DISPLAY_LIMIT} from '../../../navigation/tabs/home/components/Wallet';
import {Network} from '../../../constants';
import {GetInvoiceCurrency, PayProOptions} from '../effects/paypro/paypro';
import {
GetInvoiceCurrency,
PayProOptions,
PayProPaymentOption,
} from '../effects/paypro/paypro';
import {Effect} from '../..';
import {
CoinbaseAccountProps,
Expand Down Expand Up @@ -517,92 +521,108 @@ export const BuildKeysAndWalletsList = ({
rates: Rates;
dispatch: AppDispatch;
}) => {
const selectedPaymentOptions = payProOptions?.paymentOptions?.filter(
option => option.selected,
);
const paymentOptions = selectedPaymentOptions?.length
? selectedPaymentOptions
: payProOptions?.paymentOptions;
const paymentOptions = payProOptions?.paymentOptions;

const isWalletCompatible = (
wallet: Wallet,
network: string | undefined,
paymentOptions: PayProPaymentOption[] | undefined,
) => {
if (paymentOptions?.length) {
return paymentOptions.some(
({currency, network: optionNetwork}) =>
getCurrencyCodeFromCoinAndChain(
GetInvoiceCurrency(wallet.currencyAbbreviation).toLowerCase(),
wallet.chain,
) === currency && wallet.network === optionNetwork,
);
}
if (network) {
return network === wallet.network;
}
return true;
};

const transformWallet = (
walletObj: Wallet,
defaultAltCurrencyIsoCode: string,
rates: Rates,
dispatch: AppDispatch,
) => {
const {
currencyAbbreviation,
hideWallet,
balance,
network,
chain,
credentials,
walletName,
tokenAddress,
} = walletObj;
const {walletName: fallbackName} = credentials;
return {
...walletObj,
cryptoBalance: balance.crypto,
fiatBalance: formatFiatAmount(
convertToFiat(
dispatch(
toFiat(
balance.sat,
defaultAltCurrencyIsoCode,
currencyAbbreviation,
chain,
rates,
tokenAddress,
),
),
hideWallet,
network,
),
defaultAltCurrencyIsoCode,
),
cryptoLockedBalance: balance.cryptoLocked,
fiatLockedBalance: formatFiatAmount(
convertToFiat(
dispatch(
toFiat(
balance.satLocked,
defaultAltCurrencyIsoCode,
currencyAbbreviation,
chain,
rates,
tokenAddress,
),
),
hideWallet,
network,
),
defaultAltCurrencyIsoCode,
),
network,
walletName: walletName || fallbackName,
};
};

return Object.keys(keys)
.map(keyId => {
const keyObj = keys[keyId];
return {
key: keyId,
keyName: keyObj.keyName || 'My Key',
wallets: keys[keyId].wallets
.filter(wallet => !wallet.hideWallet)
.filter(wallet => {
if (paymentOptions?.length) {
return paymentOptions.some(
({currency, network: optionNetwork}) => {
return (
getCurrencyCodeFromCoinAndChain(
GetInvoiceCurrency(
wallet.currencyAbbreviation,
).toLowerCase(),
wallet.chain,
) === currency && wallet.network === optionNetwork
);
},
);
}
if (network) {
return network === wallet.network;
}
return true;
})
.map(walletObj => {
const {
currencyAbbreviation,
hideWallet,
balance,
network,
chain,
credentials: {walletName: fallbackName},
walletName,
tokenAddress,
} = walletObj;
return merge(cloneDeep(walletObj), {
cryptoBalance: balance.crypto,
fiatBalance: formatFiatAmount(
convertToFiat(
dispatch(
toFiat(
balance.sat,
defaultAltCurrencyIsoCode,
currencyAbbreviation,
chain,
rates,
tokenAddress,
),
),
hideWallet,
network,
),
defaultAltCurrencyIsoCode,
),
cryptoLockedBalance: balance.cryptoLocked,
fiatLockedBalance: formatFiatAmount(
convertToFiat(
dispatch(
toFiat(
balance.satLocked,
defaultAltCurrencyIsoCode,
currencyAbbreviation,
chain,
rates,
tokenAddress,
),
),
hideWallet,
network,
),
defaultAltCurrencyIsoCode,
),
network,
walletName: walletName || fallbackName,
});
}),
wallets: keyObj.wallets
.filter(
wallet =>
!wallet.hideWallet &&
isWalletCompatible(wallet, network, paymentOptions),
)
.map(walletObj =>
transformWallet(
walletObj,
defaultAltCurrencyIsoCode,
rates,
dispatch,
),
),
};
})
.filter(key => key.wallets.length);
Expand Down

0 comments on commit c51233f

Please sign in to comment.