1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-02 21:28:12 +00:00

get decimals from config (RippleBlockchainActions)

This commit is contained in:
Szymon Lesisz 2019-01-02 11:38:44 +01:00
parent 1392b4b5a7
commit 32ee758af2

View File

@ -16,8 +16,6 @@ import type {
BlockchainFeeLevel, BlockchainFeeLevel,
} from 'flowtype'; } from 'flowtype';
const DECIMALS: number = 6;
export const subscribe = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => { export const subscribe = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const accounts: Array<string> = getState().accounts.filter(a => a.network === network).map(a => a.descriptor); const accounts: Array<string> = getState().accounts.filter(a => a.network === network).map(a => a.descriptor);
await TrezorConnect.blockchainSubscribe({ await TrezorConnect.blockchainSubscribe({
@ -92,6 +90,8 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
const { notification } = payload; const { notification } = payload;
const account = getState().accounts.find(a => a.descriptor === notification.address); const account = getState().accounts.find(a => a.descriptor === notification.address);
if (!account) return; if (!account) return;
const { network } = getState().selectedAccount;
if (!network) return; // flowtype fallback
if (notification.status === 'pending') { if (notification.status === 'pending') {
dispatch({ dispatch({
@ -101,9 +101,9 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
deviceState: account.deviceState, deviceState: account.deviceState,
network: account.network, network: account.network,
amount: toDecimalAmount(notification.amount, DECIMALS), amount: toDecimalAmount(notification.amount, network.decimals),
total: notification.type === 'send' ? toDecimalAmount(notification.total, DECIMALS) : toDecimalAmount(notification.amount, DECIMALS), total: notification.type === 'send' ? toDecimalAmount(notification.total, network.decimals) : toDecimalAmount(notification.amount, network.decimals),
fee: toDecimalAmount(notification.fee, DECIMALS), fee: toDecimalAmount(notification.fee, network.decimals),
}, },
}); });
@ -128,8 +128,8 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
dispatch(AccountsActions.update({ dispatch(AccountsActions.update({
networkType: 'ripple', networkType: 'ripple',
...account, ...account,
balance: toDecimalAmount(updatedAccount.payload.balance, DECIMALS), balance: toDecimalAmount(updatedAccount.payload.balance, network.decimals),
availableBalance: toDecimalAmount(updatedAccount.payload.availableBalance, DECIMALS), availableBalance: toDecimalAmount(updatedAccount.payload.availableBalance, network.decimals),
block: updatedAccount.payload.block, block: updatedAccount.payload.block,
sequence: updatedAccount.payload.sequence, sequence: updatedAccount.payload.sequence,
reserve: '0', reserve: '0',