FIX: address input qrcode denomination reset

This commit is contained in:
Ivan Vershigora 2021-03-24 20:17:17 +03:00
parent 0ec80f0616
commit 1ae82a1a7b
2 changed files with 49 additions and 19 deletions

View File

@ -156,7 +156,7 @@ const SendDetails = () => {
// load cached fees
AsyncStorage.getItem(NetworkTransactionFee.StorageKey)
.then(async res => {
.then(res => {
const fees = JSON.parse(res);
if (!fees?.fastestFee) return;
setNetworkTransactionFees(fees);
@ -325,7 +325,7 @@ const SendDetails = () => {
*
* @param data {String} Can be address or `bitcoin:xxxxxxx` uri scheme, or invalid garbage
*/
const processAddressData = async data => {
const processAddressData = data => {
setIsLoading(true);
if (!data.replace) {
// user probably scanned PSBT and got an object instead of string..?
@ -339,10 +339,6 @@ const SendDetails = () => {
addresses[scrollIndex.current].address = dataWithoutSchema;
return [...addresses];
});
setUnits(units => {
units[scrollIndex.current] = amountUnit;
return [...units];
});
setIsLoading(false);
return;
}
@ -585,7 +581,7 @@ const SendDetails = () => {
*
* @returns {Promise<void>}
*/
const importQrTransaction = async () => {
const importQrTransaction = () => {
if (wallet.type !== WatchOnlyWallet.type) {
return Alert.alert(loc.errors.error, 'Error: importing transaction in non-watchonly wallet (this should never happen)');
}
@ -601,7 +597,7 @@ const SendDetails = () => {
});
};
const importQrTransactionOnBarScanned = async ret => {
const importQrTransactionOnBarScanned = ret => {
navigation.dangerouslyGetParent().pop();
if (!ret.data) ret = { data: ret };
if (ret.data.toUpperCase().startsWith('UR')) {
@ -734,7 +730,7 @@ const SendDetails = () => {
setOptionsVisible(false);
};
const importTransactionMultisig = async () => {
const importTransactionMultisig = () => {
return _importTransactionMultisig();
};
@ -752,7 +748,7 @@ const SendDetails = () => {
}
};
const importTransactionMultisigScanQr = async () => {
const importTransactionMultisigScanQr = () => {
setOptionsVisible(false);
navigation.navigate('ScanQRCodeRoot', {
screen: 'ScanQRCode',
@ -1237,7 +1233,7 @@ const SendDetails = () => {
inputAccessoryViewID={wallet.allowSendMax() ? BlueUseAllFundsButton.InputAccessoryViewID : null}
/>
<AddressInput
onChangeText={async text => {
onChangeText={text => {
text = text.trim();
const { address, amount, memo: lmemo, payjoinUrl } = DeeplinkSchemaMatch.decodeBitcoinUri(text);
setAddresses(addresses => {

View File

@ -538,10 +538,10 @@ describe('BlueWallet UI Tests', () => {
await device.pressBack();
await device.pressBack();
await element(by.id('changeAmountUnitButton')).tap(); // switched to FIAT
await element(by.id('changeAmountUnitButton')).tap(); // switched to SATS
await element(by.id('BlueAddressInputScanQrButton')).tap();
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
await sleep(1000);
@ -564,10 +564,44 @@ describe('BlueWallet UI Tests', () => {
assert.strictEqual(bitcoin.address.fromOutputScript(transaction.outs[0].script), 'bc1qnapskphjnwzw2w3dk4anpxntunc77v6qrua0f7');
assert.strictEqual(transaction.outs[0].value, 15000);
// now, testing scanQR with just address after amount set to 1.1 USD. Denomination should not change after qrcode scan
await device.pressBack();
await device.pressBack();
await element(by.id('changeAmountUnitButton')).tap(); // switched to SATS
await element(by.id('changeAmountUnitButton')).tap(); // switched to FIAT
await element(by.id('BitcoinAmountInput')).replaceText('1.1');
await element(by.id('BlueAddressInputScanQrButton')).tap();
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
await sleep(1000);
}
await element(by.id('scanQrBackdoorInput')).replaceText('bc1qnapskphjnwzw2w3dk4anpxntunc77v6qrua0f7');
await element(by.id('scanQrBackdoorOkButton')).tap();
if (process.env.TRAVIS) await sleep(5000);
try {
await element(by.id('CreateTransactionButton')).tap();
} catch (_) {}
// created. verifying:
await yo('TransactionValue');
await yo('PayjoinSwitch');
await element(by.id('TransactionDetailsButton')).tap();
txhex = await extractTextFromElementById('TxhexInput');
transaction = bitcoin.Transaction.fromHex(txhex);
assert.strictEqual(bitcoin.address.fromOutputScript(transaction.outs[0].script), 'bc1qnapskphjnwzw2w3dk4anpxntunc77v6qrua0f7');
assert.notEqual(transaction.outs[0].value, 110000000); // check that it is 1.1 USD, not 1 BTC
assert.ok(transaction.outs[0].value < 10000); // 1.1 USD ~ 0,00001964 sats in march 2021
// now, testing units switching, and then creating tx with SATS:
await device.pressBack();
await device.pressBack();
await element(by.id('changeAmountUnitButton')).tap(); // switched to BTC
await element(by.id('BitcoinAmountInput')).replaceText('0.00015');
await element(by.id('changeAmountUnitButton')).tap(); // switched to sats
assert.strictEqual(await extractTextFromElementById('BitcoinAmountInput'), '15000');
await element(by.id('changeAmountUnitButton')).tap(); // switched to FIAT
@ -698,7 +732,7 @@ describe('BlueWallet UI Tests', () => {
await element(by.id('advancedOptionsMenuButton')).tap();
await element(by.id('PsbtSign')).tap();
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
await sleep(1000);
@ -824,7 +858,7 @@ describe('BlueWallet UI Tests', () => {
const signedPsbt =
'ur:bytes/tyqjuurnvf607qgq2gpqqqqqq8tn32hc9nqtgta558mezl70l6jyqa9q3ppqfsh3zg6rdpqsj3qrqqqqqqqqpllllllsryxzqqqqqqqqqqtqq9xcmv2lt34gsdnr78msss5jpcdg2hvetmgqqqqqqqqpqy04pscqqqqqqqqqzcqpfdq6gfm4aaal9r8vsg3zps42fgf4e3znxgszqfmxyrpwfsdmnlfdfwrcj7clx30kcecty3gte7ekvjeekkx2q9vvgjpsg5pzzqxjc9xv3rlhu2n6u87pm94agwcmvcywwsx9k0jpvwyng8crytgrkcpzqae6amp5xy03x2lsklv5zgnmeht0grzns27tmsjtsg2j0ne2969kqyqsxpqpqqqqqgsxqfmxyrpwfsdmnlfdfwrcj7clx30kcecty3gte7ekvjeekkx2q9vvgxqk3htqx4qqqzqqqqqqsqqqqqyqqqqqqqqyqqqqqqqqear8ke';
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
await sleep(1000);
@ -838,7 +872,7 @@ describe('BlueWallet UI Tests', () => {
await element(by.id('PsbtWithHardwareScrollView')).swipe('up', 'fast', 1); // in case emu screen is small and it doesnt fit
await element(by.id('PsbtTxScanButton')).tap(); // opening camera
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
await sleep(1000);
@ -911,7 +945,7 @@ describe('BlueWallet UI Tests', () => {
await waitFor(element(by.id('UrProgressBar'))).toBeNotVisible();
for (const ur of urs) {
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
}
@ -961,7 +995,7 @@ describe('BlueWallet UI Tests', () => {
];
for (const ur of ursSignedByColdcard) {
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
}
@ -982,7 +1016,7 @@ describe('BlueWallet UI Tests', () => {
];
for (const ur of urSignedByColdcardAndCobo) {
// tapping 10 times invisible button is a backdoor:
// tapping 5 times invisible button is a backdoor:
for (let c = 0; c <= 5; c++) {
await element(by.id('ScanQrBackdoorButton')).tap();
}