mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
cleaning up flowtype (DiscoveryResult + EthTxRequest)
This commit is contained in:
parent
892f4fe7c0
commit
4c9f5468b3
@ -27,8 +27,6 @@ import type {
|
|||||||
AsyncAction,
|
AsyncAction,
|
||||||
PromiseAction,
|
PromiseAction,
|
||||||
ThunkAction,
|
ThunkAction,
|
||||||
AccountDiscovery,
|
|
||||||
EthereumTxRequest
|
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
@ -38,7 +36,14 @@ export type BlockchainAction = {
|
|||||||
type: typeof BLOCKCHAIN.READY,
|
type: typeof BLOCKCHAIN.READY,
|
||||||
}
|
}
|
||||||
|
|
||||||
export const discoverAccount = (device: TrezorDevice, xpub: string, network: string): PromiseAction<AccountDiscovery> => async (dispatch: Dispatch, getState: GetState): Promise<AccountDiscovery> => {
|
export type DiscoveryResult = {
|
||||||
|
transactions: number;
|
||||||
|
block: number;
|
||||||
|
balance: string;
|
||||||
|
nonce: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const discoverAccount = (device: TrezorDevice, xpub: string, network: string): PromiseAction<DiscoveryResult> => async (dispatch: Dispatch, getState: GetState): Promise<DiscoveryResult> => {
|
||||||
// get data from connect
|
// get data from connect
|
||||||
// Temporary disabled, enable after trezor-connect@5.0.32 release
|
// Temporary disabled, enable after trezor-connect@5.0.32 release
|
||||||
const txs = await TrezorConnect.ethereumGetAccountInfo({
|
const txs = await TrezorConnect.ethereumGetAccountInfo({
|
||||||
|
@ -10,12 +10,28 @@ import type {
|
|||||||
Dispatch,
|
Dispatch,
|
||||||
GetState,
|
GetState,
|
||||||
PromiseAction,
|
PromiseAction,
|
||||||
EthereumTxRequest,
|
|
||||||
EthereumPreparedTx
|
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
|
import type {
|
||||||
|
EthereumTransaction
|
||||||
|
} from 'trezor-connect';
|
||||||
|
|
||||||
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumPreparedTx> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumPreparedTx> => {
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
|
|
||||||
|
type EthereumTxRequest = {
|
||||||
|
network: string;
|
||||||
|
token: ?Token;
|
||||||
|
from: string;
|
||||||
|
to: string;
|
||||||
|
amount: string;
|
||||||
|
data: string;
|
||||||
|
gasLimit: string;
|
||||||
|
gasPrice: string;
|
||||||
|
nonce: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<EthereumTransaction> => async (dispatch: Dispatch, getState: GetState): Promise<EthereumTransaction> => {
|
||||||
const instance = await dispatch( initWeb3(tx.network) );
|
const instance = await dispatch( initWeb3(tx.network) );
|
||||||
const token = tx.token;
|
const token = tx.token;
|
||||||
let data: string = `0x${tx.data}`; // TODO: check if already prefixed
|
let data: string = `0x${tx.data}`; // TODO: check if already prefixed
|
||||||
@ -46,10 +62,8 @@ export const prepareEthereumTx = (tx: EthereumTxRequest): PromiseAction<Ethereum
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export const serializeEthereumTx = (tx: EthereumPreparedTx): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
|
export const serializeEthereumTx = (tx: EthereumTransaction): PromiseAction<string> => async (dispatch: Dispatch, getState: GetState): Promise<string> => {
|
||||||
const ethTx = new EthereumjsTx(tx);
|
const ethTx = new EthereumjsTx(tx);
|
||||||
console.warn("SERIALIZE 1", `0x${ ethTx.serialize().toString('hex') }`)
|
|
||||||
console.warn("SERIALIZE 2", toHex( ethTx.serialize() ))
|
|
||||||
return `0x${ ethTx.serialize().toString('hex') }`;
|
return `0x${ ethTx.serialize().toString('hex') }`;
|
||||||
// return toHex( ethTx.serialize() );
|
// return toHex( ethTx.serialize() );
|
||||||
}
|
}
|
@ -19,9 +19,6 @@ import type {
|
|||||||
ThunkAction,
|
ThunkAction,
|
||||||
AsyncAction,
|
AsyncAction,
|
||||||
PromiseAction,
|
PromiseAction,
|
||||||
AccountDiscovery,
|
|
||||||
EthereumTxRequest,
|
|
||||||
EthereumPreparedTx
|
|
||||||
} from 'flowtype';
|
} from 'flowtype';
|
||||||
|
|
||||||
import type { EthereumAccount } from 'trezor-connect';
|
import type { EthereumAccount } from 'trezor-connect';
|
||||||
@ -30,6 +27,7 @@ import type { PendingTx } from 'reducers/PendingTxReducer';
|
|||||||
import type { Web3Instance } from 'reducers/Web3Reducer';
|
import type { Web3Instance } from 'reducers/Web3Reducer';
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
import type { Token } from 'reducers/TokensReducer';
|
||||||
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
import type { NetworkToken } from 'reducers/LocalStorageReducer';
|
||||||
|
import type { DiscoveryResult } from './BlockchainActions';
|
||||||
import * as TokenActions from './TokenActions';
|
import * as TokenActions from './TokenActions';
|
||||||
import * as AccountsActions from './AccountsActions';
|
import * as AccountsActions from './AccountsActions';
|
||||||
|
|
||||||
@ -137,7 +135,7 @@ export const initWeb3 = (network: string, urlIndex: number = 0): PromiseAction<W
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export const discoverAccount = (address: string, network: string): PromiseAction<AccountDiscovery> => async (dispatch: Dispatch, getState: GetState): Promise<AccountDiscovery> => {
|
export const discoverAccount = (address: string, network: string): PromiseAction<DiscoveryResult> => async (dispatch: Dispatch, getState: GetState): Promise<DiscoveryResult> => {
|
||||||
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
const instance: Web3Instance = await dispatch( initWeb3(network) );
|
||||||
const balance = await instance.web3.eth.getBalance(address);
|
const balance = await instance.web3.eth.getBalance(address);
|
||||||
const nonce = await instance.web3.eth.getTransactionCount(address);
|
const nonce = await instance.web3.eth.getTransactionCount(address);
|
||||||
|
@ -169,41 +169,3 @@ export type PromiseAction<R> = ReduxPromiseAction<State, Action, R>;
|
|||||||
|
|
||||||
export type Store = ReduxStore<State, Action>;
|
export type Store = ReduxStore<State, Action>;
|
||||||
export type GetState = () => State;
|
export type GetState = () => State;
|
||||||
|
|
||||||
|
|
||||||
// temporary types
|
|
||||||
export type AccountDiscovery = {
|
|
||||||
transactions: number;
|
|
||||||
block: number;
|
|
||||||
balance: string;
|
|
||||||
nonce: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
import type { Token } from 'reducers/TokensReducer';
|
|
||||||
|
|
||||||
export type EthereumTxRequest = {
|
|
||||||
network: string;
|
|
||||||
token: ?Token;
|
|
||||||
from: string;
|
|
||||||
to: string;
|
|
||||||
amount: string;
|
|
||||||
data: string;
|
|
||||||
gasLimit: string;
|
|
||||||
gasPrice: string;
|
|
||||||
nonce: number;
|
|
||||||
}
|
|
||||||
// copypaste from trezor-connect
|
|
||||||
export type EthereumPreparedTx = {
|
|
||||||
to: string,
|
|
||||||
value: string,
|
|
||||||
gasPrice: string,
|
|
||||||
gasLimit: string,
|
|
||||||
nonce: string,
|
|
||||||
data?: string,
|
|
||||||
chainId?: number,
|
|
||||||
txType?: number,
|
|
||||||
v: string,
|
|
||||||
r: string,
|
|
||||||
s: string,
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user