fix XRP balance update if tx is sent between 2 Trezor accounts

pull/615/head
Szymon Lesisz 5 years ago
parent aecfbb76df
commit b5f2692d38

@ -161,31 +161,46 @@ export const onNotification = (
}); });
} }
const updatedAccount = await TrezorConnect.rippleGetAccountInfo({ // In case of tx sent between two Trezor accounts there is a possibility that only 1 notification will be received
account: { // therefore we need to find target account and update data for it as well
descriptor: account.descriptor, const accountsToUpdate = [account];
from: account.block, const targetAddress =
history: false, notification.type === 'send'
}, ? notification.outputs[0].addresses[0]
coin: account.network, : notification.inputs[0].addresses[0];
});
const targetAccount = getState().accounts.find(a => a.descriptor === targetAddress);
if (targetAccount) {
accountsToUpdate.push(targetAccount);
}
accountsToUpdate.forEach(async a => {
const response = await TrezorConnect.rippleGetAccountInfo({
account: {
descriptor: a.descriptor,
from: a.block,
history: false,
},
coin: a.network,
});
if (!updatedAccount.success) return; if (response.success) {
const updatedAccount = response.payload;
const empty = updatedAccount.payload.sequence <= 0 && updatedAccount.payload.balance === '0'; const empty = updatedAccount.sequence <= 0 && updatedAccount.balance === '0';
dispatch( dispatch(
AccountsActions.update({ AccountsActions.update({
networkType: 'ripple', ...a,
...account, balance: toDecimalAmount(updatedAccount.balance, network.decimals),
balance: toDecimalAmount(updatedAccount.payload.balance, network.decimals), availableBalance: toDecimalAmount(
availableBalance: toDecimalAmount( updatedAccount.availableBalance,
updatedAccount.payload.availableBalance, network.decimals
network.decimals ),
), block: updatedAccount.block,
block: updatedAccount.payload.block, sequence: updatedAccount.sequence,
sequence: updatedAccount.payload.sequence, reserve: '0',
reserve: '0', empty,
empty, })
}) );
); }
});
}; };

Loading…
Cancel
Save