@jetthai/cuora 1.1.488-dev.1 → 1.2.0

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.
Files changed (221) hide show
  1. package/.husky/pre-commit +3 -1
  2. package/.prettierignore +1 -2
  3. package/CHANGELOG.md +0 -746
  4. package/README.md +15 -299
  5. package/package.json +3 -6
  6. package/resetGitBranch.sh +101 -0
  7. package/src/api/activity.js +39 -24
  8. package/src/api/auth.js +35 -4
  9. package/src/api/common.js +1 -8
  10. package/src/api/game.js +10 -0
  11. package/src/api/index.js +1 -3
  12. package/src/api/payment.js +55 -18
  13. package/src/api/user.js +16 -11
  14. package/src/index.js +2 -2
  15. package/src/lib/fingerprint_v3_11_12.js +11433 -0
  16. package/src/machine/activity/activity.js +209 -0
  17. package/src/machine/activity/activity_cash.js +18 -71
  18. package/src/machine/activity/diamond_shop_activity_cash.js +1 -0
  19. package/src/machine/activity/diamond_shop_activity_fc.js +196 -0
  20. package/src/machine/activity/diamond_shop_activity_vn.js +178 -0
  21. package/src/machine/activity/fafafa_activity.js +10 -0
  22. package/src/machine/activity/index.js +12 -0
  23. package/src/machine/activity/invite_friends_activity.js +114 -0
  24. package/src/machine/activity/mini_game_activity.js +68 -0
  25. package/src/machine/activity/return_bonus_activity.js +153 -0
  26. package/src/machine/activity/roulette_activity_v2.js +0 -5
  27. package/src/machine/auth.js +140 -192
  28. package/src/machine/auth_otp_v2.js +177 -0
  29. package/src/machine/auth_otp_v3.js +32 -111
  30. package/src/machine/bank_binding.js +2 -2
  31. package/src/machine/bank_binding_amb.js +145 -0
  32. package/src/machine/bonus.js +75 -0
  33. package/src/machine/common.js +91 -27
  34. package/src/machine/deposit/amb.js +92 -0
  35. package/src/machine/deposit/crypto_bank.js +325 -0
  36. package/src/machine/deposit/crypto_bank_cash.js +8 -19
  37. package/src/machine/deposit/crypto_qrcode.js +148 -0
  38. package/src/machine/deposit/crypto_qrcode_cash.js +41 -26
  39. package/src/machine/deposit/crypto_way.js +247 -0
  40. package/src/machine/deposit/crypto_way_cash.js +32 -52
  41. package/src/machine/deposit/deposit_fc.js +271 -0
  42. package/src/machine/deposit/direct.js +310 -0
  43. package/src/machine/deposit/direct_cash.js +9 -8
  44. package/src/machine/deposit/float.js +374 -0
  45. package/src/machine/deposit/index.js +28 -0
  46. package/src/machine/deposit/krway.js +151 -0
  47. package/src/machine/deposit/loadcard_cash.js +31 -14
  48. package/src/machine/deposit/loadcard_vn.js +351 -0
  49. package/src/machine/deposit/manual_cash.js +10 -8
  50. package/src/machine/deposit/manual_vn.js +458 -0
  51. package/src/machine/deposit/qrcode_cash.js +30 -14
  52. package/src/machine/deposit/qrcode_v2.js +338 -0
  53. package/src/machine/deposit/usdt.js +144 -0
  54. package/src/machine/deposit/virtual_bank_cash.js +2 -5
  55. package/src/machine/deposit/virtual_bank_vn.js +269 -0
  56. package/src/machine/deposit/vpay.js +367 -0
  57. package/src/machine/error.js +0 -7
  58. package/src/machine/game_hot_new.js +79 -0
  59. package/src/machine/game_info.js +12 -5
  60. package/src/machine/game_replay.js +46 -0
  61. package/src/machine/game_search_v2.js +401 -0
  62. package/src/machine/game_v2_1.js +88 -58
  63. package/src/machine/honor_board.js +132 -0
  64. package/src/machine/honor_board_cash.js +18 -15
  65. package/src/machine/inbox.js +12 -0
  66. package/src/machine/index.js +32 -0
  67. package/src/machine/leaderboard.js +11 -8
  68. package/src/machine/merge.js +57 -0
  69. package/src/machine/payment_data.js +86 -0
  70. package/src/machine/promotions.js +170 -0
  71. package/src/machine/ranking.js +25 -43
  72. package/src/machine/reward.js +255 -0
  73. package/src/machine/reward_cash.js +41 -2
  74. package/src/machine/reward_fc.js +98 -0
  75. package/src/machine/roulette_v2.js +25 -20
  76. package/src/machine/side.js +154 -0
  77. package/src/machine/side_cash.js +2 -3
  78. package/src/machine/side_v2.js +209 -0
  79. package/src/machine/user_reset_password.js +15 -4
  80. package/src/machine/user_sign_up.js +60 -49
  81. package/src/machine/vip_table.js +57 -0
  82. package/src/machine/websocket.js +325 -378
  83. package/src/machine/welcome.js +110 -0
  84. package/src/machine/withdraw/index.js +6 -0
  85. package/src/machine/withdraw/withdraw_crypto_cash.js +327 -0
  86. package/src/machine/withdraw/withdraw_krway.js +222 -0
  87. package/src/machine/withdraw/withdraw_manual.js +533 -0
  88. package/src/machine/withdraw/withdraw_manual_cash.js +43 -74
  89. package/src/request/config.js +0 -2
  90. package/src/request/request.js +64 -231
  91. package/src/util/constant.js +2 -12
  92. package/src/util/deviceToken.js +59 -0
  93. package/src/util/index.js +4 -2
  94. package/src/util/math.js +4 -0
  95. package/.claude/commands/sync-ai-prompts.md +0 -180
  96. package/.claude/settings.local.json +0 -25
  97. package/.github/copilot-instructions.md +0 -459
  98. package/.husky/post-checkout +0 -32
  99. package/.husky/pre-push +0 -36
  100. package/AGENTS.md +0 -459
  101. package/AI_PROMPT_SOURCE.md +0 -457
  102. package/CLAUDE.md +0 -459
  103. package/GEMINI.md +0 -459
  104. package/docs/kibana/crypto-way-deposit-amount-bug-analysis.md +0 -1003
  105. package/docs/kibana/play-providerId-error.md +0 -202
  106. package/docs/kibana/play-selectedWalletType.md +0 -1
  107. package/docs/kibana/play-selectedWalletType_2.md +0 -1
  108. package/docs/kibana/play-selectedWalletType_analysis.md +0 -565
  109. package/docs/my-claude/feat-sharon-JT-1790247240-socket/branch-transfer.md +0 -14
  110. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-preparation.json +0 -40
  111. package/docs/my-claude/feat-sharon-JT-1790247240-socket/cash-module-verification.md +0 -41
  112. package/docs/my-claude/feat-sharon-JT-1790247240-socket/implementation-ledger.md +0 -87
  113. package/docs/my-claude/feat-sharon-JT-1790247240-socket/module-report.md +0 -73
  114. package/docs/my-claude/feat-sharon-JT-1790247240-socket/plan.md +0 -309
  115. package/docs/my-claude/feat-sharon-JT-1790247240-socket/test-cases.md +0 -245
  116. package/docs/my-claude/feat-sharon-JT-1791180540-onesignal/transfer.md +0 -9
  117. package/e2e/feature-map.md +0 -19
  118. package/prepare-for-pr/JT-1776243420.md +0 -85
  119. package/prepare-for-pr/TI-16026/STATE.md +0 -18
  120. package/prepare-for-pr/TI-16026/after-prepare-authorization.md +0 -3
  121. package/prepare-for-pr/TI-16026/analysis.md +0 -38
  122. package/prepare-for-pr/TI-16026/answer-analyze-01.md +0 -1
  123. package/prepare-for-pr/TI-16026/answer-commit-01.md +0 -2
  124. package/prepare-for-pr/TI-16026/answer-commit-02.md +0 -1
  125. package/prepare-for-pr/TI-16026/bundle.json +0 -18
  126. package/prepare-for-pr/TI-16026/checklist.md +0 -196
  127. package/prepare-for-pr/TI-16026/checklist.unit-test-original.md +0 -39
  128. package/prepare-for-pr/TI-16026/claude-after-model +0 -1
  129. package/prepare-for-pr/TI-16026/claude-commit-session +0 -1
  130. package/prepare-for-pr/TI-16026/claude-harvest-session +0 -1
  131. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.err +0 -1
  132. package/prepare-for-pr/TI-16026/claude-hops/01-analyze.out +0 -2
  133. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.err +0 -1
  134. package/prepare-for-pr/TI-16026/claude-hops/02-analyze.out +0 -4
  135. package/prepare-for-pr/TI-16026/claude-hops/03-dev.err +0 -1
  136. package/prepare-for-pr/TI-16026/claude-hops/03-dev.out +0 -4
  137. package/prepare-for-pr/TI-16026/claude-hops/04-dev.err +0 -1
  138. package/prepare-for-pr/TI-16026/claude-hops/04-dev.out +0 -4
  139. package/prepare-for-pr/TI-16026/claude-hops/05-dev.err +0 -1
  140. package/prepare-for-pr/TI-16026/claude-hops/05-dev.out +0 -3
  141. package/prepare-for-pr/TI-16026/claude-hops/06-after.err +0 -1
  142. package/prepare-for-pr/TI-16026/claude-hops/06-after.out +0 -2
  143. package/prepare-for-pr/TI-16026/claude-hops/07-commit.err +0 -1
  144. package/prepare-for-pr/TI-16026/claude-hops/07-commit.out +0 -2
  145. package/prepare-for-pr/TI-16026/claude-hops/08-commit.err +0 -1
  146. package/prepare-for-pr/TI-16026/claude-hops/08-commit.out +0 -2
  147. package/prepare-for-pr/TI-16026/claude-hops/09-commit.err +0 -1
  148. package/prepare-for-pr/TI-16026/claude-hops/09-commit.out +0 -8
  149. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.err +0 -1
  150. package/prepare-for-pr/TI-16026/claude-hops/10-harvest.out +0 -3
  151. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.err +0 -1
  152. package/prepare-for-pr/TI-16026/claude-hops/11-harvest.out +0 -3
  153. package/prepare-for-pr/TI-16026/commit-note.md +0 -5
  154. package/prepare-for-pr/TI-16026/evidence-index.json +0 -215
  155. package/prepare-for-pr/TI-16026/feature-map.before.md +0 -61
  156. package/prepare-for-pr/TI-16026/harvest-redaction.json +0 -34
  157. package/prepare-for-pr/TI-16026/harvest-redaction.out +0 -37
  158. package/prepare-for-pr/TI-16026/harvest.md +0 -46
  159. package/prepare-for-pr/TI-16026/lessons.md +0 -5
  160. package/prepare-for-pr/TI-16026/note-harvest-redaction.md +0 -1
  161. package/prepare-for-pr/TI-16026/open-questions.md +0 -6
  162. package/prepare-for-pr/TI-16026/publish.md +0 -32
  163. package/prepare-for-pr/TI-16026/review-convergence-response.md +0 -3
  164. package/prepare-for-pr/TI-16026/review-input/scope.md +0 -18
  165. package/prepare-for-pr/TI-16026/review-log.md +0 -57
  166. package/prepare-for-pr/TI-16026/review-notes.md +0 -97
  167. package/prepare-for-pr/TI-16026/review-response-r1.md +0 -7
  168. package/prepare-for-pr/TI-16026/self-test-report.md +0 -67
  169. package/prepare-for-pr/TI-16026/spec-proposal.md +0 -34
  170. package/prepare-for-pr/TI-16026/spec-snapshot.md +0 -291
  171. package/prepare-for-pr/TI-16026/state-log.md +0 -57
  172. package/prepare-for-pr/TI-16026/user-messages/01.md +0 -12
  173. package/prepare-for-pr/TI-16026/user-messages/02.md +0 -20
  174. package/prepare-for-pr/TI-16026/user-messages/03.md +0 -1
  175. package/prepare-for-pr/TI-16026/user-messages/04.md +0 -1
  176. package/prepare-for-pr/TI-16026/user-messages/05.md +0 -1
  177. package/prepare-for-pr/TI-16026/user-messages/06.md +0 -1
  178. package/prepare-for-pr/TI-16026/user-messages/07.md +0 -1
  179. package/prepare-for-pr/TI-16026/user-messages/08.md +0 -1
  180. package/prepare-for-pr/TI-16026/user-messages/09.md +0 -1
  181. package/prepare-for-pr/TI-16026/user-messages/10.md +0 -1
  182. package/prepare-for-pr/TI-16026/user-messages/11.md +0 -1
  183. package/prepare-for-pr/TI-16026/user-messages/12.md +0 -1
  184. package/prepare-for-pr/TI-16026/user-messages/13.md +0 -1
  185. package/prepare-for-pr/TI-16026/user-messages/14.md +0 -1
  186. package/prepare-for-pr/TI-16026/user-messages/15.md +0 -1
  187. package/prepare-for-pr/TI-16026/user-messages/16.md +0 -1
  188. package/prepare-for-pr/TI-16026/user-messages/17.md +0 -1
  189. package/prepare-for-pr/TI-16026/user-messages/18.md +0 -10
  190. package/prepare-for-pr/TI-16026/user-messages/19.md +0 -1
  191. package/prepare-for-pr/TI-16026/user-messages/20.md +0 -1
  192. package/prepare-for-pr/TI-16026/user-messages/21.md +0 -1
  193. package/prepare-for-pr/TI-16026/user-messages/22.md +0 -1
  194. package/prepare-for-pr/TI-16026/user-messages/23.md +0 -8
  195. package/prepare-for-pr/TI-16026/user-messages/24.md +0 -24
  196. package/prepare-for-pr/TI-16026/user-question.md +0 -24
  197. package/prepare-for-pr/TI-16026/verify/metrics-check.json +0 -13
  198. package/prepare-for-pr/TI-16026/verify/redaction.json +0 -38
  199. package/prepare-for-pr/TI-16026/verify/row-closure.json +0 -45
  200. package/prepare-for-pr/TI-16026/verify/s04-ws-capture.md +0 -23
  201. package/prepare-for-pr/TI-16026/verify-after.md +0 -23
  202. package/prepare-for-pr/TI-16026/verify.json +0 -80
  203. package/prepare-for-pr/TI-16026.md +0 -408
  204. package/scripts/auto-version.js +0 -69
  205. package/scripts/auto-version.sh +0 -33
  206. package/scripts/branch-auto-npm-publish.js +0 -36
  207. package/scripts/check-version.sh +0 -36
  208. package/scripts/clean-tags.sh +0 -84
  209. package/src/api/account.js +0 -7
  210. package/src/api/otp.js +0 -5
  211. package/src/util/amount.js +0 -8
  212. package/src/util/err998SentryExtra.js +0 -26
  213. package/src/util/paramStore.js +0 -139
  214. package/src/util/socketPolicy.js +0 -57
  215. package/src/util/tokenStore.js +0 -44
  216. package/test/auth_otp_v3.test.js +0 -323
  217. package/test/auth_self_timeout.test.js +0 -171
  218. package/test/request_self.test.js +0 -288
  219. package/test/withdraw_manual_cash.test.js +0 -149
  220. package/tests/session.test.mjs +0 -177
  221. package/tests/websocket.test.mjs +0 -779
