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/js/actions/ModalActions.js

95 lines
2.0 KiB

7 years ago
/* @flow */
'use strict';
import TrezorConnect, { UI, UI_EVENT } from 'trezor-connect';
import * as MODAL from './constants/modal';
6 years ago
import * as CONNECT from './constants/TrezorConnect';
7 years ago
import type { AsyncAction, Action, GetState, Dispatch } from '../flowtype';
7 years ago
export type ModalAction = {
type: typeof MODAL.CLOSE
} | {
type: typeof MODAL.REMEMBER,
device: any
};
export const onPinSubmit = (value: string): Action => {
TrezorConnect.uiResponse({ type: UI.RECEIVE_PIN, payload: value });
7 years ago
return {
type: MODAL.CLOSE
7 years ago
}
}
export const onPassphraseSubmit = (passphrase: string): AsyncAction => {
return async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const resp = await TrezorConnect.uiResponse({
6 years ago
type: UI.RECEIVE_PASSPHRASE,
payload: {
6 years ago
value: passphrase,
save: true
}
});
dispatch({
type: MODAL.CLOSE
6 years ago
});
7 years ago
}
}
export const askForRemember = (device: any): Action => {
7 years ago
return {
6 years ago
type: MODAL.REMEMBER,
device
7 years ago
}
}
export const onRememberDevice = (device: any): Action => {
7 years ago
return {
6 years ago
type: CONNECT.REMEMBER,
device
7 years ago
}
}
export const onForgetDevice = (device: any): Action => {
7 years ago
return {
6 years ago
type: CONNECT.FORGET,
device,
7 years ago
}
}
export const onForgetSingleDevice = (device: any): Action => {
7 years ago
return {
6 years ago
type: CONNECT.FORGET_SINGLE,
device,
7 years ago
}
}
export const onCancel = (): Action => {
7 years ago
return {
type: MODAL.CLOSE
7 years ago
}
}
export const onDuplicateDevice = (device: any): AsyncAction => {
return (dispatch: Dispatch, getState: GetState): void => {
7 years ago
6 years ago
dispatch( onCancel() );
7 years ago
6 years ago
dispatch({
type: CONNECT.DUPLICATE,
device
});
7 years ago
}
}
export default {
onPinSubmit,
onPassphraseSubmit,
askForRemember,
onRememberDevice,
onForgetDevice,
onForgetSingleDevice,
onCancel,
onDuplicateDevice
7 years ago
}