You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
trezor-wallet/src/actions/ReceiveActions.js

107 lines
2.7 KiB

6 years ago
/* @flow */
6 years ago
import TrezorConnect from 'trezor-connect';
import * as RECEIVE from 'actions/constants/receive';
import * as NOTIFICATION from 'actions/constants/notification';
6 years ago
import { initialState } from 'reducers/ReceiveReducer';
import type { State } from 'reducers/ReceiveReducer';
6 years ago
import type {
TrezorDevice, ThunkAction, AsyncAction, Action, GetState, Dispatch,
} from 'flowtype';
6 years ago
export type ReceiveAction = {
type: typeof RECEIVE.INIT,
state: State
} | {
type: typeof RECEIVE.DISPOSE,
} | {
type: typeof RECEIVE.REQUEST_UNVERIFIED,
device: TrezorDevice
} | {
type: typeof RECEIVE.SHOW_ADDRESS
} | {
type: typeof RECEIVE.HIDE_ADDRESS
} | {
type: typeof RECEIVE.SHOW_UNVERIFIED_ADDRESS
}
export const init = (): ThunkAction => (dispatch: Dispatch, getState: GetState): void => {
const state: State = {
...initialState,
};
6 years ago
dispatch({
type: RECEIVE.INIT,
state,
});
};
6 years ago
export const dispose = (): Action => ({
type: RECEIVE.DISPOSE,
});
6 years ago
export const showUnverifiedAddress = (): Action => ({
type: RECEIVE.SHOW_UNVERIFIED_ADDRESS,
});
6 years ago
6 years ago
//export const showAddress = (address_n: string): AsyncAction => {
export const showAddress = (address_n: Array<number>): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const selected = getState().wallet.selectedDevice;
if (!selected) return;
if (selected && (!selected.connected || !selected.available)) {
dispatch({
type: RECEIVE.REQUEST_UNVERIFIED,
device: selected,
});
return;
}
6 years ago
const response = await TrezorConnect.ethereumGetAddress({
device: {
path: selected.path,
instance: selected.instance,
state: selected.state,
},
path: address_n,
useEmptyPassphrase: !selected.instance,
});
6 years ago
if (response && response.success) {
dispatch({
type: RECEIVE.SHOW_ADDRESS,
});
} else {
dispatch({
type: RECEIVE.HIDE_ADDRESS,
});
6 years ago
dispatch({
type: NOTIFICATION.ADD,
payload: {
type: 'error',
title: 'Verifying address error',
message: response.payload.error,
cancelable: true,
actions: [
{
label: 'Try again',
callback: () => {
dispatch(showAddress(address_n));
},
},
],
6 years ago
},
});
}
};
export default {
init,
dispose,
showAddress,
showUnverifiedAddress,
};