mirror of
https://github.com/trezor/trezor-wallet
synced 2025-01-03 21:00:55 +00:00
fix PendingTransactions format
This commit is contained in:
parent
0b25f884aa
commit
baec449936
@ -63,7 +63,7 @@ const findTokens = (accounts: Array<Account>, tokens: Array<Token>): Array<Token
|
|||||||
|
|
||||||
const findDiscovery = (devices: Array<TrezorDevice>, discovery: Array<Discovery>): Array<Discovery> => devices.reduce((arr, dev) => arr.concat(discovery.filter(d => d.deviceState === dev.state && d.completed)), []);
|
const findDiscovery = (devices: Array<TrezorDevice>, discovery: Array<Discovery>): Array<Discovery> => devices.reduce((arr, dev) => arr.concat(discovery.filter(d => d.deviceState === dev.state && d.completed)), []);
|
||||||
|
|
||||||
const findPendingTxs = (accounts: Array<Account>, pending: Array<Transaction>): Array<Transaction> => accounts.reduce((result, account) => result.concat(pending.filter(p => p.address === account.descriptor && p.network === account.network)), []);
|
const findPendingTxs = (accounts: Array<Account>, pending: Array<Transaction>): Array<Transaction> => accounts.reduce((result, account) => result.concat(pending.filter(p => p.descriptor === account.descriptor && p.network === account.network)), []);
|
||||||
|
|
||||||
export const save = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
export const save = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
const devices: Array<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
|
const devices: Array<TrezorDevice> = getState().devices.filter(d => d.features && d.remember === true);
|
||||||
|
@ -131,10 +131,10 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (dis
|
|||||||
|
|
||||||
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
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.descriptor);
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
|
|
||||||
if (notification.status === 'pending') {
|
if (!notification.blockHeight) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PENDING.ADD,
|
type: PENDING.ADD,
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -530,9 +530,7 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
|
|||||||
const fee = ValidationActions.calculateFee(currentState.gasLimit, currentState.gasPrice);
|
const fee = ValidationActions.calculateFee(currentState.gasLimit, currentState.gasPrice);
|
||||||
const blockchainNotification = {
|
const blockchainNotification = {
|
||||||
type: 'send',
|
type: 'send',
|
||||||
status: 'pending',
|
descriptor: account.descriptor,
|
||||||
confirmations: 0,
|
|
||||||
address: account.descriptor,
|
|
||||||
inputs: [
|
inputs: [
|
||||||
{
|
{
|
||||||
addresses: [account.descriptor],
|
addresses: [account.descriptor],
|
||||||
@ -553,7 +551,14 @@ export const onSend = (): AsyncAction => async (dispatch: Dispatch, getState: Ge
|
|||||||
total: currentState.total,
|
total: currentState.total,
|
||||||
|
|
||||||
sequence: nonce,
|
sequence: nonce,
|
||||||
currency: isToken ? currentState.currency : undefined,
|
tokens: isToken ? [{
|
||||||
|
name: currentState.currency,
|
||||||
|
shortcut: currentState.currency,
|
||||||
|
value: currentState.amount,
|
||||||
|
}] : undefined,
|
||||||
|
|
||||||
|
blockHeight: 0,
|
||||||
|
blockHash: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
dispatch(BlockchainActions.onNotification({
|
dispatch(BlockchainActions.onNotification({
|
||||||
|
@ -89,12 +89,12 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (dis
|
|||||||
|
|
||||||
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
export const onNotification = (payload: $ElementType<BlockchainNotification, 'payload'>): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
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.descriptor);
|
||||||
if (!account) return;
|
if (!account) return;
|
||||||
const { network } = getState().selectedAccount;
|
const { network } = getState().selectedAccount;
|
||||||
if (!network) return; // flowtype fallback
|
if (!network) return; // flowtype fallback
|
||||||
|
|
||||||
if (notification.status === 'pending') {
|
if (!notification.blockHeight) {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PENDING.ADD,
|
type: PENDING.ADD,
|
||||||
payload: {
|
payload: {
|
||||||
@ -109,7 +109,7 @@ export const onNotification = (payload: $ElementType<BlockchainNotification, 'pa
|
|||||||
});
|
});
|
||||||
|
|
||||||
// todo: replace "send success" notification with link to explorer
|
// todo: replace "send success" notification with link to explorer
|
||||||
} else if (notification.status === 'confirmed') {
|
} else {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: PENDING.TX_RESOLVED,
|
type: PENDING.TX_RESOLVED,
|
||||||
hash: notification.hash,
|
hash: notification.hash,
|
||||||
|
@ -70,26 +70,24 @@ const TransactionItem = ({
|
|||||||
network,
|
network,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const url = `${network.explorer.tx}${tx.hash}`;
|
const url = `${network.explorer.tx}${tx.hash}`;
|
||||||
const date = typeof tx.timestamp === 'string' && tx.confirmations > 0 ? tx.timestamp : undefined; // TODO: format date
|
const date = typeof tx.timestamp === 'string' ? tx.timestamp : undefined; // TODO: format date
|
||||||
const addresses = (tx.type === 'send' ? tx.outputs : tx.inputs).reduce((arr, item) => arr.concat(item.addresses), []);
|
const addresses = (tx.type === 'send' ? tx.outputs : tx.inputs).reduce((arr, item) => arr.concat(item.addresses), []);
|
||||||
|
|
||||||
const currency = tx.currency || tx.network;
|
|
||||||
const isToken = currency !== tx.network;
|
|
||||||
const amount = isToken ? `${tx.amount} ${currency}` : `${tx.total} ${network.symbol}`;
|
|
||||||
const fee = isToken && tx.type === 'send' ? `${tx.fee} ${network.symbol}` : undefined;
|
|
||||||
const operation = tx.type === 'send' ? '-' : '+';
|
const operation = tx.type === 'send' ? '-' : '+';
|
||||||
|
const amount = tx.tokens ? tx.tokens.map(t => (<Amount key={t.value}>{operation}{t.value} {t.shortcut}</Amount>)) : <Amount>{operation}{tx.total} {network.symbol}</Amount>;
|
||||||
|
const fee = tx.tokens && tx.type === 'send' ? `${tx.fee} ${network.symbol}` : undefined;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
{ date && (<Date href={url} isGray>{ date }</Date>)}
|
{ date && (<Date href={url} isGray>{ date }</Date>)}
|
||||||
<Addresses>
|
<Addresses>
|
||||||
{ addresses.map(addr => (<Address key={addr}>{addr}</Address>)) }
|
{ addresses.map(addr => (<Address key={addr}>{addr}</Address>)) }
|
||||||
{ tx.confirmations <= 0 && (
|
{ !tx.blockHeight && (
|
||||||
<Date href={url} isGray>Transaction hash: {tx.hash}</Date>
|
<Date href={url} isGray>Transaction hash: {tx.hash}</Date>
|
||||||
)}
|
)}
|
||||||
</Addresses>
|
</Addresses>
|
||||||
<Value className={tx.type}>
|
<Value className={tx.type}>
|
||||||
<Amount>{operation}{amount}</Amount>
|
{amount}
|
||||||
{ fee && (<Fee>{operation}{fee}</Fee>) }
|
{ fee && (<Fee>{operation}{fee}</Fee>) }
|
||||||
</Value>
|
</Value>
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
|
@ -86,18 +86,27 @@ export const getDiscoveryProcess = (state: State): ?Discovery => {
|
|||||||
export const getAccountPendingTx = (pending: Array<Transaction>, account: ?Account): Array<Transaction> => {
|
export const getAccountPendingTx = (pending: Array<Transaction>, account: ?Account): Array<Transaction> => {
|
||||||
const a = account;
|
const a = account;
|
||||||
if (!a) return [];
|
if (!a) return [];
|
||||||
return pending.filter(p => p.network === a.network && p.address === a.descriptor);
|
return pending.filter(p => p.network === a.network && p.descriptor === a.descriptor);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getPendingSequence = (pending: Array<Transaction>): number => pending.reduce((value: number, tx: Transaction) => {
|
export const getPendingSequence = (pending: Array<Transaction>): number => pending.reduce((value: number, tx: Transaction): number => {
|
||||||
if (tx.rejected) return value;
|
if (tx.rejected) return value;
|
||||||
return Math.max(value, tx.sequence + 1);
|
return Math.max(value, tx.sequence + 1);
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
export const getPendingAmount = (pending: Array<Transaction>, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: Transaction) => {
|
export const getPendingAmount = (pending: Array<Transaction>, currency: string, token: boolean = false): BigNumber => pending.reduce((value: BigNumber, tx: Transaction): BigNumber => {
|
||||||
if (tx.currency === currency && !tx.rejected) {
|
if (!token) {
|
||||||
return new BigNumber(value).plus(token ? tx.amount : tx.total);
|
// regular transactions
|
||||||
|
// add fees from token txs and amount from regular txs
|
||||||
|
return new BigNumber(value).plus(tx.tokens ? tx.fee : tx.total);
|
||||||
}
|
}
|
||||||
|
if (tx.tokens) {
|
||||||
|
// token transactions
|
||||||
|
const allTokens = tx.tokens.filter(t => t.shortcut === currency);
|
||||||
|
const tokensValue: BigNumber = allTokens.reduce((tv, t) => new BigNumber(value).plus(t.value), new BigNumber('0'));
|
||||||
|
return new BigNumber(value).plus(tokensValue);
|
||||||
|
}
|
||||||
|
// default
|
||||||
return value;
|
return value;
|
||||||
}, new BigNumber('0'));
|
}, new BigNumber('0'));
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
/* @flow */
|
/* @flow */
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import BigNumber from 'bignumber.js';
|
||||||
import styled, { css } from 'styled-components';
|
import styled, { css } from 'styled-components';
|
||||||
import { Select } from 'components/Select';
|
import { Select } from 'components/Select';
|
||||||
import Button from 'components/Button';
|
import Button from 'components/Button';
|
||||||
@ -13,6 +14,7 @@ import colors from 'config/colors';
|
|||||||
import Title from 'views/Wallet/components/Title';
|
import Title from 'views/Wallet/components/Title';
|
||||||
import P from 'components/Paragraph';
|
import P from 'components/Paragraph';
|
||||||
import Content from 'views/Wallet/components/Content';
|
import Content from 'views/Wallet/components/Content';
|
||||||
|
import * as stateUtils from 'reducers/utils';
|
||||||
import type { Token } from 'flowtype';
|
import type { Token } from 'flowtype';
|
||||||
import AdvancedForm from './components/AdvancedForm';
|
import AdvancedForm from './components/AdvancedForm';
|
||||||
import PendingTransactions from '../components/PendingTransactions';
|
import PendingTransactions from '../components/PendingTransactions';
|
||||||
@ -221,10 +223,11 @@ const AccountSend = (props: Props) => {
|
|||||||
|
|
||||||
const isCurrentCurrencyToken = networkSymbol !== currency;
|
const isCurrentCurrencyToken = networkSymbol !== currency;
|
||||||
|
|
||||||
let selectedTokenBalance = 0;
|
let selectedTokenBalance = '0';
|
||||||
const selectedToken = tokens.find(t => t.symbol === currency);
|
const selectedToken = tokens.find(t => t.symbol === currency);
|
||||||
if (selectedToken) {
|
if (selectedToken) {
|
||||||
selectedTokenBalance = selectedToken.balance;
|
const pendingAmount: BigNumber = stateUtils.getPendingAmount(props.selectedAccount.pending, selectedToken.symbol, true);
|
||||||
|
selectedTokenBalance = new BigNumber(selectedToken.balance).minus(pendingAmount).toString(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
let isSendButtonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending;
|
let isSendButtonDisabled: boolean = Object.keys(errors).length > 0 || total === '0' || amount.length === 0 || address.length === 0 || sending;
|
||||||
|
Loading…
Reference in New Issue
Block a user