@jetthai/cuora 1.1.333-dev-2 → 1.1.333-dev-4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -25
- package/package.json +2 -3
- package/src/api/common.js +0 -1
- package/src/machine/deposit/index.js +0 -4
- package/src/machine/index.js +0 -2
- package/src/machine/withdraw/withdraw_krway.js +20 -22
- package/src/machine/withdraw/withdraw_manual.js +22 -22
- package/src/machine/withdraw/withdraw_vn.js +20 -22
- package/src/machine/withdraw/withdraw_vn2.js +20 -22
- package/src/request/config.js +1 -16
- package/src/machine/deposit/virtual_bank_cash.js +0 -201
- package/src/machine/deposit/virtual_bank_vn.js +0 -289
- package/src/machine/websocket.js +0 -352
package/CHANGELOG.md
CHANGED
|
@@ -2,33 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
### [1.1.333-dev-
|
|
5
|
+
### [1.1.333-dev-4](https://github.com/jetthai/cuora-module/compare/v1.1.333-dev-3...v1.1.333-dev-4) (2025-01-10)
|
|
6
6
|
|
|
7
|
-
### [1.1.333-dev-
|
|
7
|
+
### [1.1.333-dev-3](https://github.com/jetthai/cuora-module/compare/v1.1.333...v1.1.333-dev-3) (2025-01-10)
|
|
8
8
|
|
|
9
|
-
### [1.1.
|
|
10
|
-
|
|
11
|
-
### [1.1.332-dev-7](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-6...v1.1.332-dev-7) (2025-01-03)
|
|
12
|
-
|
|
13
|
-
### [1.1.332-dev-6](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-5...v1.1.332-dev-6) (2024-12-29)
|
|
14
|
-
|
|
15
|
-
### [1.1.332-dev-5](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-4...v1.1.332-dev-5) (2024-12-28)
|
|
16
|
-
|
|
17
|
-
### [1.1.332-dev-4](https://github.com/jetthai/cuora-module/compare/v1.1.332-tg...v1.1.332-dev-4) (2024-12-28)
|
|
18
|
-
|
|
19
|
-
### [1.1.332-tg](https://github.com/jetthai/cuora-module/compare/v1.1.332...v1.1.332-tg) (2024-12-25)
|
|
20
|
-
|
|
21
|
-
### [1.1.332-dev-8](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-7...v1.1.332-dev-8) (2025-01-03)
|
|
22
|
-
|
|
23
|
-
### [1.1.332-dev-7](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-6...v1.1.332-dev-7) (2025-01-03)
|
|
24
|
-
|
|
25
|
-
### [1.1.332-dev-6](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-5...v1.1.332-dev-6) (2024-12-29)
|
|
26
|
-
|
|
27
|
-
### [1.1.332-tg](https://github.com/jetthai/cuora-module/compare/v1.1.332...v1.1.332-tg) (2024-12-25)
|
|
28
|
-
|
|
29
|
-
### [1.1.332-dev-5](https://github.com/jetthai/cuora-module/compare/v1.1.332-dev-4...v1.1.332-dev-5) (2024-12-28)
|
|
30
|
-
|
|
31
|
-
### [1.1.332-dev-4](https://github.com/jetthai/cuora-module/compare/v1.1.332...v1.1.332-dev-4) (2024-12-28)
|
|
9
|
+
### [1.1.333](https://github.com/jetthai/cuora-module/compare/v1.1.332...v1.1.333) (2025-01-07)
|
|
32
10
|
|
|
33
11
|
### [1.1.332](https://github.com/jetthai/cuora-module/compare/v1.1.331...v1.1.332) (2024-12-24)
|
|
34
12
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetthai/cuora",
|
|
3
|
-
"version": "1.1.333-dev-
|
|
3
|
+
"version": "1.1.333-dev-4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -25,7 +25,6 @@
|
|
|
25
25
|
"ua-parser-js": "^0.7.34",
|
|
26
26
|
"universal-cookie": "^4.0.4",
|
|
27
27
|
"url-join": "^4.0.1",
|
|
28
|
-
"xstate": "^4.25.0"
|
|
29
|
-
"socket.io-client": "^4.8.0"
|
|
28
|
+
"xstate": "^4.25.0"
|
|
30
29
|
}
|
|
31
30
|
}
|
package/src/api/common.js
CHANGED
|
@@ -6,5 +6,4 @@ export default {
|
|
|
6
6
|
getAnnouncements: ({ appSecret }) => ({ url: 'getAnnouncements', params: { appSecret }, method: 'get', isPublic: true }),
|
|
7
7
|
getNavbar: ({ appSecret } = {}) => ({ url: 'getNavbarSetting', params: { appSecret }, method: 'get', isPublic: true }),
|
|
8
8
|
getDefaultAffiliateCode: ({ appSecret }) => ({ url: 'getAffiliateCode', params: { appSecret }, method: 'get', isPublic: true }),
|
|
9
|
-
getSiteInfoConfig: ({ appSecret, config }) => ({ url: 'get-site-config', method: 'get', params: { appSecret, config }, isPublic: true }),
|
|
10
9
|
}
|
|
@@ -22,8 +22,6 @@ import crypto_way from './crypto_way.js'
|
|
|
22
22
|
import crypto_bank_cash from './crypto_bank_cash.js'
|
|
23
23
|
import crypto_qrcode_cash from './crypto_qrcode_cash.js'
|
|
24
24
|
import crypto_way_cash from './crypto_way_cash.js'
|
|
25
|
-
import virtual_bank_vn from './virtual_bank_vn.js'
|
|
26
|
-
import virtual_bank_cash from './virtual_bank_cash.js'
|
|
27
25
|
|
|
28
26
|
export default {
|
|
29
27
|
manual_vn,
|
|
@@ -50,6 +48,4 @@ export default {
|
|
|
50
48
|
crypto_bank_cash,
|
|
51
49
|
crypto_qrcode_cash,
|
|
52
50
|
crypto_way_cash,
|
|
53
|
-
virtual_bank_vn,
|
|
54
|
-
virtual_bank_cash,
|
|
55
51
|
}
|
package/src/machine/index.js
CHANGED
|
@@ -38,7 +38,6 @@ import honor_board_cash from './honor_board_cash.js'
|
|
|
38
38
|
import honor_board from './honor_board.js'
|
|
39
39
|
import user_photo from './user_photo.js'
|
|
40
40
|
import navbar from './navbar.js'
|
|
41
|
-
import websocket from './websocket.js'
|
|
42
41
|
|
|
43
42
|
export default {
|
|
44
43
|
...activity,
|
|
@@ -81,5 +80,4 @@ export default {
|
|
|
81
80
|
user_photo,
|
|
82
81
|
navbar,
|
|
83
82
|
...withdraw,
|
|
84
|
-
websocket,
|
|
85
83
|
}
|
|
@@ -58,35 +58,39 @@ export default function (request) {
|
|
|
58
58
|
src: 'withdrawCheck',
|
|
59
59
|
onDone: [
|
|
60
60
|
{
|
|
61
|
-
target: '
|
|
61
|
+
target: 'notWithdrawMinDepositAmount',
|
|
62
|
+
cond: 'isNotWithdrawMinDepositAmount',
|
|
62
63
|
actions: assign((context, event) => {
|
|
63
64
|
return {
|
|
64
65
|
withdrawCheck: event.data,
|
|
65
66
|
}
|
|
66
67
|
}),
|
|
67
68
|
},
|
|
69
|
+
{
|
|
70
|
+
target: 'passWithdrawCooldownTime',
|
|
71
|
+
cond: 'isPassWithdrawCooldownTime',
|
|
72
|
+
actions: assign((context, event) => {
|
|
73
|
+
return {
|
|
74
|
+
withdrawCheck: event.data,
|
|
75
|
+
}
|
|
76
|
+
}),
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
target: 'notWithdrawable',
|
|
80
|
+
cond: 'isNotWithdrawable',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
target: 'withdrawable',
|
|
84
|
+
},
|
|
68
85
|
],
|
|
69
86
|
onError: {
|
|
70
87
|
target: '#withdraw_krway.fail',
|
|
71
88
|
},
|
|
72
89
|
},
|
|
73
90
|
},
|
|
74
|
-
checkingWithdrawStatus: {
|
|
75
|
-
always: [
|
|
76
|
-
// 提款最低存款金額
|
|
77
|
-
{ target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
|
|
78
|
-
// 提款冷卻時間
|
|
79
|
-
{ target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
|
|
80
|
-
// 提款服務時間
|
|
81
|
-
{ target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
|
|
82
|
-
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
83
|
-
{ target: 'withdrawable' },
|
|
84
|
-
],
|
|
85
|
-
},
|
|
86
91
|
notWithdrawMinDepositAmount: {},
|
|
87
92
|
passWithdrawCooldownTime: {},
|
|
88
93
|
inProcessing: {},
|
|
89
|
-
withdrawServiceTime: {},
|
|
90
94
|
notWithdrawable: {},
|
|
91
95
|
withdrawable: {
|
|
92
96
|
on: {
|
|
@@ -176,16 +180,10 @@ export default function (request) {
|
|
|
176
180
|
return !enableWithdraw || balance < minWithdrawAmount
|
|
177
181
|
},
|
|
178
182
|
isNotWithdrawMinDepositAmount: (context, event) => {
|
|
179
|
-
|
|
180
|
-
return !withdrawCheck?.passDepositeLimit
|
|
183
|
+
return !event.data?.passDepositeLimit
|
|
181
184
|
},
|
|
182
185
|
isPassWithdrawCooldownTime: (context, event) => {
|
|
183
|
-
|
|
184
|
-
return !withdrawCheck?.passWithdrawCooldownTime
|
|
185
|
-
},
|
|
186
|
-
isNotWIthdrawServiceTime: (context, event) => {
|
|
187
|
-
const { withdrawCheck } = context
|
|
188
|
-
return !withdrawCheck?.withdrawInServiceTime
|
|
186
|
+
return !event.data?.passWithdrawCooldownTime
|
|
189
187
|
},
|
|
190
188
|
},
|
|
191
189
|
services: {
|
|
@@ -168,35 +168,41 @@ export default function (request) {
|
|
|
168
168
|
invoke: {
|
|
169
169
|
src: 'withdrawCheck',
|
|
170
170
|
onDone: [
|
|
171
|
+
// 提款最低存款金額
|
|
171
172
|
{
|
|
172
|
-
target: '
|
|
173
|
+
target: 'notWithdrawMinDepositAmount',
|
|
174
|
+
cond: 'isNotWithdrawMinDepositAmount',
|
|
173
175
|
actions: assign((context, event) => {
|
|
174
176
|
return {
|
|
175
177
|
withdrawCheck: event.data,
|
|
176
178
|
}
|
|
177
179
|
}),
|
|
178
180
|
},
|
|
181
|
+
// 提款冷卻時間
|
|
182
|
+
{
|
|
183
|
+
target: 'passWithdrawCooldownTime',
|
|
184
|
+
cond: 'isPassWithdrawCooldownTime',
|
|
185
|
+
actions: assign((context, event) => {
|
|
186
|
+
return {
|
|
187
|
+
withdrawCheck: event.data,
|
|
188
|
+
}
|
|
189
|
+
}),
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
target: 'notWithdrawable',
|
|
193
|
+
cond: 'isNotWithdrawable',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
target: 'withdrawable',
|
|
197
|
+
},
|
|
179
198
|
],
|
|
180
199
|
onError: {
|
|
181
200
|
target: '#withdraw_manual.fail',
|
|
182
201
|
},
|
|
183
202
|
},
|
|
184
203
|
},
|
|
185
|
-
checkingWithdrawStatus: {
|
|
186
|
-
always: [
|
|
187
|
-
// 提款最低存款金額
|
|
188
|
-
{ target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
|
|
189
|
-
// 提款冷卻時間
|
|
190
|
-
{ target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
|
|
191
|
-
// 提款服務時間
|
|
192
|
-
{ target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
|
|
193
|
-
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
194
|
-
{ target: 'withdrawable' },
|
|
195
|
-
],
|
|
196
|
-
},
|
|
197
204
|
notWithdrawMinDepositAmount: {},
|
|
198
205
|
passWithdrawCooldownTime: {},
|
|
199
|
-
withdrawServiceTime: {},
|
|
200
206
|
notWithdrawable: {},
|
|
201
207
|
unbound: {
|
|
202
208
|
// to bank_binding.js
|
|
@@ -519,16 +525,10 @@ export default function (request) {
|
|
|
519
525
|
return event.data?.status === 'otp-verifying'
|
|
520
526
|
},
|
|
521
527
|
isNotWithdrawMinDepositAmount: (context, event) => {
|
|
522
|
-
|
|
523
|
-
return !withdrawCheck?.passDepositeLimit
|
|
528
|
+
return !event.data?.passDepositeLimit
|
|
524
529
|
},
|
|
525
530
|
isPassWithdrawCooldownTime: (context, event) => {
|
|
526
|
-
|
|
527
|
-
return !withdrawCheck?.passWithdrawCooldownTime
|
|
528
|
-
},
|
|
529
|
-
isNotWIthdrawServiceTime: (context, event) => {
|
|
530
|
-
const { withdrawCheck } = context
|
|
531
|
-
return !withdrawCheck?.withdrawInServiceTime
|
|
531
|
+
return !event.data?.passWithdrawCooldownTime
|
|
532
532
|
},
|
|
533
533
|
},
|
|
534
534
|
services: {
|
|
@@ -142,34 +142,38 @@ export default function (request) {
|
|
|
142
142
|
src: 'withdrawCheck',
|
|
143
143
|
onDone: [
|
|
144
144
|
{
|
|
145
|
-
target: '
|
|
145
|
+
target: 'notWithdrawMinDepositAmount',
|
|
146
|
+
cond: 'isNotWithdrawMinDepositAmount',
|
|
146
147
|
actions: assign((context, event) => {
|
|
147
148
|
return {
|
|
148
149
|
withdrawCheck: event.data,
|
|
149
150
|
}
|
|
150
151
|
}),
|
|
151
152
|
},
|
|
153
|
+
{
|
|
154
|
+
target: 'passWithdrawCooldownTime',
|
|
155
|
+
cond: 'isPassWithdrawCooldownTime',
|
|
156
|
+
actions: assign((context, event) => {
|
|
157
|
+
return {
|
|
158
|
+
withdrawCheck: event.data,
|
|
159
|
+
}
|
|
160
|
+
}),
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
target: 'notWithdrawable',
|
|
164
|
+
cond: 'isNotWithdrawable',
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
target: 'withdrawable',
|
|
168
|
+
},
|
|
152
169
|
],
|
|
153
170
|
onError: {
|
|
154
171
|
target: '#withdraw_vn.fail',
|
|
155
172
|
},
|
|
156
173
|
},
|
|
157
174
|
},
|
|
158
|
-
checkingWithdrawStatus: {
|
|
159
|
-
always: [
|
|
160
|
-
// 提款最低存款金額
|
|
161
|
-
{ target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
|
|
162
|
-
// 提款冷卻時間
|
|
163
|
-
{ target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
|
|
164
|
-
// 提款服務時間
|
|
165
|
-
{ target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
|
|
166
|
-
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
167
|
-
{ target: 'withdrawable' },
|
|
168
|
-
],
|
|
169
|
-
},
|
|
170
175
|
notWithdrawMinDepositAmount: {},
|
|
171
176
|
passWithdrawCooldownTime: {},
|
|
172
|
-
withdrawServiceTime: {},
|
|
173
177
|
notWithdrawable: {},
|
|
174
178
|
unbound: {
|
|
175
179
|
// to bank_binding.js
|
|
@@ -455,16 +459,10 @@ export default function (request) {
|
|
|
455
459
|
},
|
|
456
460
|
isNewWalletMode: (context, event) => context.siteConfig.walletMode > 0,
|
|
457
461
|
isNotWithdrawMinDepositAmount: (context, event) => {
|
|
458
|
-
|
|
459
|
-
return !withdrawCheck?.passDepositeLimit
|
|
462
|
+
return !event.data?.passDepositeLimit
|
|
460
463
|
},
|
|
461
464
|
isPassWithdrawCooldownTime: (context, event) => {
|
|
462
|
-
|
|
463
|
-
return !withdrawCheck?.passWithdrawCooldownTime
|
|
464
|
-
},
|
|
465
|
-
isNotWIthdrawServiceTime: (context, event) => {
|
|
466
|
-
const { withdrawCheck } = context
|
|
467
|
-
return !withdrawCheck?.withdrawInServiceTime
|
|
465
|
+
return !event.data?.passWithdrawCooldownTime
|
|
468
466
|
},
|
|
469
467
|
},
|
|
470
468
|
services: {
|
|
@@ -170,34 +170,38 @@ export default function (request) {
|
|
|
170
170
|
src: 'withdrawCheck',
|
|
171
171
|
onDone: [
|
|
172
172
|
{
|
|
173
|
-
target: '
|
|
173
|
+
target: 'notWithdrawMinDepositAmount',
|
|
174
|
+
cond: 'isNotWithdrawMinDepositAmount',
|
|
174
175
|
actions: assign((context, event) => {
|
|
175
176
|
return {
|
|
176
177
|
withdrawCheck: event.data,
|
|
177
178
|
}
|
|
178
179
|
}),
|
|
179
180
|
},
|
|
181
|
+
{
|
|
182
|
+
target: 'passWithdrawCooldownTime',
|
|
183
|
+
cond: 'isPassWithdrawCooldownTime',
|
|
184
|
+
actions: assign((context, event) => {
|
|
185
|
+
return {
|
|
186
|
+
withdrawCheck: event.data,
|
|
187
|
+
}
|
|
188
|
+
}),
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
target: 'notWithdrawable',
|
|
192
|
+
cond: 'isNotWithdrawable',
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
target: 'withdrawable',
|
|
196
|
+
},
|
|
180
197
|
],
|
|
181
198
|
onError: {
|
|
182
199
|
target: '#withdraw_vn2.fail',
|
|
183
200
|
},
|
|
184
201
|
},
|
|
185
202
|
},
|
|
186
|
-
checkingWithdrawStatus: {
|
|
187
|
-
always: [
|
|
188
|
-
// 提款最低存款金額
|
|
189
|
-
{ target: 'notWithdrawMinDepositAmount', cond: 'isNotWithdrawMinDepositAmount' },
|
|
190
|
-
// 提款冷卻時間
|
|
191
|
-
{ target: 'passWithdrawCooldownTime', cond: 'isPassWithdrawCooldownTime' },
|
|
192
|
-
// 提款服務時間
|
|
193
|
-
{ target: 'withdrawServiceTime', cond: 'isNotWIthdrawServiceTime' },
|
|
194
|
-
{ target: 'notWithdrawable', cond: 'isNotWithdrawable' },
|
|
195
|
-
{ target: 'withdrawable' },
|
|
196
|
-
],
|
|
197
|
-
},
|
|
198
203
|
notWithdrawMinDepositAmount: {},
|
|
199
204
|
passWithdrawCooldownTime: {},
|
|
200
|
-
withdrawServiceTime: {},
|
|
201
205
|
notWithdrawable: {},
|
|
202
206
|
unbound: {
|
|
203
207
|
// to bank_binding.js
|
|
@@ -480,16 +484,10 @@ export default function (request) {
|
|
|
480
484
|
return event.data?.status === 'otp-verifying'
|
|
481
485
|
},
|
|
482
486
|
isNotWithdrawMinDepositAmount: (context, event) => {
|
|
483
|
-
|
|
484
|
-
return !withdrawCheck?.passDepositeLimit
|
|
487
|
+
return !event.data?.passDepositeLimit
|
|
485
488
|
},
|
|
486
489
|
isPassWithdrawCooldownTime: (context, event) => {
|
|
487
|
-
|
|
488
|
-
return !withdrawCheck?.passWithdrawCooldownTime
|
|
489
|
-
},
|
|
490
|
-
isNotWIthdrawServiceTime: (context, event) => {
|
|
491
|
-
const { withdrawCheck } = context
|
|
492
|
-
return !withdrawCheck?.withdrawInServiceTime
|
|
490
|
+
return !event.data?.passWithdrawCooldownTime
|
|
493
491
|
},
|
|
494
492
|
},
|
|
495
493
|
services: {
|
package/src/request/config.js
CHANGED
|
@@ -3,20 +3,7 @@ import urljoin from 'url-join'
|
|
|
3
3
|
// const urljoin = require('url-join')
|
|
4
4
|
|
|
5
5
|
export default class Config {
|
|
6
|
-
constructor({
|
|
7
|
-
apiURL,
|
|
8
|
-
apiVersion,
|
|
9
|
-
clientId,
|
|
10
|
-
appSecret,
|
|
11
|
-
platform,
|
|
12
|
-
version,
|
|
13
|
-
fpToken,
|
|
14
|
-
sentry,
|
|
15
|
-
defaultChannel,
|
|
16
|
-
defaultSubchannel,
|
|
17
|
-
socketURL,
|
|
18
|
-
bucketName,
|
|
19
|
-
}) {
|
|
6
|
+
constructor({ apiURL, apiVersion, clientId, appSecret, platform, version, fpToken, sentry, defaultChannel, defaultSubchannel }) {
|
|
20
7
|
this.apiURL = apiURL
|
|
21
8
|
this.apiVersion = apiVersion
|
|
22
9
|
this.clientId = clientId
|
|
@@ -28,8 +15,6 @@ export default class Config {
|
|
|
28
15
|
this.sentry = sentry
|
|
29
16
|
this.defaultChannel = defaultChannel
|
|
30
17
|
this.defaultSubchannel = defaultSubchannel
|
|
31
|
-
this.socketURL = socketURL
|
|
32
|
-
this.bucketName = bucketName
|
|
33
18
|
}
|
|
34
19
|
|
|
35
20
|
setApiURL(url) {
|
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import payment from '@jetthai/cuora/src/api/payment.js'
|
|
3
|
-
import { max } from '@jetthai/cuora/src/util/index.js'
|
|
4
|
-
|
|
5
|
-
export default function (request, context) {
|
|
6
|
-
const { appSecret } = request.config
|
|
7
|
-
const { paymentDetail = [], promotion, selectedAmount, siteConfig = {} } = context || {}
|
|
8
|
-
|
|
9
|
-
return createMachine(
|
|
10
|
-
{
|
|
11
|
-
id: 'virtual_bank_cash',
|
|
12
|
-
initial: 'loading',
|
|
13
|
-
context: {
|
|
14
|
-
siteConfig,
|
|
15
|
-
paymentDetail,
|
|
16
|
-
promotion,
|
|
17
|
-
selectedAmount,
|
|
18
|
-
|
|
19
|
-
bindingPaymentList: {},
|
|
20
|
-
bindingPaymentInfo: {},
|
|
21
|
-
virtualBanks: {},
|
|
22
|
-
|
|
23
|
-
depositTime: null,
|
|
24
|
-
|
|
25
|
-
currentCategory: 'virtualBank',
|
|
26
|
-
method: null,
|
|
27
|
-
currentPayment: null,
|
|
28
|
-
currentApplyerBank: null,
|
|
29
|
-
|
|
30
|
-
calculation: null,
|
|
31
|
-
processing: null,
|
|
32
|
-
},
|
|
33
|
-
states: {
|
|
34
|
-
loading: {
|
|
35
|
-
invoke: {
|
|
36
|
-
src: 'fetchInitData',
|
|
37
|
-
onDone: {
|
|
38
|
-
target: 'checking',
|
|
39
|
-
actions: 'setInitData',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
checking: {
|
|
44
|
-
always: [
|
|
45
|
-
{
|
|
46
|
-
target: 'submitted',
|
|
47
|
-
cond: 'isProcessing',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
target: 'debouncing',
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
},
|
|
54
|
-
loaded: {},
|
|
55
|
-
debouncing: {
|
|
56
|
-
entry: 'clearCalculation',
|
|
57
|
-
after: {
|
|
58
|
-
1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'loaded' }],
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
calculating: {
|
|
62
|
-
invoke: {
|
|
63
|
-
src: 'fetchCalculation',
|
|
64
|
-
onDone: {
|
|
65
|
-
target: 'calculated',
|
|
66
|
-
actions: 'setCalculation',
|
|
67
|
-
},
|
|
68
|
-
onError: {
|
|
69
|
-
target: 'loaded',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
},
|
|
73
|
-
calculated: {
|
|
74
|
-
on: {
|
|
75
|
-
SET_DEPOSIT_TIME: {
|
|
76
|
-
actions: 'setDepositTime',
|
|
77
|
-
},
|
|
78
|
-
SUBMIT: {
|
|
79
|
-
target: 'submitting',
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
submitting: {
|
|
84
|
-
invoke: {
|
|
85
|
-
src: 'submitDeposit',
|
|
86
|
-
onDone: {
|
|
87
|
-
target: 'submitted',
|
|
88
|
-
actions: 'setProcessing',
|
|
89
|
-
},
|
|
90
|
-
onError: {
|
|
91
|
-
target: 'loaded',
|
|
92
|
-
},
|
|
93
|
-
},
|
|
94
|
-
},
|
|
95
|
-
submitted: {},
|
|
96
|
-
},
|
|
97
|
-
on: {
|
|
98
|
-
SET_PROMOTION: {
|
|
99
|
-
target: 'debouncing',
|
|
100
|
-
actions: 'setPromotion',
|
|
101
|
-
internal: false,
|
|
102
|
-
},
|
|
103
|
-
INPUT_AMOUNT: {
|
|
104
|
-
target: 'debouncing',
|
|
105
|
-
actions: 'inputAmount',
|
|
106
|
-
internal: false,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
actions: {
|
|
112
|
-
setInitData: assign((context, event) => {
|
|
113
|
-
const { currentPayment } = event.data
|
|
114
|
-
|
|
115
|
-
const processing = currentPayment?.processing?.[0]
|
|
116
|
-
|
|
117
|
-
const virtualBanks = currentPayment?.virtualBanks?.[0]
|
|
118
|
-
|
|
119
|
-
return {
|
|
120
|
-
currentPayment,
|
|
121
|
-
method: currentPayment.method,
|
|
122
|
-
processing,
|
|
123
|
-
selectedAmount: max(promotion?.minimumAmount, currentPayment?.minimum, selectedAmount, 0),
|
|
124
|
-
virtualBanks,
|
|
125
|
-
}
|
|
126
|
-
}),
|
|
127
|
-
inputAmount: assign((context, event) => {
|
|
128
|
-
return { selectedAmount: event.data }
|
|
129
|
-
}),
|
|
130
|
-
setCalculation: assign((context, event) => {
|
|
131
|
-
return {
|
|
132
|
-
calculation: event.data,
|
|
133
|
-
}
|
|
134
|
-
}),
|
|
135
|
-
setProcessing: assign((context, event) => {
|
|
136
|
-
return {
|
|
137
|
-
processing: event.data,
|
|
138
|
-
}
|
|
139
|
-
}),
|
|
140
|
-
clearCalculation: assign((context, event) => {
|
|
141
|
-
return {
|
|
142
|
-
calculation: null,
|
|
143
|
-
}
|
|
144
|
-
}),
|
|
145
|
-
setDepositTime: assign((context, event) => {
|
|
146
|
-
return {
|
|
147
|
-
depositTime: event.data,
|
|
148
|
-
}
|
|
149
|
-
}),
|
|
150
|
-
setPromotion: assign((context, event) => {
|
|
151
|
-
return {
|
|
152
|
-
promotion: event.data,
|
|
153
|
-
}
|
|
154
|
-
}),
|
|
155
|
-
},
|
|
156
|
-
guards: {
|
|
157
|
-
isCalculable: (context, event) => {
|
|
158
|
-
const {
|
|
159
|
-
selectedAmount,
|
|
160
|
-
currentPayment: { maximum, minimum },
|
|
161
|
-
} = context
|
|
162
|
-
return selectedAmount && minimum <= +selectedAmount && +selectedAmount <= maximum
|
|
163
|
-
},
|
|
164
|
-
isProcessing: (context, event) => {
|
|
165
|
-
return context.processing
|
|
166
|
-
},
|
|
167
|
-
},
|
|
168
|
-
services: {
|
|
169
|
-
fetchInitData: async (context, event) => {
|
|
170
|
-
const { paymentDetail = [] } = context
|
|
171
|
-
const currentPayment = paymentDetail.find((element) => element.category === context.currentCategory && element.transferType === 'deposit')
|
|
172
|
-
|
|
173
|
-
return {
|
|
174
|
-
currentPayment,
|
|
175
|
-
}
|
|
176
|
-
},
|
|
177
|
-
fetchCalculation: async (context, event) => {
|
|
178
|
-
const { method, selectedAmount, promotion } = context
|
|
179
|
-
return await request.send(
|
|
180
|
-
payment.getDepositExpectedResult({
|
|
181
|
-
method,
|
|
182
|
-
amount: selectedAmount,
|
|
183
|
-
promotionsNo: promotion?.promotionsNo,
|
|
184
|
-
})
|
|
185
|
-
)
|
|
186
|
-
},
|
|
187
|
-
submitDeposit: async (context, event) => {
|
|
188
|
-
const { method, selectedAmount, depositTime, promotion } = context
|
|
189
|
-
return await request.send(
|
|
190
|
-
payment.submitDepositTransactionBank({
|
|
191
|
-
method,
|
|
192
|
-
amount: selectedAmount,
|
|
193
|
-
depositTime,
|
|
194
|
-
promotionsNo: promotion?.promotionsNo,
|
|
195
|
-
})
|
|
196
|
-
)
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
}
|
|
200
|
-
)
|
|
201
|
-
}
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import payment from '../../api/payment.js'
|
|
3
|
-
|
|
4
|
-
export default function (request) {
|
|
5
|
-
const { appSecret } = request.config
|
|
6
|
-
|
|
7
|
-
return createMachine(
|
|
8
|
-
{
|
|
9
|
-
id: 'virtual_bank',
|
|
10
|
-
initial: 'loading',
|
|
11
|
-
context: {
|
|
12
|
-
siteConfig: null,
|
|
13
|
-
paymentDetail: [],
|
|
14
|
-
virtualBanks: {},
|
|
15
|
-
|
|
16
|
-
amount: null,
|
|
17
|
-
depositTime: null,
|
|
18
|
-
|
|
19
|
-
currentCategory: 'virtualBank',
|
|
20
|
-
method: null,
|
|
21
|
-
currentPayment: null,
|
|
22
|
-
|
|
23
|
-
calculation: null,
|
|
24
|
-
processing: null,
|
|
25
|
-
|
|
26
|
-
// use for wallet mode 3
|
|
27
|
-
promotion: null,
|
|
28
|
-
},
|
|
29
|
-
states: {
|
|
30
|
-
loading: {
|
|
31
|
-
initial: 'init',
|
|
32
|
-
states: {
|
|
33
|
-
init: {
|
|
34
|
-
invoke: {
|
|
35
|
-
src: 'fetchPaymentDetail',
|
|
36
|
-
onDone: {
|
|
37
|
-
target: '#virtual_bank.step1',
|
|
38
|
-
actions: 'setInitData',
|
|
39
|
-
},
|
|
40
|
-
onError: {
|
|
41
|
-
target: '#virtual_bank.fail',
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
},
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
step1: {
|
|
48
|
-
initial: 'promotion',
|
|
49
|
-
states: {
|
|
50
|
-
promotion: {
|
|
51
|
-
always: [
|
|
52
|
-
{
|
|
53
|
-
target: 'idle',
|
|
54
|
-
cond: 'isDoubleWalletMode',
|
|
55
|
-
},
|
|
56
|
-
{
|
|
57
|
-
target: 'calculating',
|
|
58
|
-
actions: 'setPromotionDefaultAmount',
|
|
59
|
-
cond: 'hasMinPromotionDeposit',
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
target: 'idle',
|
|
63
|
-
},
|
|
64
|
-
],
|
|
65
|
-
},
|
|
66
|
-
idle: {},
|
|
67
|
-
calculating: {
|
|
68
|
-
invoke: {
|
|
69
|
-
src: 'fetchCalculation',
|
|
70
|
-
onDone: {
|
|
71
|
-
target: 'idle',
|
|
72
|
-
actions: 'setCalculation',
|
|
73
|
-
},
|
|
74
|
-
onError: {
|
|
75
|
-
target: 'idle',
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
debouncing: {
|
|
80
|
-
after: {
|
|
81
|
-
1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'idle' }],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
},
|
|
85
|
-
on: {
|
|
86
|
-
SET_AMOUNT: {
|
|
87
|
-
actions: ['setAmount', 'clearCalculation'],
|
|
88
|
-
},
|
|
89
|
-
CALCULATE: {
|
|
90
|
-
target: '.debouncing',
|
|
91
|
-
},
|
|
92
|
-
CLEAR_CALCULATION: {
|
|
93
|
-
target: '.debouncing',
|
|
94
|
-
actions: 'clearCalculation',
|
|
95
|
-
},
|
|
96
|
-
TRANSACT: {
|
|
97
|
-
target: 'checking',
|
|
98
|
-
cond: 'isCalculated',
|
|
99
|
-
},
|
|
100
|
-
},
|
|
101
|
-
},
|
|
102
|
-
checking: {
|
|
103
|
-
always: [
|
|
104
|
-
{
|
|
105
|
-
target: 'pending',
|
|
106
|
-
cond: (context, event) => {
|
|
107
|
-
const { siteConfig = {}, calculation, promotion } = context
|
|
108
|
-
const { walletMode } = siteConfig
|
|
109
|
-
const { promotionsNo, activityNo } = promotion
|
|
110
|
-
const isNoBonus = promotionsNo === 'none' || activityNo === 'none'
|
|
111
|
-
return walletMode === '4' && !!calculation && !isNoBonus
|
|
112
|
-
},
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
target: '#virtual_bank.step2',
|
|
116
|
-
},
|
|
117
|
-
],
|
|
118
|
-
},
|
|
119
|
-
pending: {
|
|
120
|
-
on: {
|
|
121
|
-
CONFIRM: {
|
|
122
|
-
target: '#virtual_bank.step2',
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
step2: {
|
|
127
|
-
initial: 'idle',
|
|
128
|
-
states: {
|
|
129
|
-
idle: {},
|
|
130
|
-
calculating: {
|
|
131
|
-
invoke: {
|
|
132
|
-
src: 'fetchCalculation',
|
|
133
|
-
onDone: {
|
|
134
|
-
target: 'idle',
|
|
135
|
-
actions: 'setCalculation',
|
|
136
|
-
},
|
|
137
|
-
onError: {
|
|
138
|
-
target: 'idle',
|
|
139
|
-
},
|
|
140
|
-
},
|
|
141
|
-
},
|
|
142
|
-
debouncing: {
|
|
143
|
-
after: {
|
|
144
|
-
1000: [{ target: 'calculating', cond: 'isCalculable' }, { target: 'idle' }],
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
submitting: {
|
|
148
|
-
invoke: {
|
|
149
|
-
src: 'submitDeposit',
|
|
150
|
-
onDone: {
|
|
151
|
-
target: '#virtual_bank.submitted',
|
|
152
|
-
actions: 'setProcessing',
|
|
153
|
-
},
|
|
154
|
-
onError: {
|
|
155
|
-
target: 'idle',
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
},
|
|
159
|
-
},
|
|
160
|
-
on: {
|
|
161
|
-
SET_AMOUNT: {
|
|
162
|
-
actions: ['setAmount', 'clearCalculation'],
|
|
163
|
-
},
|
|
164
|
-
CALCULATE: {
|
|
165
|
-
target: '.debouncing',
|
|
166
|
-
},
|
|
167
|
-
SET_DEPOSIT_TIME: {
|
|
168
|
-
actions: 'setDepositTime',
|
|
169
|
-
},
|
|
170
|
-
CLEAR_CALCULATION: {
|
|
171
|
-
target: '.debouncing',
|
|
172
|
-
actions: 'clearCalculation',
|
|
173
|
-
},
|
|
174
|
-
SUBMIT: {
|
|
175
|
-
target: '.submitting',
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
},
|
|
179
|
-
processing: {},
|
|
180
|
-
submitted: {},
|
|
181
|
-
fail: {},
|
|
182
|
-
},
|
|
183
|
-
on: {
|
|
184
|
-
SET_PROMOTION: {
|
|
185
|
-
actions: 'setPromotion',
|
|
186
|
-
},
|
|
187
|
-
},
|
|
188
|
-
},
|
|
189
|
-
{
|
|
190
|
-
actions: {
|
|
191
|
-
setInitData: assign((context, event) => {
|
|
192
|
-
const paymentDetail = event.data || []
|
|
193
|
-
const currentPayment = paymentDetail.find((element) => element.category === context.currentCategory)
|
|
194
|
-
const { method, processing, virtualBanks } = currentPayment || {}
|
|
195
|
-
|
|
196
|
-
return {
|
|
197
|
-
paymentDetail,
|
|
198
|
-
currentPayment,
|
|
199
|
-
method,
|
|
200
|
-
processing: processing?.[0],
|
|
201
|
-
virtualBanks: virtualBanks?.[0],
|
|
202
|
-
}
|
|
203
|
-
}),
|
|
204
|
-
setAmount: assign((context, event) => {
|
|
205
|
-
return {
|
|
206
|
-
amount: event.data,
|
|
207
|
-
}
|
|
208
|
-
}),
|
|
209
|
-
setCalculation: assign((context, event) => {
|
|
210
|
-
return {
|
|
211
|
-
calculation: event.data,
|
|
212
|
-
}
|
|
213
|
-
}),
|
|
214
|
-
setProcessing: assign((context, event) => {
|
|
215
|
-
return {
|
|
216
|
-
processing: event.data,
|
|
217
|
-
}
|
|
218
|
-
}),
|
|
219
|
-
clearCalculation: assign((context, event) => {
|
|
220
|
-
return {
|
|
221
|
-
calculation: null,
|
|
222
|
-
}
|
|
223
|
-
}),
|
|
224
|
-
setDepositTime: assign((context, event) => {
|
|
225
|
-
return {
|
|
226
|
-
depositTime: event.data,
|
|
227
|
-
}
|
|
228
|
-
}),
|
|
229
|
-
setPromotion: assign((context, event) => {
|
|
230
|
-
return {
|
|
231
|
-
promotion: event.data,
|
|
232
|
-
}
|
|
233
|
-
}),
|
|
234
|
-
setPromotionDefaultAmount: assign((context, event) => {
|
|
235
|
-
return {
|
|
236
|
-
amount: context.promotion.minimumAmount,
|
|
237
|
-
}
|
|
238
|
-
}),
|
|
239
|
-
},
|
|
240
|
-
guards: {
|
|
241
|
-
isDoubleWalletMode: (context, event) => {
|
|
242
|
-
return context.siteConfig?.walletMode === '4'
|
|
243
|
-
},
|
|
244
|
-
isCalculable: (context, event) => {
|
|
245
|
-
const {
|
|
246
|
-
amount,
|
|
247
|
-
currentPayment: { maximum, minimum },
|
|
248
|
-
} = context
|
|
249
|
-
return amount && minimum <= +amount && +amount <= maximum
|
|
250
|
-
},
|
|
251
|
-
isCalculated: (context, event) => {
|
|
252
|
-
return context.calculation
|
|
253
|
-
},
|
|
254
|
-
isProcessing: (context, event) => {
|
|
255
|
-
return context.processing
|
|
256
|
-
},
|
|
257
|
-
hasMinPromotionDeposit: (context, event) => {
|
|
258
|
-
return context.promotion?.minimumAmount
|
|
259
|
-
},
|
|
260
|
-
},
|
|
261
|
-
services: {
|
|
262
|
-
fetchPaymentDetail: async (context, event) => {
|
|
263
|
-
return await request.send(payment.getPaymentDetail({ transferType: 'DEPOSIT' }))
|
|
264
|
-
},
|
|
265
|
-
fetchCalculation: async (context, event) => {
|
|
266
|
-
const { method, amount, promotion } = context
|
|
267
|
-
return await request.send(
|
|
268
|
-
payment.getDepositExpectedResult({
|
|
269
|
-
method,
|
|
270
|
-
amount,
|
|
271
|
-
promotionsNo: promotion?.activityNo,
|
|
272
|
-
})
|
|
273
|
-
)
|
|
274
|
-
},
|
|
275
|
-
submitDeposit: async (context, event) => {
|
|
276
|
-
const { method, amount, depositTime, promotion } = context
|
|
277
|
-
return await request.send(
|
|
278
|
-
payment.submitDepositTransactionBank({
|
|
279
|
-
method,
|
|
280
|
-
amount,
|
|
281
|
-
depositTime,
|
|
282
|
-
promotionsNo: promotion?.activityNo,
|
|
283
|
-
})
|
|
284
|
-
)
|
|
285
|
-
},
|
|
286
|
-
},
|
|
287
|
-
}
|
|
288
|
-
)
|
|
289
|
-
}
|
package/src/machine/websocket.js
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
import { assign, createMachine } from 'xstate'
|
|
2
|
-
import { io } from 'socket.io-client'
|
|
3
|
-
|
|
4
|
-
export default function (request) {
|
|
5
|
-
const { socketURL, bucketName, clientId, sentry } = request.config
|
|
6
|
-
const maxReconnectCount = 3
|
|
7
|
-
return createMachine(
|
|
8
|
-
{
|
|
9
|
-
id: 'socket',
|
|
10
|
-
initial: 'idle',
|
|
11
|
-
context: {
|
|
12
|
-
clientSocket: null,
|
|
13
|
-
reconnectCount: 0,
|
|
14
|
-
connectStatus: 0, // 0: 未連線, 1: 連線中, 2: 連線成功,
|
|
15
|
-
connectError: null,
|
|
16
|
-
analytics: null,
|
|
17
|
-
url: `https://storage.googleapis.com/${bucketName}/site_resources/${clientId}/target/target.json`,
|
|
18
|
-
socketURL: socketURL,
|
|
19
|
-
socketData: {},
|
|
20
|
-
},
|
|
21
|
-
states: {
|
|
22
|
-
idle: {},
|
|
23
|
-
fetchSocket: {
|
|
24
|
-
invoke: {
|
|
25
|
-
src: 'fetchSocket',
|
|
26
|
-
onDone: {
|
|
27
|
-
target: 'connecting',
|
|
28
|
-
actions: 'saveSocketURL',
|
|
29
|
-
},
|
|
30
|
-
onError: {
|
|
31
|
-
target: 'idle',
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
connecting: {
|
|
36
|
-
entry: 'setConnecting',
|
|
37
|
-
invoke: {
|
|
38
|
-
src: 'connectSocket',
|
|
39
|
-
onDone: {
|
|
40
|
-
actions: 'setSocket',
|
|
41
|
-
target: 'connected',
|
|
42
|
-
},
|
|
43
|
-
onError: {
|
|
44
|
-
target: 'disconnected',
|
|
45
|
-
actions: 'setConnectError',
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
connected: {
|
|
50
|
-
invoke: {
|
|
51
|
-
src: 'listenToSocketEvents', // 監聽事件
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
disconnected: {
|
|
55
|
-
after: {
|
|
56
|
-
0: {
|
|
57
|
-
target: 'reconnect',
|
|
58
|
-
cond: 'isReconnect',
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
reconnect: {
|
|
63
|
-
after: {
|
|
64
|
-
2000: {
|
|
65
|
-
actions: 'setReconnectCount',
|
|
66
|
-
target: 'connecting',
|
|
67
|
-
cond: 'isNeedConnect',
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
checkSocketConnect: {
|
|
72
|
-
always: [{ target: 'fetchSocket', cond: 'isNeedConnect' }, { target: 'connected' }],
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
on: {
|
|
76
|
-
CONNECT: {
|
|
77
|
-
target: 'fetchSocket',
|
|
78
|
-
cond: 'isNeedConnect',
|
|
79
|
-
},
|
|
80
|
-
SET_CONNECTED: {
|
|
81
|
-
actions: 'setSocket',
|
|
82
|
-
},
|
|
83
|
-
CONNECT_ERROR: {
|
|
84
|
-
actions: 'setConnectError',
|
|
85
|
-
},
|
|
86
|
-
DISCONNECT: {
|
|
87
|
-
actions: 'setDisconnected',
|
|
88
|
-
},
|
|
89
|
-
DISCONNECT_SOCKET: {
|
|
90
|
-
actions: 'disconnectSocket',
|
|
91
|
-
target: 'idle',
|
|
92
|
-
},
|
|
93
|
-
CHECK_SOCKET: {
|
|
94
|
-
target: 'checkSocketConnect',
|
|
95
|
-
},
|
|
96
|
-
ACTIVITY_INFO: {
|
|
97
|
-
actions: 'setActivityInfo',
|
|
98
|
-
},
|
|
99
|
-
CLEAR_SOCKET_DATA: {
|
|
100
|
-
actions: 'clearSocketData',
|
|
101
|
-
},
|
|
102
|
-
SET_ANALYTICS: {
|
|
103
|
-
actions: 'setAnalytics',
|
|
104
|
-
},
|
|
105
|
-
PUSH_ANALYTICS: {
|
|
106
|
-
actions: 'pushEvent',
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
{
|
|
111
|
-
actions: {
|
|
112
|
-
saveSocketURL: assign((context, event) => {
|
|
113
|
-
const { socketURL } = event.data
|
|
114
|
-
// console.log('[socket][saveSocketURL] socketURL:', socketURL)
|
|
115
|
-
return { socketURL }
|
|
116
|
-
}),
|
|
117
|
-
setSocket: assign((context, event) => {
|
|
118
|
-
console.log('[socket][setSocket] clientSocket:', event.data.id)
|
|
119
|
-
return {
|
|
120
|
-
clientSocket: event.data,
|
|
121
|
-
connectStatus: 2, // 0: 未連線, 1: 連線中, 2: 連線成功
|
|
122
|
-
}
|
|
123
|
-
}),
|
|
124
|
-
setConnectError: assign((context, event) => {
|
|
125
|
-
const error = event.data
|
|
126
|
-
const { analytics, connectError } = context
|
|
127
|
-
if (connectError === null) {
|
|
128
|
-
sentry?.captureException(`[socket] connectError ${error}`)
|
|
129
|
-
analytics?.push({
|
|
130
|
-
event: 'connect_error',
|
|
131
|
-
message: error,
|
|
132
|
-
})
|
|
133
|
-
}
|
|
134
|
-
return {
|
|
135
|
-
connectError: error,
|
|
136
|
-
connectStatus: 0, // 0: 未連線, 1: 連線中, 2: 連線成功
|
|
137
|
-
}
|
|
138
|
-
}),
|
|
139
|
-
setConnecting: assign((context, event) => {
|
|
140
|
-
return {
|
|
141
|
-
connectStatus: 1, // 0: 未連線, 1: 連線中, 2: 連線成功
|
|
142
|
-
}
|
|
143
|
-
}),
|
|
144
|
-
disconnectSocket: assign((context, event) => {
|
|
145
|
-
// 主動觸發斷開socket連接
|
|
146
|
-
let { clientSocket } = context
|
|
147
|
-
console.log('[socket][disconnectSocket]')
|
|
148
|
-
if (clientSocket) {
|
|
149
|
-
clientSocket.disconnect()
|
|
150
|
-
clientSocket = null
|
|
151
|
-
}
|
|
152
|
-
return { clientSocket }
|
|
153
|
-
}),
|
|
154
|
-
setDisconnected: assign((context, event) => {
|
|
155
|
-
const { reason } = event
|
|
156
|
-
const { analytics } = context
|
|
157
|
-
if (reason !== 'io client disconnect') {
|
|
158
|
-
analytics?.push({
|
|
159
|
-
event: 'socket_disconnect',
|
|
160
|
-
message: reason,
|
|
161
|
-
})
|
|
162
|
-
}
|
|
163
|
-
return {
|
|
164
|
-
connectStatus: 0, // 0: 未連線, 1: 連線中, 2: 連線成功
|
|
165
|
-
}
|
|
166
|
-
}),
|
|
167
|
-
setActivityInfo: assign((context, event) => {
|
|
168
|
-
const { data } = event
|
|
169
|
-
return { socketData: data }
|
|
170
|
-
}),
|
|
171
|
-
clearSocketData: assign({
|
|
172
|
-
socketData: (_, event) => {},
|
|
173
|
-
}),
|
|
174
|
-
setAnalytics: assign({
|
|
175
|
-
analytics: (_, event) => event.data,
|
|
176
|
-
}),
|
|
177
|
-
pushEvent: assign((context, value) => {
|
|
178
|
-
const { analytics } = context
|
|
179
|
-
const { data, event } = value.data
|
|
180
|
-
analytics?.push(
|
|
181
|
-
{
|
|
182
|
-
event: event,
|
|
183
|
-
paymentMethod: data.paymentMethod,
|
|
184
|
-
transaction_id: data.transactionId,
|
|
185
|
-
currency: data.currency,
|
|
186
|
-
value: data.value,
|
|
187
|
-
app_value: data.value,
|
|
188
|
-
},
|
|
189
|
-
{ eventID: data.transactionId }
|
|
190
|
-
)
|
|
191
|
-
if (event === 'purchase' && data?.isFirst === true) {
|
|
192
|
-
analytics?.push(
|
|
193
|
-
{
|
|
194
|
-
event: 'first_deposit',
|
|
195
|
-
paymentMethod: data.paymentMethod,
|
|
196
|
-
transaction_id: data.transactionId,
|
|
197
|
-
currency: data.currency,
|
|
198
|
-
value: data.value,
|
|
199
|
-
app_value: data.value,
|
|
200
|
-
},
|
|
201
|
-
{ eventID: data.transactionId }
|
|
202
|
-
)
|
|
203
|
-
}
|
|
204
|
-
}),
|
|
205
|
-
setReconnectCount: assign((context, event) => {
|
|
206
|
-
let { reconnectCount } = context
|
|
207
|
-
reconnectCount++
|
|
208
|
-
return { reconnectCount }
|
|
209
|
-
}),
|
|
210
|
-
},
|
|
211
|
-
guards: {
|
|
212
|
-
isNeedConnect: (context, event) => {
|
|
213
|
-
const { connectStatus, clientSocket } = context
|
|
214
|
-
// 檢查 Socket 是否已連接
|
|
215
|
-
if (connectStatus == 1 || (clientSocket && clientSocket?.connected)) {
|
|
216
|
-
// console.log(`[socket] [isNeedConnect] 不做socket連線`)
|
|
217
|
-
return false
|
|
218
|
-
} else {
|
|
219
|
-
// console.log(`[socket] [isNeedConnect] 重新socket連線`)
|
|
220
|
-
return true
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
isReconnect: (context, event) => {
|
|
224
|
-
const { reconnectCount, connectError } = context
|
|
225
|
-
return reconnectCount < maxReconnectCount && connectError === 'io server disconnect'
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
services: {
|
|
229
|
-
fetchSocket: async (context, event) => {
|
|
230
|
-
// 取得 Socket 連線資訊及選線
|
|
231
|
-
const { url } = context
|
|
232
|
-
const socketTester = new SocketTester(url)
|
|
233
|
-
const socketURL = await socketTester.test()
|
|
234
|
-
console.log('[socket][fetchSocket] socketURL:', socketURL)
|
|
235
|
-
return { socketURL }
|
|
236
|
-
},
|
|
237
|
-
connectSocket: async (context, event) => {
|
|
238
|
-
// 連接 Socket
|
|
239
|
-
const { socketURL } = context
|
|
240
|
-
const authToken = request.getToken()
|
|
241
|
-
console.log('[socket][connectSocket] socketURL:', socketURL)
|
|
242
|
-
const clientSocket = io(`${socketURL}/frontend`, {
|
|
243
|
-
withCredentials: true,
|
|
244
|
-
forceNew: true,
|
|
245
|
-
transports: ['websocket', 'polling'],
|
|
246
|
-
auth: {
|
|
247
|
-
Authorization: authToken,
|
|
248
|
-
},
|
|
249
|
-
})
|
|
250
|
-
return new Promise((resolve, reject) => {
|
|
251
|
-
clientSocket.on('connect', () => {
|
|
252
|
-
console.log('[socket][connect] success', clientSocket.id)
|
|
253
|
-
resolve(clientSocket) // 成功後返回 socket 實例
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
clientSocket.on('connect_error', (error) => {
|
|
257
|
-
console.log('[socket][connect_error] error', error.message)
|
|
258
|
-
reject(error.message) // 連接錯誤
|
|
259
|
-
})
|
|
260
|
-
})
|
|
261
|
-
},
|
|
262
|
-
listenToSocketEvents: (context) => (callback) => {
|
|
263
|
-
// 監聽事件
|
|
264
|
-
const { clientSocket } = context
|
|
265
|
-
|
|
266
|
-
if (!clientSocket) {
|
|
267
|
-
console.log('[socket][listenToSocketEvents] Socket is not connected')
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 監聽 activity-info 事件
|
|
271
|
-
clientSocket.on('activity-info', (data) => {
|
|
272
|
-
console.log('[socket][activity-info]:', data)
|
|
273
|
-
callback({ type: 'ACTIVITY_INFO', data })
|
|
274
|
-
})
|
|
275
|
-
|
|
276
|
-
// 監聽 payment-info 事件
|
|
277
|
-
clientSocket.on('payment-info', (data) => {
|
|
278
|
-
console.log('[socket][payment-info]:', data, data.windowType)
|
|
279
|
-
if (data.windowType === 'toast') {
|
|
280
|
-
callback({ type: 'ACTIVITY_INFO', data })
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
callback({ type: 'PUSH_ANALYTICS', data })
|
|
284
|
-
})
|
|
285
|
-
|
|
286
|
-
// 監聽 'connect' 事件
|
|
287
|
-
clientSocket.on('connect', () => {
|
|
288
|
-
// console.log('[socket] [listenToSocketEvents] [connect] :', clientSocket.id)
|
|
289
|
-
callback({ type: 'SET_CONNECTED', data: clientSocket })
|
|
290
|
-
})
|
|
291
|
-
|
|
292
|
-
// 連線錯誤時觸發此事件'connect_error'
|
|
293
|
-
clientSocket.on('connect_error', (error) => {
|
|
294
|
-
// console.log('[socket] [listenToSocketEvents] [connect_error]:', error.message)
|
|
295
|
-
callback({ type: 'CONNECT_ERROR', data: error.message })
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
// 斷開連線時觸發此事件'disconnect'
|
|
299
|
-
clientSocket.on('disconnect', (data) => {
|
|
300
|
-
// console.log('[socket] [listenToSocketEvents] [disconnect] data:', data)
|
|
301
|
-
callback({ type: 'DISCONNECT', reason: data })
|
|
302
|
-
})
|
|
303
|
-
},
|
|
304
|
-
},
|
|
305
|
-
}
|
|
306
|
-
)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
class SocketTester {
|
|
310
|
-
constructor(url) {
|
|
311
|
-
this.url = url
|
|
312
|
-
this.socket = []
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
async init() {
|
|
316
|
-
const target = await fetch(this.url)
|
|
317
|
-
const { socket } = await target.json()
|
|
318
|
-
this.socket = socket
|
|
319
|
-
console.log(`[socket] this.socket:`, this.socket)
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
async test() {
|
|
323
|
-
try {
|
|
324
|
-
if (this.socket.length === 0) {
|
|
325
|
-
await this.init()
|
|
326
|
-
}
|
|
327
|
-
const { url, index } = await Promise.any(
|
|
328
|
-
this.socket.map((url, i) => {
|
|
329
|
-
return this.ping(url, i)
|
|
330
|
-
})
|
|
331
|
-
)
|
|
332
|
-
console.info(`[Socket] Host ${index} is chosen. (${url})`)
|
|
333
|
-
return url
|
|
334
|
-
} catch (error) {
|
|
335
|
-
console.error('[Socket] Socket Test Fail.', error)
|
|
336
|
-
return serviceUrl
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
async ping(url, index) {
|
|
341
|
-
let ts, response
|
|
342
|
-
try {
|
|
343
|
-
ts = new Date().getTime()
|
|
344
|
-
response = await fetch(`${url}/ping/status`)
|
|
345
|
-
return { url, index }
|
|
346
|
-
} finally {
|
|
347
|
-
const speed = new Date().getTime() - ts
|
|
348
|
-
const status = !!response?.ok ? 'Success' : 'Failure'
|
|
349
|
-
console.info(`[Socket] Host: ${index}, URL: ${url}, Status: ${status}, Speed: ${speed}ms`)
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
}
|