@@ -0,0 +1,110 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../api/payment.js'
3
+ import user from '../api/user.js'
4
+ import storage from '../util/storage.js'
5
+
6
+ export default function (request) {
7
+ return createMachine(
8
+ {
9
+ id: 'welcome',
10
+ initial: 'loading',
11
+ context: {
12
+ userInfo: null,
13
+ bonus: null,
14
+ gender: null,
15
+ },
16
+ states: {
17
+ loading: {
18
+ invoke: {
19
+ src: 'fetchUserInfo',
20
+ onDone: {
21
+ target: 'checking',
22
+ actions: 'setUserInfo',
23
+ },
24
+ onError: {
25
+ target: 'checking',
26
+ },
27
+ },
28
+ },
29
+ checking: {
30
+ always: [{ target: 'firstLogin', cond: 'isFirstLogin' }, { target: 'completed' }],
31
+ },
32
+ firstLogin: {
33
+ initial: 'input',
34
+ states: {
35
+ input: {
36
+ on: {
37
+ SET_BONUS: {
38
+ actions: 'setBonus',
39
+ },
40
+ SET_GENDER: {
41
+ actions: 'setGender',
42
+ },
43
+ SEND_INFO: {
44
+ target: 'submitting',
45
+ cond: 'isFilled',
46
+ },
47
+ },
48
+ },
49
+ submitting: {
50
+ invoke: {
51
+ src: 'updatingInfo',
52
+ onDone: {
53
+ target: '#welcome.completed',
54
+ },
55
+ onError: {
56
+ target: '#welcome.completed',
57
+ },
58
+ },
59
+ exit: 'setInfo',
60
+ },
61
+ },
62
+ },
63
+ completed: {},
64
+ },
65
+ },
66
+ {
67
+ guards: {
68
+ isFirstLogin: (context, event) => {
69
+ const { bank_account, bank_setting_status, topup, verification_status, uid } = context.userInfo || {}
70
+ // const hasBankAccount = bank_account || bank_setting_status === 1 // sabai
71
+ const isComplete = topup === 1 || verification_status === 1
72
+ const isSent = storage.get(`welcome_${uid}`)
73
+ return !(isSent || isComplete)
74
+ },
75
+ isFilled: (context, event) => {
76
+ const { bonus, gender } = context
77
+ return bonus !== null && gender !== null
78
+ },
79
+ },
80
+ actions: {
81
+ setUserInfo: assign((context, event) => {
82
+ return {
83
+ userInfo: event.data,
84
+ }
85
+ }),
86
+ setInfo: (context, event) => {
87
+ storage.set(`welcome_${context.userInfo.uid}`, 'done', {
88
+ path: '/',
89
+ maxAge: 60 * 60 * 24 * 365,
90
+ })
91
+ },
92
+ setBonus: assign((context, event) => {
93
+ return { bonus: event.data }
94
+ }),
95
+ setGender: assign((context, event) => {
96
+ return { gender: event.data }
97
+ }),
98
+ },
99
+ services: {
100
+ fetchUserInfo: async (context, event) => {
101
+ return await request.send(user.getUserInfo())
102
+ },
103
+ updatingInfo: async (context, event) => {
104
+ const { bonus, gender } = context
105
+ await Promise.all([request.send(payment.setBonusSetting({ bonus })), request.send(user.updateUserInfo({ gender }))])
106
+ },
107
+ },
108
+ }
109
+ )
110
+ }
@@ -1,5 +1,11 @@
1
+ import withdraw_manual from './withdraw_manual.js'
2
+ import withdraw_krway from './withdraw_krway.js'
3
+ import withdraw_crypto_cash from './withdraw_crypto_cash.js'
1
4
  import withdraw_manual_cash from './withdraw_manual_cash.js'
