mirror of
https://github.com/trezor/trezor-wallet
synced 2024-11-24 09:18:09 +00:00
TrezorConnect BLOCKCHAIN events returns CoinInfo object
This commit is contained in:
parent
7790babb3a
commit
892f4fe7c0
@ -86,7 +86,9 @@ export const estimateGasLimit = (network: string, data: string, value: string, g
|
|||||||
return await dispatch( Web3Actions.estimateGasLimit(network, { to: '', data, value, gasPrice }) );
|
return await dispatch( Web3Actions.estimateGasLimit(network, { to: '', data, value, gasPrice }) );
|
||||||
}
|
}
|
||||||
|
|
||||||
export const onBlockMined = (network: string): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
export const onBlockMined = (coinInfo: any): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
|
// incoming "coinInfo" from TrezorConnect is CoinInfo | EthereumNetwork type
|
||||||
|
const network: string = coinInfo.shortcut.toLowerCase();
|
||||||
|
|
||||||
// try to resolve pending transactions
|
// try to resolve pending transactions
|
||||||
await dispatch( Web3Actions.resolvePendingTransactions(network) );
|
await dispatch( Web3Actions.resolvePendingTransactions(network) );
|
||||||
@ -119,12 +121,15 @@ export const onBlockMined = (network: string): PromiseAction<void> => async (dis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// not used for now, waiting for fix in blockbook
|
||||||
export const onNotification = (payload: any): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
export const onNotification = (payload: any): PromiseAction<void> => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
|
||||||
|
|
||||||
// this event can be triggered multiple times
|
// this event can be triggered multiple times
|
||||||
// 1. check if pair [txid + address] is already in reducer
|
// 1. check if pair [txid + address] is already in reducer
|
||||||
|
const network: string = payload.coin.shortcut.toLowerCase();
|
||||||
const address: string = EthereumjsUtil.toChecksumAddress(payload.tx.address);
|
const address: string = EthereumjsUtil.toChecksumAddress(payload.tx.address);
|
||||||
const txInfo = await dispatch( Web3Actions.getPendingInfo(payload.coin, payload.tx.txid) );
|
const txInfo = await dispatch( Web3Actions.getPendingInfo(network, payload.tx.txid) );
|
||||||
|
|
||||||
// const exists = getState().pending.filter(p => p.id === payload.tx.txid && p.address === address);
|
// const exists = getState().pending.filter(p => p.id === payload.tx.txid && p.address === address);
|
||||||
const exists = getState().pending.filter(p => {
|
const exists = getState().pending.filter(p => {
|
||||||
@ -137,7 +142,7 @@ export const onNotification = (payload: any): PromiseAction<void> => async (disp
|
|||||||
payload: {
|
payload: {
|
||||||
type: 'send',
|
type: 'send',
|
||||||
id: payload.tx.txid,
|
id: payload.tx.txid,
|
||||||
network: payload.coin,
|
network,
|
||||||
currency: "tETH",
|
currency: "tETH",
|
||||||
amount: txInfo.value,
|
amount: txInfo.value,
|
||||||
total: "0",
|
total: "0",
|
||||||
@ -152,7 +157,7 @@ export const onNotification = (payload: any): PromiseAction<void> => async (disp
|
|||||||
// dispatch({
|
// dispatch({
|
||||||
// type: PENDING.ADD_UNKNOWN,
|
// type: PENDING.ADD_UNKNOWN,
|
||||||
// payload: {
|
// payload: {
|
||||||
// network: payload.coin,
|
// network,
|
||||||
// ...payload.tx,
|
// ...payload.tx,
|
||||||
// }
|
// }
|
||||||
// });
|
// });
|
||||||
|
@ -299,7 +299,9 @@ export const estimateGasLimit = (network: string, options: EstimateGasOptions):
|
|||||||
return limit;
|
return limit;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const disconnect = (network: string): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
export const disconnect = (coinInfo: any): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
|
||||||
|
// incoming "coinInfo" from TrezorConnect is CoinInfo | EthereumNetwork type
|
||||||
|
const network: string = coinInfo.shortcut.toLowerCase();
|
||||||
// check if Web3 was already initialized
|
// check if Web3 was already initialized
|
||||||
const instance = getState().web3.find(w3 => w3.network === network);
|
const instance = getState().web3.find(w3 => w3.network === network);
|
||||||
if (instance) {
|
if (instance) {
|
||||||
|
@ -18,12 +18,13 @@ const find = (state: State, name: string): number => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const connect = (state: State, action: any): State => {
|
const connect = (state: State, action: any): State => {
|
||||||
|
const name = action.payload.coin.shortcut.toLowerCase();
|
||||||
const network: BlockchainNetwork = {
|
const network: BlockchainNetwork = {
|
||||||
name: action.payload.coin,
|
name,
|
||||||
connected: true,
|
connected: true,
|
||||||
}
|
}
|
||||||
const newState: State = [...state];
|
const newState: State = [...state];
|
||||||
const index: number = find(newState, action.payload.coin);
|
const index: number = find(newState, name);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
newState[index] = network;
|
newState[index] = network;
|
||||||
} else {
|
} else {
|
||||||
@ -33,12 +34,13 @@ const connect = (state: State, action: any): State => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const disconnect = (state: State, action: any): State => {
|
const disconnect = (state: State, action: any): State => {
|
||||||
|
const name = action.payload.coin.shortcut.toLowerCase();
|
||||||
const network: BlockchainNetwork = {
|
const network: BlockchainNetwork = {
|
||||||
name: action.payload.coin,
|
name,
|
||||||
connected: false,
|
connected: false,
|
||||||
}
|
}
|
||||||
const newState: State = [...state];
|
const newState: State = [...state];
|
||||||
const index: number = find(newState, action.payload.coin);
|
const index: number = find(newState, name);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
newState[index] = network;
|
newState[index] = network;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user