mirror of
https://github.com/BlueWallet/BlueWallet.git
synced 2025-02-24 23:38:57 +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() {
|
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) {
|
static decodeBitcoinUri(uri) {
|
||||||
|
|
|
@ -311,12 +311,16 @@ const ReceiveDetails = () => {
|
||||||
<View style={stylesHook.scrollBody}>
|
<View style={stylesHook.scrollBody}>
|
||||||
{isCustom && (
|
{isCustom && (
|
||||||
<>
|
<>
|
||||||
<BlueText testID="CustomAmountText" style={stylesHook.amount} numberOfLines={1}>
|
{getDisplayAmount() && (
|
||||||
{getDisplayAmount()}
|
<BlueText testID="CustomAmountText" style={stylesHook.amount} numberOfLines={1}>
|
||||||
</BlueText>
|
{getDisplayAmount()}
|
||||||
<BlueText testID="CustomAmountDescriptionText" style={stylesHook.label} numberOfLines={1}>
|
</BlueText>
|
||||||
{customLabel}
|
)}
|
||||||
</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`
|
* @returns {string} BTC amount, accounting for current `customUnit` and `customUnit`
|
||||||
*/
|
*/
|
||||||
const getDisplayAmount = () => {
|
const getDisplayAmount = () => {
|
||||||
switch (customUnit) {
|
if (Number(customAmount) > 0) {
|
||||||
case BitcoinUnit.BTC:
|
switch (customUnit) {
|
||||||
return customAmount + ' BTC';
|
case BitcoinUnit.BTC:
|
||||||
case BitcoinUnit.SATS:
|
return customAmount + ' BTC';
|
||||||
return currency.satoshiToBTC(customAmount) + ' BTC';
|
case BitcoinUnit.SATS:
|
||||||
case BitcoinUnit.LOCAL_CURRENCY:
|
return currency.satoshiToBTC(customAmount) + ' BTC';
|
||||||
return currency.fiatToBTC(customAmount) + ' BTC';
|
case BitcoinUnit.LOCAL_CURRENCY:
|
||||||
|
return currency.fiatToBTC(customAmount) + ' BTC';
|
||||||
|
}
|
||||||
|
return customAmount + ' ' + customUnit;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return customAmount + ' ' + customUnit;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -365,6 +365,14 @@ describe('unit - DeepLinkSchemaMatch', function () {
|
||||||
assert.strictEqual(encoded, 'bitcoin:1BgGZ9tcN4rm9KBzDn7KprQz87SZ26SAMH?amount=20.3&label=Foobar');
|
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', () => {
|
it('can decodeBitcoinUri', () => {
|
||||||
assert.deepStrictEqual(
|
assert.deepStrictEqual(
|
||||||
DeeplinkSchemaMatch.decodeBitcoinUri(
|
DeeplinkSchemaMatch.decodeBitcoinUri(
|
||||||
|
|
Loading…
Add table
Reference in a new issue