2
5
 
3
6
  export default {
7
+ withdraw_manual,
8
+ withdraw_krway,
9
+ withdraw_crypto_cash,
4
10
  withdraw_manual_cash,
5
11
  }
@@ -0,0 +1,327 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import payment from '../../api/payment.js'
3
+ import user from '../../api/user.js'
4
+ import api from '../../api/payment.js'
5
+
6
+ export default function (request, context) {
7
+ const { paymentDetail = [] } = context || {}
8
+ return createMachine(
9
+ {
10
+ id: 'withdraw_crypto_cash',
11
+ initial: 'loading',
12
+ context: {
13
+ paymentDetail,
14
+ withdrawRule: null,
15
+ selectedCrypto: null,
16
+ networks: [],
17
+ selectedNetwork: null,
18
+ address: '',
19
+ selectedAmount: null,
20
+ calculation: null,
21
+ processing: null,
22
+
23
+ // otp
24
+ requestId: null,
25
+ status: null,
26
+ target: null,
27
+ ttl: null,
28
+ },
29
+ states: {
30
+ loading: {
31
+ invoke: {
32
+ src: 'fetchInitData',
33
+ onDone: {
34
+ target: 'checking',
35
+ actions: 'setInitData',
36
+ },
37
+ onError: {
38
+ target: 'loaded',
39
+ },
40
+ },
41
+ },
42
+ checking: {
43
+ always: [{ target: 'submitted', cond: 'isProcessing' }, { target: 'loaded' }],
44
+ },
45
+ loaded: {},
46
+ debouncing: {
47
+ after: {
48
+ 1000: [
49
+ {
50
+ target: 'calculating',
51
+ cond: 'isCalculable',
52
+ },
53
+ { target: 'loaded' },
54
+ ],
55
+ },
56
+ },
57
+ calculating: {
58
+ entry: 'resetCharge',
59
+ invoke: {
60
+ src: 'fetchCalculation',
61
+ onDone: {
62
+ target: 'calculated',
63
+ actions: 'setCalculation',
64
+ },
65
+ onError: {
66
+ target: 'calculated',
67
+ },
68
+ },
69
+ },
70
+ calculated: {
71
+ on: {
72
+ SUBMIT: [
73
+ {
74
+ target: 'submitting',
75
+ },
76
+ ],
77
+ },
78
+ },
79
+ submitting: {
80
+ invoke: {
81
+ src: 'submitWithdraw',
82
+ onDone: [
83
+ {
84
+ target: 'otp',
85
+ actions: 'setOtp',
86
+ cond: 'isOtpRequired',
87
+ },
88
+ {
89
+ target: 'submitted',
90
+ actions: 'setProcessing',
91
+ },
92
+ ],
93
+ onError: {
94
+ target: 'loaded',
95
+ },
96
+ },
97
+ },
98
+ submitted: {},
99
+ otp: {
100
+ type: 'parallel',
101
+ states: {
102
+ countdown: {
103
+ after: {
104
+ 1000: {
105
+ target: 'countdown',
106
+ actions: 'decreaseTtl',
107
+ cond: (context) => context.ttl > 0,
108
+ },
109
+ },
110
+ },
111
+ verification: {
112
+ initial: 'idle',
113
+ states: {
114
+ idle: {
115
+ on: {
116
+ ACKNOWLEDGE: {
117
+ target: 'acknowledging',
118
+ },
119
+ RESET_OTP: {
120
+ target: 'reset',
121
+ },
122
+ },
123
+ },
124
+ acknowledging: {
125
+ invoke: {
126
+ src: 'acknowledge',
127
+ onDone: [
128
+ {
129
+ target: '#withdraw_crypto_cash.submitted',
130
+ },
131
+ ],
132
+ onError: {
133
+ target: 'idle',
134
+ },
135
+ },
136
+ },
137
+ reset: {
138
+ invoke: {
139
+ src: 'resetOtp',
140
+ onDone: {
141
+ target: 'idle',
142
+ actions: 'setVerificationData',
143
+ },
144
+ onError: { target: 'idle' },
145
+ },
146
+ },
147
+ },
148
+ },
149
+ },
150
+ },
151
+ },
152
+ on: {
153
+ SET_NETWORK: {
154
+ target: 'debouncing',
155
+ actions: 'setNetwork',
156
+ internal: false,
157
+ },
158
+ SET_ADDRESS: {
159
+ actions: 'setAddress',
160
+ internal: false,
161
+ },
162
+ SET_AMOUNT: {
163
+ target: 'debouncing',
164
+ actions: 'setAmount',
165
+ internal: false,
166
+ },
167
+ },
168
+ },
169
+ {
170
+ actions: {
171
+ setInitData: assign((context, event) => {
172
+ const { withdrawRule, processing } = event.data
173
+ const { paymentDetail } = context
174
+ const selectedCrypto = paymentDetail.find((item) => item.transferType === 'withdraw' && item.category === 'crypto')
175
+ const networks = (selectedCrypto?.networkName || []).map((value, i) => {
176
+ return {
177
+ label: selectedCrypto.networkOptional?.[i],
178
+ value,
179
+ icon: value,
180
+ }
181
+ })
182
+
183
+ return {
184
+ withdrawRule,
185
+ selectedCrypto,
186
+ networks,
187
+ selectedNetwork: networks[0],
188
+ processing,
189
+ }
190
+ }),
191
+ setNetwork: assign((context, event) => {
192
+ return {
193
+ selectedNetwork: event.data,
194
+ }
195
+ }),
196
+ setAddress: assign((context, event) => {
197
+ return {
198
+ address: event.data,
199
+ }
200
+ }),
201
+ setAmount: assign((context, event) => {
202
+ return {
203
+ selectedAmount: event.data,
204
+ }
205
+ }),
206
+ setCalculation: assign((context, event) => {
207
+ // V2接口轉換中回傳的資料結構不同
208
+ const { data } = event.data
209
+ if (data) {
210
+ return {
211
+ calculation: data,
212
+ }
213
+ } else {
214
+ return {
215
+ calculation: event.data,
216
+ }
217
+ }
218
+ }),
219
+ resetCharge: assign((context, event) => {
220
+ return {
221
+ charge: null,
222
+ }
223
+ }),
224
+ setTransaction: assign((context, event) => {
225
+ const { realAmount } = event.data
226
+ return {
227
+ realAmount,
228
+ }
229
+ }),
230
+ setOtp: assign((context, event) => {
231
+ const { requestId, status, target, ttl } = event.data
232
+ return {
233
+ requestId,
234
+ status,
235
+ target,
236
+ ttl,
237
+ }
238
+ }),
239
+ decreaseTtl: assign((context, evnet) => {
240
+ const second = context.ttl
241
+ return {
242
+ ttl: Math.max(second - 1, 0),
243
+ }
244
+ }),
245
+ setVerificationData: assign((context, event) => {
246
+ const { requestId, ttl, target } = event.data
247
+ return {
248
+ requestId,
249
+ ttl,
250
+ target,
251
+ }
252
+ }),
253
+ setAttachmentType: assign((context, event) => {
254
+ return {
255
+ attachmentType: event.data,
256
+ }
257
+ }),
258
+ setProcessing: assign((context, event) => {
259
+ return {
260
+ processing: event.data,
261
+ }
262
+ }),
263
+ },
264
+ guards: {
265
+ isProcessing: (context, event) => {
266
+ return context.processing
267
+ },
268
+ isCalculable: (context, event) => {
269
+ const { withdrawRule, selectedCrypto, selectedNetwork, selectedAmount } = context
270
+ const maximum = Math.min(withdrawRule.balance, selectedCrypto.maximum)
271
+ return selectedNetwork && selectedAmount && selectedCrypto.minimum <= selectedAmount && selectedAmount <= maximum
272
+ },
273
+ isOtpRequired: (context, event) => {
274
+ return event.data?.status === 'otp-verifying'
275
+ },
276
+ },
277
+ services: {
278
+ fetchInitData: async (context, event) => {
279
+ const [withdrawRule, orders] = await Promise.all([
280
+ request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' })),
281
+ request.send(payment.getPendingOrder({ transferType: 'WITHDRAW' })),
282
+ ])
283
+
284
+ return {
285
+ withdrawRule,
286
+ processing: orders[0],
287
+ }
288
+ },
289
+ fetchWithdrawRule: async (context, event) => {
290
+ return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' }))
291
+ },
292
+ submitWithdraw: async (context, event) => {
293
+ const { selectedCrypto, selectedNetwork, address, selectedAmount } = context
294
+ return await request.send(
295
+ api.submitWithdrawTransactionCrypto({
296
+ method: selectedCrypto.method,
297
+ amount: selectedAmount,
298
+ cryptoCurrency: selectedCrypto.channel,
299
+ cryptoNetwork: selectedNetwork.value,
300
+ targetAddress: address,
301
+ })
302
+ )
303
+ },
304
+ fetchCalculation: async (context, event) => {
305
+ const { selectedCrypto, selectedNetwork, selectedAmount } = context
306
+ const method = selectedCrypto.method
307
+ return await request.send(
308
+ api.getWithdrawExpectedResult({
309
+ method,
310
+ amount: selectedAmount,
311
+ cryptoNetwork: selectedNetwork.value,
312
+ })
313
+ )
314
+ },
315
+ resetOtp: async (context, event) => {
316
+ const { requestId, target } = context
317
+ return await request.send(user.otpReset({ requestId, target }))
318
+ },
319
+ acknowledge: async (context, event) => {
320
+ const { requestId, target } = context
321
+ const code = event.data
322
+ return await request.send(user.otpAcknowledge({ requestId, target, code }))
323
+ },
324
+ },
325
+ }
326
+ )
327
+ }
@@ -0,0 +1,222 @@
1
+ import { assign, createMachine } from 'xstate'
2
+ import findLastIndex from 'lodash/findLastIndex.js'
3
+ import payment from '../../api/payment.js'
4
+ import user from '../../api/user.js'
5
+
6
+ export default function (request) {
7
+ const { appSecret } = request.config
8
+ return createMachine(
9
+ {
10
+ id: 'withdraw_krway',
11
+ initial: 'loading',
12
+ context: {
13
+ userInfo: {},
14
+ paymentDetail: {},
15
+ minimum: 0,
16
+ maximum: 0,
17
+ options: [],
18
+ amount: 0,
19
+ bankInfo: [],
20
+ bank: null,
21
+ enableWithdraw: false,
22
+ applyId: '',
23
+ balance: 0,
24
+ realAmount: 0,
25
+ charge: 0,
26
+ withdrawCheck: null,
27
+ },
28
+ states: {
29
+ loading: {
30
+ invoke: {
31
+ src: 'fetchPaymentDetail',
32
+ onDone: {
33
+ target: 'fetching',
34
+ actions: 'setPaymentData',
35
+ },
36
+ onError: {
37
+ target: 'fail',
38
+ },
39
+ },
40
+ },
41
+ fetching: {
42
+ invoke: {
43
+ src: 'fetchWithdrawRules',
44
+ onDone: {
45
+ target: 'checking',
46
+ actions: 'updateWithdrawCondition',
47
+ },
48
+ onError: {
49
+ target: 'fail',
50
+ },
51
+ },
52
+ },
53
+ checking: {
54
+ always: [{ target: 'inProcessing', cond: 'haveProcessing' }, { target: 'withdrawCheck' }],
55
+ },
56
+ withdrawCheck: {
57
+ invoke: {
58
+ src: 'withdrawCheck',
59
+ onDone: [
60
+ {
61
+ target: 'checkingWithdrawStatus',
62
+ actions: assign((context, event) => {
63
+ return {
64
+ withdrawCheck: event.data,
65
+ }
66
+ }),
67
+ },
68
+ ],
69
+ onError: {
70
+ target: '#withdraw_krway.fail',
71
+ },
72
+ },
73
+ },
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
+ notWithdrawMinDepositAmount: {},
87
+ passWithdrawCooldownTime: {},
88
+ inProcessing: {},
89
+ withdrawServiceTime: {},
90
+ notWithdrawable: {},
91
+ withdrawable: {
92
+ on: {
93
+ ADD_AMOUNT: {
94
+ actions: 'addAmount',
95
+ },
96
+ SET_AMOUNT: {
97
+ actions: 'setAmount',
98
+ },
99
+ CLEAR_AMOUNT: {
100
+ actions: 'clearAmount',
101
+ },
102
+ SUBMIT: {
103
+ target: 'submitting',
104
+ cond: 'isSubmittable',
105
+ },
106
+ },
107
+ },
108
+ submitting: {
109
+ invoke: {
110
+ src: 'submitWithdraw',
111
+ onDone: {
112
+ target: 'submitted',
113
+ actions: 'setResult',
114
+ },
115
+ onError: {
116
+ target: 'withdrawable',
117
+ },
118
+ },
119
+ },
120
+ submitted: {
121
+ invoke: {
122
+ src: 'fetchPaymentDetail',
123
+ onDone: {
124
+ target: 'inProcessing',
125
+ actions: 'setPaymentData',
126
+ },
127
+ onError: {
128
+ target: 'fail',
129
+ },
130
+ },
131
+ },
132
+ fail: {},
133
+ },
134
+ },
135
+ {
136
+ actions: {
137
+ setPaymentData: assign((context, event) => {
138
+ const { paymentDetail, bankInfo } = event.data
139
+ const { minimum, maximum, optional } = paymentDetail?.[0] || {}
140
+ return { paymentDetail, bank: bankInfo[0], minimum, maximum, options: optional }
141
+ }),
142
+ updateWithdrawCondition: assign((context, event) => {
143
+ const { enableWithdraw, balance } = event.data
144
+ return {
145
+ balance,
146
+ enableWithdraw,
147
+ }
148
+ }),
149
+ addAmount: assign((context, event) => {
150
+ return {
151
+ amount: parseFloat(`${context.amount || 0}`) + parseFloat(`${event.data}`),
152
+ }
153
+ }),
154
+ setAmount: assign((context, event) => {
155
+ return { amount: parseFloat(`${event.data}`) }
156
+ }),
157
+ clearAmount: assign((context, event) => {
158
+ return { amount: null }
159
+ }),
160
+ setResult: assign((context, event) => {
161
+ const { applyId, balance, realAmount, charge } = event.data
162
+ return { applyId, balance, realAmount, charge }
163
+ }),
164
+ },
165
+ guards: {
166
+ haveProcessing: (context, event) => {
167
+ return (context.paymentDetail?.[0]?.processing || []).length > 0
168
+ },
169
+ isSubmittable: (context, event) => {
170
+ const { amount } = context
171
+ return parseFloat(`${amount}`) > 0
172
+ },
173
+ isNotWithdrawable: (context, event) => {
174
+ const { balance, enableWithdraw, paymentDetail } = context
175
+ const minWithdrawAmount = paymentDetail[0]?.minimum || 0
176
+ return !enableWithdraw || balance < minWithdrawAmount
177
+ },
178
+ isNotWithdrawMinDepositAmount: (context, event) => {
179
+ const { withdrawCheck } = context
180
+ return !withdrawCheck?.passDepositeLimit
181
+ },
182
+ isPassWithdrawCooldownTime: (context, event) => {
183
+ const { withdrawCheck } = context
184
+ return !withdrawCheck?.passWithdrawCooldownTime
185
+ },
186
+ isNotWIthdrawServiceTime: (context, event) => {
187
+ const { withdrawCheck } = context
188
+ return !withdrawCheck?.withdrawInServiceTime
189
+ },
190
+ },
191
+ services: {
192
+ fetchPaymentDetail: async (context, event) => {
193
+ const [paymentDetail = [], { bankInfo }] = await Promise.all([
194
+ request.send(payment.getPaymentDetail({ transferType: 'WITHDRAW' })),
195
+ request.send(payment.getPaymentInfo()),
196
+ ])
197
+ return { paymentDetail, bankInfo }
198
+ },
199
+ fetchWithdrawRules: async (context, event) => {
200
+ return await request.send(payment.getDoubleWalletWithdrawRule({ walletType: 'CASH' }))
201
+ },
202
+ submitWithdraw: async (context, event) => {
203
+ const { paymentDetail, amount, bank } = context
204
+ const { method } = paymentDetail[0]
205
+ return await request.send(
206
+ payment.submitWithdrawTransactionVN({
207
+ method,
208
+ amount,
209
+ applyerBankCode: bank.bankCode,
210
+ applyerAccountNumber: bank.accountNumber,
211
+ branch: bank.branch,
212
+ holderName: bank.holderName,
213
+ })
214
+ )
215
+ },
216
+ withdrawCheck: async (context, event) => {
217
+ return await request.send(payment.withdrawCheck())
218
+ },
219
+ },
220
+ }
221
+ )
222
+ }