mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-24 15:36:59 +01:00
Merge pull request #4179 from BlueWallet/receiveundefined
FIX: 0 amounts in custom receive would result in undefined
This commit is contained in:
commit
acf6c7949b
3 changed files with 40 additions and 15 deletions
|
@ -446,7 +446,16 @@ class DeeplinkSchemaMatch {
|
|||
}
|
||||
|
||||
static bip21encode() {
|
||||
return bip21.encode.apply(bip21, arguments);
|
||||
const argumentsArray = Array.from(arguments);
|
||||
for (const argument of argumentsArray) {
|
||||
if (String(argument.label).replace(' ', '').length === 0) {
|
||||
delete argument.label;
|
||||
}
|
||||
if (!(Number(argument.amount) > 0)) {
|
||||
delete argument.amount;
|
||||
}
|
||||
}
|
||||
return bip21.encode.apply(bip21, argumentsArray);
|
||||
}
|
||||
|
||||
static decodeBitcoinUri(uri) {
|
||||
|
|
|
@ -311,12 +311,16 @@ const ReceiveDetails = () => {
|
|||
<View style={stylesHook.scrollBody}>
|
||||
{isCustom && (
|
||||
<>
|
||||
<BlueText testID="CustomAmountText" style={stylesHook.amount} numberOfLines={1}>
|
||||
{getDisplayAmount()}
|
||||
</BlueText>
|
||||
<BlueText testID="CustomAmountDescriptionText" style={stylesHook.label} numberOfLines={1}>
|
||||
{customLabel}
|
||||
</BlueText>
|
||||
{getDisplayAmount() && (
|
||||
<BlueText testID="CustomAmountText" style={stylesHook.amount} numberOfLines={1}>
|
||||
{getDisplayAmount()}
|
||||
</BlueText>
|
||||
)}
|
||||
{customLabel?.length > 0 && (
|
||||
<BlueText testID="CustomAmountDescriptionText" style={stylesHook.label} numberOfLines={1}>
|
||||
{customLabel}
|
||||
</BlueText>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
|
@ -493,15 +497,19 @@ const ReceiveDetails = () => {
|
|||
* @returns {string} BTC amount, accounting for current `customUnit` and `customUnit`
|
||||
*/
|
||||
const getDisplayAmount = () => {
|
||||
switch (customUnit) {
|
||||
case BitcoinUnit.BTC:
|
||||
return customAmount + ' BTC';
|
||||
case BitcoinUnit.SATS:
|
||||
return currency.satoshiToBTC(customAmount) + ' BTC';
|
||||
case BitcoinUnit.LOCAL_CURRENCY:
|
||||
return currency.fiatToBTC(customAmount) + ' BTC';
|
||||
if (Number(customAmount) > 0) {
|
||||
switch (customUnit) {
|
||||
case BitcoinUnit.BTC:
|
||||
return customAmount + ' BTC';
|
||||
case BitcoinUnit.SATS:
|
||||
return currency.satoshiToBTC(customAmount) + ' BTC';
|
||||
case BitcoinUnit.LOCAL_CURRENCY:
|
||||
return currency.fiatToBTC(customAmount) + ' BTC';
|
||||
}
|
||||
return customAmount + ' ' + customUnit;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
return customAmount + ' ' + customUnit;
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -365,6 +365,14 @@ describe('unit - DeepLinkSchemaMatch', function () {
|
|||
assert.strictEqual(encoded, 'bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar');
|
||||
});
|
||||
|
||||
it('encodes bip21 and discards empty arguments', () => {
|
||||
const encoded = DeeplinkSchemaMatch.bip21encode('1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH', {
|
||||
label: ' ',
|
||||
amoount: undefined,
|
||||
});
|
||||
assert.strictEqual(encoded, 'bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH');
|
||||
});
|
||||
|
||||
it('can decodeBitcoinUri', () => {
|
||||
assert.deepStrictEqual(
|
||||
DeeplinkSchemaMatch.decodeBitcoinUri(
|
||||
|
|
Loading…
Add table
Reference in a new issue