mirror of
https://github.com/trezor/trezor-wallet
synced 2025-03-28 14:05:44 +00:00
Merge pull request #561 from trezor/fix/update-remembered-device-accounts
Fix/updating xrp accounts on remembered device
This commit is contained in:
commit
8072c662b2
@ -84,6 +84,7 @@ export const onBlockMined = (
|
|||||||
payload: $ElementType<BlockchainBlock, 'payload'>
|
payload: $ElementType<BlockchainBlock, 'payload'>
|
||||||
): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
const shortcut = payload.coin.shortcut.toLowerCase();
|
const shortcut = payload.coin.shortcut.toLowerCase();
|
||||||
|
const { block } = payload;
|
||||||
if (getState().router.location.state.network !== shortcut) return;
|
if (getState().router.location.state.network !== shortcut) return;
|
||||||
|
|
||||||
const { config } = getState().localStorage;
|
const { config } = getState().localStorage;
|
||||||
@ -95,7 +96,7 @@ export const onBlockMined = (
|
|||||||
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
|
await dispatch(EthereumBlockchainActions.onBlockMined(shortcut));
|
||||||
break;
|
break;
|
||||||
case 'ripple':
|
case 'ripple':
|
||||||
await dispatch(RippleBlockchainActions.onBlockMined(shortcut));
|
await dispatch(RippleBlockchainActions.onBlockMined(shortcut, block));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -141,6 +141,9 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (
|
|||||||
dispatch(Web3Actions.updateAccount(accounts[i], a, network));
|
dispatch(Web3Actions.updateAccount(accounts[i], a, network));
|
||||||
} else {
|
} else {
|
||||||
// there are no new txs, just update block
|
// there are no new txs, just update block
|
||||||
|
// TODO: There still could be internal transactions as a result of contract
|
||||||
|
// If that's the case, account balance won't be updated
|
||||||
|
// Currently waiting for deprecating web3 and utilising new blockbook
|
||||||
dispatch(AccountsActions.update({ ...accounts[i], block: a.block }));
|
dispatch(AccountsActions.update({ ...accounts[i], block: a.block }));
|
||||||
|
|
||||||
// HACK: since blockbook can't work with smart contracts for now
|
// HACK: since blockbook can't work with smart contracts for now
|
||||||
|
@ -47,24 +47,24 @@ export const getFeeLevels = (network: Network): PayloadAction<Array<BlockchainFe
|
|||||||
return blockchain.feeLevels;
|
return blockchain.feeLevels;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onBlockMined = (network: string): PromiseAction<void> => async (
|
export const onBlockMined = (networkShortcut: string, block: number): PromiseAction<void> => async (
|
||||||
dispatch: Dispatch,
|
dispatch: Dispatch,
|
||||||
getState: GetState
|
getState: GetState
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const blockchain = getState().blockchain.find(b => b.shortcut === network);
|
const blockchain = getState().blockchain.find(b => b.shortcut === networkShortcut);
|
||||||
if (!blockchain) return; // flowtype fallback
|
if (!blockchain) return; // flowtype fallback
|
||||||
|
|
||||||
// if last update was more than 5 minutes ago
|
// if last update was more than 5 minutes ago
|
||||||
const now = new Date().getTime();
|
const now = new Date().getTime();
|
||||||
if (blockchain.feeTimestamp < now - 300000) {
|
if (blockchain.feeTimestamp < now - 300000) {
|
||||||
const feeRequest = await TrezorConnect.blockchainEstimateFee({
|
const feeRequest = await TrezorConnect.blockchainEstimateFee({
|
||||||
coin: network,
|
coin: networkShortcut,
|
||||||
});
|
});
|
||||||
if (feeRequest.success && observeChanges(blockchain.feeLevels, feeRequest.payload)) {
|
if (feeRequest.success && observeChanges(blockchain.feeLevels, feeRequest.payload)) {
|
||||||
// check if downloaded fee levels are different
|
// check if downloaded fee levels are different
|
||||||
dispatch({
|
dispatch({
|
||||||
type: BLOCKCHAIN.UPDATE_FEE,
|
type: BLOCKCHAIN.UPDATE_FEE,
|
||||||
shortcut: network,
|
shortcut: networkShortcut,
|
||||||
feeLevels: feeRequest.payload,
|
feeLevels: feeRequest.payload,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -72,28 +72,59 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (
|
|||||||
|
|
||||||
// TODO: check for blockchain rollbacks here!
|
// TODO: check for blockchain rollbacks here!
|
||||||
|
|
||||||
const accounts: Array<any> = getState().accounts.filter(a => a.network === network);
|
const accounts: Array<any> = getState().accounts.filter(a => a.network === networkShortcut);
|
||||||
// console.warn('ACCOUNTS', accounts);
|
if (accounts.length === 0) return;
|
||||||
if (accounts.length > 0) {
|
const { networks } = getState().localStorage.config;
|
||||||
// const response = await TrezorConnect.rippleGetAccountInfo({
|
const network = networks.find(c => c.shortcut === networkShortcut);
|
||||||
// bundle: accounts,
|
if (!network) return;
|
||||||
// level: 'transactions',
|
|
||||||
// coin: network,
|
// HACK: Since Connect always returns account.transactions as 0
|
||||||
// });
|
// we don't have info about new transactions for the account since last update.
|
||||||
// if (!response.success) return;
|
// Untill there is a better solution compare accounts block.
|
||||||
// response.payload.forEach((a, i) => {
|
// If we missed some blocks (wallet was offline) we'll update the account
|
||||||
// if (a.transactions.length > 0) {
|
// If we are update to date with the last block that means wallet was online
|
||||||
// console.warn('APDEJTED!', a, i);
|
// and we would get Blockchain notification about new transaction if needed
|
||||||
// dispatch(AccountsActions.update({
|
accounts.forEach(async account => {
|
||||||
// ...accounts[i],
|
const missingBlocks = account.block !== block - 1;
|
||||||
// balance: toDecimalAmount(a.balance, DECIMALS),
|
if (!missingBlocks) {
|
||||||
// availableBalance: toDecimalAmount(a.availableBalance, DECIMALS),
|
// account was last updated on account.block, current block is +1, we didn't miss single block
|
||||||
// block: a.block,
|
// if there was new tx, blockchain notification would let us know
|
||||||
// sequence: a.sequence,
|
// so just update the block for the account
|
||||||
// }));
|
dispatch(
|
||||||
// }
|
AccountsActions.update({
|
||||||
// });
|
...account,
|
||||||
}
|
block,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// we missed some blocks (wallet was offline). get updated account info from connect
|
||||||
|
const response = await TrezorConnect.rippleGetAccountInfo({
|
||||||
|
account: {
|
||||||
|
descriptor: account.descriptor,
|
||||||
|
},
|
||||||
|
level: 'transactions',
|
||||||
|
coin: networkShortcut,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.success) return;
|
||||||
|
|
||||||
|
const updatedAccount = response.payload;
|
||||||
|
|
||||||
|
// new txs
|
||||||
|
dispatch(
|
||||||
|
AccountsActions.update({
|
||||||
|
...account,
|
||||||
|
balance: toDecimalAmount(updatedAccount.balance, network.decimals),
|
||||||
|
availableBalance: toDecimalAmount(
|
||||||
|
updatedAccount.availableBalance,
|
||||||
|
network.decimals
|
||||||
|
),
|
||||||
|
block: updatedAccount.block,
|
||||||
|
sequence: updatedAccount.sequence,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const onNotification = (
|
export const onNotification = (
|
||||||
|
Loading…
Reference in New Issue
Block a user