1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-11-13 20:08:56 +00:00
trezor-wallet/src/js/actions/ReceiveActions.js

102 lines
2.6 KiB
JavaScript
Raw Normal View History

2018-02-20 09:30:36 +00:00
/* @flow */
'use strict';
import TrezorConnect from 'trezor-connect';
import * as RECEIVE from './constants/receive';
import * as NOTIFICATION from './constants/notification';
import { initialState } from '../reducers/ReceiveReducer';
import type { State } from '../reducers/ReceiveReducer';
import { findSelectedDevice } from '../reducers/TrezorConnectReducer';
export const init = (): any => {
return (dispatch, getState): void => {
2018-04-11 13:21:43 +00:00
2018-02-20 09:30:36 +00:00
const state: State = {
...initialState,
};
dispatch({
type: RECEIVE.INIT,
state: state
});
}
}
export const update = (newProps: any): any => {
return (dispatch, getState): void => {
const {
2018-04-11 13:21:43 +00:00
abstractAccount,
2018-02-20 09:30:36 +00:00
router
} = getState();
2018-04-11 13:21:43 +00:00
const isLocationChanged: boolean = router.location.pathname !== abstractAccount.location;
2018-02-20 09:30:36 +00:00
if (isLocationChanged) {
dispatch( init() );
}
}
}
export const dispose = (address: string): any => {
return {
type: RECEIVE.DISPOSE
}
}
export const showUnverifiedAddress = () => {
return {
type: RECEIVE.SHOW_UNVERIFIED_ADDRESS
}
}
export const showAddress = (address_n: string): any => {
return async (dispatch, getState) => {
const selected = findSelectedDevice(getState().connect);
2018-03-08 16:10:53 +00:00
if (!selected) return;
2018-02-20 09:30:36 +00:00
if (selected && (!selected.connected || !selected.available)) {
2018-02-20 09:30:36 +00:00
dispatch({
type: RECEIVE.REQUEST_UNVERIFIED,
device: selected
2018-02-20 09:30:36 +00:00
});
return;
}
const response = await TrezorConnect.ethereumGetAddress({
device: {
path: selected.path,
instance: selected.instance,
state: selected.state
2018-02-20 09:30:36 +00:00
},
path: address_n,
2018-02-20 09:30:36 +00:00
});
if (response && response.success) {
dispatch({
type: RECEIVE.SHOW_ADDRESS
})
} else {
// TODO: handle invalid pin?
dispatch({
type: NOTIFICATION.ADD,
payload: {
type: 'error',
title: 'Veryfying address error',
message: response.payload.error,
2018-02-20 09:30:36 +00:00
cancelable: true,
actions: [
{
label: 'Try again',
callback: () => {
dispatch(showAddress(address_n))
}
}
]
}
})
}
}
}