-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstate-transitions.js
121 lines (104 loc) · 4.41 KB
/
state-transitions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* This file defines the states for the state machine, plus the different valid
* transitions to other states from each state.
*
* The transition 'fail' is a special one, and will (also) be triggered if we
* try to apply an invalid transition from that state.
*/
module.exports = {
startState: 'Uninitialized',
endStates: ['BrowserNotSupported', 'Success', 'Aborted', 'Cancelled', 'TimedOut', 'Error'],
Uninitialized: {
initialize: 'Loading', // Expected payload: {canRestart: true/false}
browserError: 'BrowserNotSupported', // Expected payload: undefined
},
Loading: {
loaded: 'CheckingUserAgent', // Expected payload: { sessionPtr, frontendRequest, sessionToken (if present) }
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
CheckingUserAgent: {
prepareQRCode: 'PreparingQRCode', // Expected payload: undefined
prepareButton: 'PreparingYiviButton', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
PreparingQRCode: {
showQRCode: 'ShowingQRCode', // Expected payload: {qr: <payload for in QRs>, showBackButton: true/false}
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
ShowingQRCode: {
appConnected: 'ContinueOn2ndDevice', // Expected payload: undefined
appPairing: 'EnterPairingCode', // Expected payload: frontend options
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
checkUserAgent: 'CheckingUserAgent', // Expected payload: undefined
},
EnterPairingCode: {
codeEntered: 'Pairing', // Expected payload: {enteredPairingCode: ...}
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
Pairing: {
pairingRejected: 'EnterPairingCode', // Expected payload: rejected codeEntered payload
appConnected: 'ContinueOn2ndDevice', // Expected payload: undefined
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
ContinueOn2ndDevice: {
prepareResult: 'PreparingResult', // Expected payload: undefined
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
PreparingYiviButton: {
showYiviButton: 'ShowingYiviButton', // Expected payload: {mobile: <app link for launching the Yivi app>}
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
ShowingYiviButton: {
chooseQR: 'PreparingQRCode', // Expected payload: frontend options
appConnected: 'ContinueInYiviApp', // Expected payload: undefined
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
checkUserAgent: 'CheckingUserAgent', // Expected payload: undefined
},
ContinueInYiviApp: {
prepareResult: 'PreparingResult', // Expected payload: undefined
cancel: 'Cancelled', // Expected payload: undefined
timeout: 'TimedOut', // Expected payload: undefined
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
PreparingResult: {
succeed: 'Success', // Expected payload: result
abort: 'Aborted', // Expected payload: undefined
fail: 'Error', // Expected payload: error object
},
// Possible end states
Cancelled: {
abort: 'Aborted', // Expected payload: undefined
restart: 'Loading', // Expected payload: undefined
},
TimedOut: {
abort: 'Aborted', // Expected payload: undefined
restart: 'Loading', // Expected payload: undefined
},
Error: {
abort: 'Aborted', // Expected payload: undefined
restart: 'Loading', // Expected payload: undefined
},
BrowserNotSupported: {},
Success: {},
Aborted: {},
};