Skip to content
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
7 changes: 5 additions & 2 deletions packages/bitcore-wallet-client/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,7 @@ export class API extends EventEmitter {
if (!txp.payProUrl || this.doNotVerifyPayPro) return Promise.resolve();

const chain = txp.chain || Utils.getChain(txp.coin); // getChain -> backwards compatibility
const currency = txp.coin;
const currency = Utils.getCurrencyCodeFromCoinAndChain(txp.coin, chain);
const payload = {
address: txp.from
};
Expand Down Expand Up @@ -2097,7 +2097,10 @@ export class API extends EventEmitter {
this._applyAllSignatures(txp, t);

const chain = txp.chain || Utils.getChain(txp.coin); // getChain -> backwards compatibility
const currency = txp.coin;
const currency = Utils.getCurrencyCodeFromCoinAndChain(
txp.coin,
chain
);
const rawTxUnsigned = t_unsigned.uncheckedSerialize();
const serializedTx = t.serialize({
disableSmallFees: true,
Expand Down
6 changes: 5 additions & 1 deletion packages/bitcore-wallet-client/src/lib/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,9 @@ export const Constants = {
EVM_CHAINS: ['eth', 'matic'],
ETH_TOKEN_OPTS: CWC.Constants.ETH_TOKEN_OPTS,
MATIC_TOKEN_OPTS: CWC.Constants.MATIC_TOKEN_OPTS,
UNITS: CWC.Constants.UNITS
UNITS: CWC.Constants.UNITS,
EVM_CHAINSUFFIXMAP: {
eth: 'e',
matic: 'm'
}
};
12 changes: 12 additions & 0 deletions packages/bitcore-wallet-client/src/lib/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,4 +503,16 @@ export class Utils {
return { uncheckedSerialize: () => unsignedTxs };
}
}

static getCurrencyCodeFromCoinAndChain(coin: string, chain: string): string {
Comment thread
gabrielbazan7 marked this conversation as resolved.
if (coin.toLowerCase() === chain.toLowerCase()) {
return coin.toUpperCase();
}
const suffix = Constants.EVM_CHAINSUFFIXMAP[chain.toLowerCase()];
const coinIsAChain = !!Constants.EVM_CHAINSUFFIXMAP[coin.toLowerCase()];
if (suffix && (coinIsAChain || chain.toLowerCase() !== 'eth')) {
return `${coin.toUpperCase()}_${suffix}`;
}
return coin.toUpperCase();
}
}
12 changes: 6 additions & 6 deletions packages/bitcore-wallet-client/src/lib/payproV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class PayProV2 {
payload,
unsafeBypassValidation = false
}) {
if (currency?.toLowerCase() === 'usdp') currency = 'pax'; // TODO workaround. Remove this when usdp is accepted as an option
if (currency === 'USDP') currency = 'PAX'; // TODO workaround. Remove this when usdp is accepted as an option
let { rawBody, headers } = await PayProV2._asyncRequest({
url: paymentUrl,
method: 'post',
Expand All @@ -220,7 +220,7 @@ export class PayProV2 {
},
args: JSON.stringify({
chain: chain?.toUpperCase(),
currency: currency?.toUpperCase(),
currency,
payload
})
});
Expand Down Expand Up @@ -250,7 +250,7 @@ export class PayProV2 {
unsignedTransactions,
unsafeBypassValidation = false
}) {
if (currency?.toLowerCase() === 'usdp') currency = 'pax'; // TODO workaround. Remove this when usdp is accepted as an option
if (currency === 'USDP') currency = 'PAX'; // TODO workaround. Remove this when usdp is accepted as an option
let { rawBody, headers } = await PayProV2._asyncRequest({
url: paymentUrl,
method: 'post',
Expand All @@ -262,7 +262,7 @@ export class PayProV2 {
},
args: JSON.stringify({
chain: chain?.toUpperCase(),
currency: currency?.toUpperCase(),
currency,
transactions: unsignedTransactions
})
});
Expand Down Expand Up @@ -293,7 +293,7 @@ export class PayProV2 {
unsafeBypassValidation = false,
bpPartner
}) {
if (currency?.toLowerCase() === 'usdp') currency = 'pax'; // TODO workaround. Remove this when usdp is accepted as an option
if (currency === 'USDP') currency = 'PAX'; // TODO workaround. Remove this when usdp is accepted as an option
let { rawBody, headers } = await this._asyncRequest({
url: paymentUrl,
method: 'post',
Expand All @@ -307,7 +307,7 @@ export class PayProV2 {
},
args: JSON.stringify({
chain: chain?.toUpperCase(),
currency: currency?.toUpperCase(),
currency,
transactions: signedTransactions
})
});
Expand Down