|
| 1 | +import type { TSchema } from '@sinclair/typebox'; |
| 2 | + |
| 3 | +import { DEVICE } from '@trezor/connect-web'; |
| 4 | +import type { TrezorConnect as TrezorConnectType } from '@trezor/connect-web'; |
| 5 | + |
| 6 | +import type { Field, TrezorConnectDevice } from './common'; |
| 7 | + |
| 8 | +// Method action constants |
| 9 | +export const SET_METHOD = 'method_set'; |
| 10 | +export const SET_SCHEMA = 'schema_set'; |
| 11 | +export const FIELD_CHANGE = 'method_field_change'; |
| 12 | +export const FIELD_DATA_CHANGE = 'method_field_data_change'; |
| 13 | +export const ADD_BATCH = 'method_add_batch'; |
| 14 | +export const REMOVE_BATCH = 'method_remove_batch'; |
| 15 | +export const SET_UNION = 'method_set_union'; |
| 16 | +export const RESPONSE = 'method_response'; |
| 17 | +export const SET_MANUAL_MODE = 'method_set_manual_mode'; |
| 18 | +export const SET_METHOD_PROCESSING = 'method_set_processing'; |
| 19 | + |
| 20 | +// TrezorConnect action constants |
| 21 | +export const ON_SELECT_DEVICE = 'action__on_select_device'; |
| 22 | +export const ON_CHANGE_CONNECT_OPTIONS = 'action__on_change_connect_options'; |
| 23 | +export const ON_CHANGE_CONNECT_OPTION = 'action__on_change_connect_option'; |
| 24 | +export const ON_HANDSHAKE_CONFIRMED = 'action__on_handshake_confirmed'; |
| 25 | +export const ON_INIT_ERROR = 'action__on_init_error'; |
| 26 | + |
| 27 | +// Method action types |
| 28 | +export type MethodAction = |
| 29 | + | { type: typeof SET_METHOD; methodConfig: any } |
| 30 | + | { type: typeof SET_SCHEMA; method: keyof TrezorConnectType; schema: TSchema } |
| 31 | + | { type: typeof FIELD_CHANGE; field: Field<any>; value: any } |
| 32 | + | { type: typeof FIELD_DATA_CHANGE; field: Field<any>; data: any } |
| 33 | + | { type: typeof ADD_BATCH; field: Field<any>; item: any } |
| 34 | + | { type: typeof REMOVE_BATCH; field: Field<any>; batch: any[] } |
| 35 | + | { type: typeof SET_UNION; field: Field<any>; current: any } |
| 36 | + | { type: typeof RESPONSE; response: any } |
| 37 | + | { type: typeof SET_MANUAL_MODE; manualMode: boolean } |
| 38 | + | { type: typeof SET_METHOD_PROCESSING; payload: boolean }; |
| 39 | + |
| 40 | +// TrezorConnect action types |
| 41 | +export type ConnectOptions = { |
| 42 | + manifest?: { |
| 43 | + email: string; |
| 44 | + appUrl: string; |
| 45 | + appName: string; |
| 46 | + appIcon?: string; |
| 47 | + }; |
| 48 | + connectSrc?: string; |
| 49 | + coreMode?: 'auto' | 'popup' | 'deeplink'; |
| 50 | + transportReconnect?: boolean; |
| 51 | + popup?: boolean; |
| 52 | + debug?: boolean; |
| 53 | + lazyLoad?: boolean; |
| 54 | + trustedHost?: boolean; |
| 55 | + [key: string]: any; |
| 56 | +}; |
| 57 | + |
| 58 | +export type TrezorConnectAction = |
| 59 | + | { type: typeof ON_SELECT_DEVICE; path: string } |
| 60 | + | { type: typeof DEVICE.CONNECT; device: TrezorConnectDevice } |
| 61 | + | { type: typeof DEVICE.CONNECT_UNACQUIRED; device: TrezorConnectDevice } |
| 62 | + | { type: typeof DEVICE.DISCONNECT; device: TrezorConnectDevice } |
| 63 | + | { type: typeof ON_CHANGE_CONNECT_OPTIONS; payload: ConnectOptions } |
| 64 | + | { type: typeof ON_HANDSHAKE_CONFIRMED } |
| 65 | + | { type: typeof ON_INIT_ERROR; payload: string } |
| 66 | + | { |
| 67 | + type: typeof ON_CHANGE_CONNECT_OPTION; |
| 68 | + payload: { option: Field<any>; value: any }; |
| 69 | + }; |
0 commit comments