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
// therefore we need to find target account and update data for it as well
const accountsToUpdate = [account];
const targetAddress =
notification.type === 'send'
? notification.outputs[0].addresses[0]
: 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: { account: {
descriptor: account.descriptor, descriptor: a.descriptor,
from: account.block, from: a.block,
history: false, history: false,
}, },
coin: account.network, 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.payload.availableBalance, updatedAccount.availableBalance,
network.decimals network.decimals
), ),
block: updatedAccount.payload.block, block: updatedAccount.block,
sequence: updatedAccount.payload.sequence, sequence: updatedAccount.sequence,
reserve: '0', reserve: '0',
empty, empty,
}) })
); );
}
});
}; };

Loading…
Cancel
Save