Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] fix paypro handling #1048

Merged
merged 1 commit into from
Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ const TransactionProposalDetails = () => {
</DetailContainer>
<Hr />


{txp.nonce ? (
<>
<DetailContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -599,11 +599,15 @@ const TransactionProposalNotifications = () => {
await sleep(400);
const count = countSuccessAndFailed(data);
if (count.failed > 0) {
const errMsgs = [`There was problem while trying to sign ${count.failed} of your transactions proposals. Please, try again`];
const errMsgs = [
`There was problem while trying to sign ${count.failed} of your transactions proposals. Please, try again`,
];
data.forEach((element, index) => {
if (element instanceof Error) {
errMsgs.push(`[ERROR ${index + 1}] ${BWCErrorMessage(element)}`);
}
errMsgs.push(
`[ERROR ${index + 1}] ${BWCErrorMessage(element)}`,
);
}
});
await showErrorMessage(
CustomErrorMessage({
Expand Down
26 changes: 3 additions & 23 deletions src/navigation/wallet/screens/send/SendTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,38 +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',
);
logger.warn('PayPro and wallet selected network/coin invalid');
return Promise.resolve({
isValid: false,
invalidReason: 'invalidCurrency',
Expand Down
67 changes: 33 additions & 34 deletions src/store/wallet/effects/send/send.ts
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,13 @@ export const buildTxDetails =
fee = proposal.fee || 0; // proposal fee is zero for coinbase
}

const selectedTransactionCurrency =
invoice?.buyerProvidedInfo!.selectedTransactionCurrency ||
getCurrencyCodeFromCoinAndChain(
wallet.currencyAbbreviation,
wallet.chain,
);
const selectedTransactionCurrency = getCurrencyCodeFromCoinAndChain(
wallet.currencyAbbreviation,
wallet.chain,
);

const isOffChain = !proposal;
if (invoice && selectedTransactionCurrency) {
if (invoice) {
amount = isOffChain
? invoice.paymentSubtotals[selectedTransactionCurrency]
: invoice.paymentTotals[selectedTransactionCurrency];
Expand All @@ -490,11 +488,7 @@ export const buildTxDetails =

amount = Number(amount); // Support BN (use number instead string only for view)
let effectiveRate;
if (
invoice &&
selectedTransactionCurrency &&
defaultAltCurrencyIsoCode === invoice.currency
) {
if (invoice && defaultAltCurrencyIsoCode === invoice.currency) {
effectiveRate = dispatch(
getInvoiceEffectiveRate(
invoice,
Expand Down Expand Up @@ -1165,7 +1159,11 @@ export const publishAndSignMultipleProposals =
}
}
// Process transactions with a nonce sequentially
const resultsWithNonce: (Partial<TransactionProposal> | void | Error)[] = [];
const resultsWithNonce: (
| Partial<TransactionProposal>
| void
| Error
)[] = [];
const evmTxsWithNonce = txps.filter(txp => txp.nonce !== undefined);
evmTxsWithNonce.sort((a, b) => (a.nonce || 0) - (b.nonce || 0));
for (const txp of evmTxsWithNonce) {
Expand Down Expand Up @@ -1195,28 +1193,29 @@ export const publishAndSignMultipleProposals =

// Process transactions without a nonce concurrently
const withoutNonce = txps.filter(txp => txp.nonce === undefined);
const promisesWithoutNonce: Promise<Partial<TransactionProposal> | void | Error>[] =
withoutNonce.map(txp =>
dispatch(
publishAndSign({
txp,
key,
wallet,
recipient,
password,
signingMultipleProposals,
}),
).catch(err => {
const errorStr =
err instanceof Error ? err.message : JSON.stringify(err);
dispatch(
LogActions.error(
`Error signing transaction proposal: ${errorStr}`,
),
);
return err;
const promisesWithoutNonce: Promise<
Partial<TransactionProposal> | void | Error
>[] = withoutNonce.map(txp =>
dispatch(
publishAndSign({
txp,
key,
wallet,
recipient,
password,
signingMultipleProposals,
}),
);
).catch(err => {
const errorStr =
err instanceof Error ? err.message : JSON.stringify(err);
dispatch(
LogActions.error(
`Error signing transaction proposal: ${errorStr}`,
),
);
return err;
}),
);
const resultsWithoutNonce = await Promise.all(promisesWithoutNonce);
return resolve([...resultsWithNonce, ...resultsWithoutNonce]);
} catch (err) {
Expand Down
7 changes: 1 addition & 6 deletions src/store/wallet/utils/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,7 @@ 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;
return Object.keys(keys)
.map(keyId => {
const keyObj = keys[keyId];
Expand Down