@n1xyz/wallet-widget 0.0.10 → 0.0.12
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/dist/Logic/transactionManager.d.ts +1 -1
- package/dist/Logic/transactionManager.js +1 -1
- package/dist/Logic/transactionManager.js.map +1 -1
- package/dist/Modal/NordFlow/NordFlow.js +22 -228
- package/dist/Modal/NordFlow/NordFlow.js.map +1 -1
- package/dist/Modal/NordFlow/components/Header.d.ts +10 -0
- package/dist/Modal/NordFlow/components/Header.js +11 -0
- package/dist/Modal/NordFlow/components/Header.js.map +1 -0
- package/dist/Modal/NordFlow/components/TransactionTable.js +4 -7
- package/dist/Modal/NordFlow/components/TransactionTable.js.map +1 -1
- package/dist/Modal/NordFlow/components/index.d.ts +1 -0
- package/dist/Modal/NordFlow/components/index.js +1 -0
- package/dist/Modal/NordFlow/components/index.js.map +1 -1
- package/dist/Modal/NordFlow/constants.js +116 -95
- package/dist/Modal/NordFlow/constants.js.map +1 -1
- package/dist/Modal/NordFlow/context/DepositContext.d.ts +27 -0
- package/dist/Modal/NordFlow/context/DepositContext.js +308 -0
- package/dist/Modal/NordFlow/context/DepositContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/FlowContext.d.ts +23 -0
- package/dist/Modal/NordFlow/context/FlowContext.js +125 -0
- package/dist/Modal/NordFlow/context/FlowContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/NordProvider.d.ts +10 -0
- package/dist/Modal/NordFlow/context/NordProvider.js +14 -0
- package/dist/Modal/NordFlow/context/NordProvider.js.map +1 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.d.ts +20 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.js +214 -0
- package/dist/Modal/NordFlow/context/WalletConnectContext.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/types.d.ts +26 -0
- package/dist/Modal/NordFlow/context/deposit/types.js +2 -0
- package/dist/Modal/NordFlow/context/deposit/types.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.d.ts +7 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js +113 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositAuth.js.map +1 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.d.ts +20 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js +235 -0
- package/dist/Modal/NordFlow/context/deposit/useDepositTransaction.js.map +1 -0
- package/dist/Modal/NordFlow/context/index.d.ts +5 -0
- package/dist/Modal/NordFlow/context/index.js +8 -0
- package/dist/Modal/NordFlow/context/index.js.map +1 -0
- package/dist/Modal/NordFlow/hooks/index.d.ts +3 -5
- package/dist/Modal/NordFlow/hooks/index.js +3 -5
- package/dist/Modal/NordFlow/hooks/index.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js +2 -4
- package/dist/Modal/NordFlow/hooks/useDepositFlow.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useNordInstance.d.ts +0 -6
- package/dist/Modal/NordFlow/hooks/useNordInstance.js +2 -358
- package/dist/Modal/NordFlow/hooks/useNordInstance.js.map +1 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.d.ts +0 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js +0 -1
- package/dist/Modal/NordFlow/hooks/useNordWalletConnect.js.map +1 -1
- package/dist/Modal/NordFlow/screens/00-IdleScreen.d.ts +6 -0
- package/dist/Modal/NordFlow/screens/00-IdleScreen.js +9 -0
- package/dist/Modal/NordFlow/screens/00-IdleScreen.js.map +1 -0
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js +10 -4
- package/dist/Modal/NordFlow/screens/01-ConnectWalletScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.d.ts +1 -5
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.js +9 -12
- package/dist/Modal/NordFlow/screens/02-EvmWalletAuthScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.d.ts +1 -7
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.js +9 -7
- package/dist/Modal/NordFlow/screens/03-ChainSelectionScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.d.ts +1 -13
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js +59 -31
- package/dist/Modal/NordFlow/screens/04-AmountInputScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.js +8 -3
- package/dist/Modal/NordFlow/screens/05-DepositProgressScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.d.ts +1 -8
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.js +15 -4
- package/dist/Modal/NordFlow/screens/06-DepositSuccessScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.d.ts +1 -6
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.js +14 -120
- package/dist/Modal/NordFlow/screens/07-AuthLoadingScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.d.ts +1 -1
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js +9 -4
- package/dist/Modal/NordFlow/screens/08-FinalSuccessScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.d.ts +1 -7
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.js +9 -9
- package/dist/Modal/NordFlow/screens/09-ErrorScreen.js.map +1 -1
- package/dist/Modal/NordFlow/screens/index.d.ts +1 -0
- package/dist/Modal/NordFlow/screens/index.js +1 -0
- package/dist/Modal/NordFlow/screens/index.js.map +1 -1
- package/dist/Modal/NordFlow/types.d.ts +0 -5
- package/dist/Modal/NordFlow/types.js +0 -1
- package/dist/Modal/NordFlow/types.js.map +1 -1
- package/dist/Modal/NordFlow/utils/index.d.ts +0 -1
- package/dist/Modal/NordFlow/utils/index.js +0 -1
- package/dist/Modal/NordFlow/utils/index.js.map +1 -1
- package/dist/Provider/LazyWalletProvider.js +2 -0
- package/dist/Provider/LazyWalletProvider.js.map +1 -1
- package/dist/Provider/N1WalletProvider.js +48 -63
- package/dist/Provider/N1WalletProvider.js.map +1 -1
- package/dist/Provider/WalletErrorBoundary.d.ts +10 -0
- package/dist/Provider/WalletErrorBoundary.js +39 -0
- package/dist/Provider/WalletErrorBoundary.js.map +1 -0
- package/dist/Provider/hooks/useNordUserInitialization.d.ts +20 -0
- package/dist/Provider/hooks/useNordUserInitialization.js +293 -0
- package/dist/Provider/hooks/useNordUserInitialization.js.map +1 -0
- package/dist/Provider/useN1WalletProvider.d.ts +37 -0
- package/dist/Provider/useN1WalletProvider.js +398 -0
- package/dist/Provider/useN1WalletProvider.js.map +1 -0
- package/dist/main.css +1 -1
- package/package.json +1 -1
|
@@ -51,130 +51,151 @@ export var CHAINS = [
|
|
|
51
51
|
* Defines all possible transitions between states and their conditions
|
|
52
52
|
*/
|
|
53
53
|
export var STATE_TRANSITIONS = [
|
|
54
|
-
//
|
|
54
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
55
55
|
{
|
|
56
|
-
from:
|
|
56
|
+
from: [
|
|
57
|
+
FlowState.ERROR,
|
|
58
|
+
FlowState.IDLE,
|
|
59
|
+
],
|
|
57
60
|
to: FlowState.CONNECTING_WALLET,
|
|
58
|
-
condition: function (context) { return !context.walletType; }, // Only if wallet is not connected
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
from: FlowState.CONNECTING_WALLET,
|
|
62
|
-
to: FlowState.ERROR,
|
|
63
|
-
// When wallet connection fails
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
from: FlowState.CONNECTING_WALLET,
|
|
67
|
-
to: FlowState.CHAIN_SELECTION,
|
|
68
|
-
condition: function (context) { return context.walletType === 'solana'; }, // If Solana wallet and no Nord account
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
from: FlowState.CONNECTING_WALLET,
|
|
72
|
-
to: FlowState.AUTH_LOADING,
|
|
73
61
|
condition: function (context) {
|
|
74
|
-
return context.
|
|
75
|
-
|
|
62
|
+
return !context.hasActiveSession
|
|
63
|
+
&& !context.hasNordAccount;
|
|
64
|
+
}
|
|
76
65
|
},
|
|
66
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
77
67
|
{
|
|
78
|
-
from:
|
|
79
|
-
|
|
68
|
+
from: [
|
|
69
|
+
FlowState.ERROR,
|
|
70
|
+
FlowState.IDLE,
|
|
71
|
+
FlowState.CONNECTING_WALLET,
|
|
72
|
+
],
|
|
73
|
+
to: FlowState.ETH_TO_SOL_AUTH,
|
|
80
74
|
condition: function (context) {
|
|
81
|
-
return context.
|
|
82
|
-
context.hasNordAccount
|
|
83
|
-
context.
|
|
84
|
-
}
|
|
75
|
+
return !context.hasActiveSession
|
|
76
|
+
&& !context.hasNordAccount
|
|
77
|
+
&& context.walletType !== 'solana';
|
|
78
|
+
}
|
|
85
79
|
},
|
|
86
|
-
//
|
|
80
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
87
81
|
{
|
|
88
|
-
from:
|
|
82
|
+
from: [
|
|
83
|
+
FlowState.ERROR,
|
|
84
|
+
FlowState.IDLE,
|
|
85
|
+
FlowState.CONNECTING_WALLET,
|
|
86
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
87
|
+
],
|
|
89
88
|
to: FlowState.CHAIN_SELECTION,
|
|
90
|
-
condition: function (context) {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
to: FlowState.AUTH_LOADING,
|
|
95
|
-
condition: function (context) { return context.hasNordAccount && !context.hasActiveSession; },
|
|
96
|
-
// After ETH auth, if has Nord account but no active session
|
|
97
|
-
},
|
|
98
|
-
{
|
|
99
|
-
from: FlowState.ETH_TO_SOL_AUTH,
|
|
100
|
-
to: FlowState.FINAL_SUCCESS,
|
|
101
|
-
condition: function (context) { return context.hasNordAccount && context.hasActiveSession; },
|
|
102
|
-
// After ETH auth, if has Nord account and active session
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
from: FlowState.ETH_TO_SOL_AUTH,
|
|
106
|
-
to: FlowState.ERROR,
|
|
107
|
-
// If ETH to SOL auth fails
|
|
89
|
+
condition: function (context) {
|
|
90
|
+
return !context.hasActiveSession
|
|
91
|
+
&& !context.hasNordAccount;
|
|
92
|
+
}
|
|
108
93
|
},
|
|
109
|
-
//
|
|
94
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
110
95
|
{
|
|
111
|
-
from:
|
|
96
|
+
from: [
|
|
97
|
+
FlowState.ERROR,
|
|
98
|
+
FlowState.IDLE,
|
|
99
|
+
FlowState.CONNECTING_WALLET,
|
|
100
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
101
|
+
FlowState.CHAIN_SELECTION,
|
|
102
|
+
FlowState.AMOUNT_INPUT,
|
|
103
|
+
],
|
|
112
104
|
to: FlowState.AMOUNT_INPUT,
|
|
113
|
-
|
|
105
|
+
condition: function (context) {
|
|
106
|
+
return !context.hasActiveSession
|
|
107
|
+
&& !context.hasNordAccount;
|
|
108
|
+
}
|
|
114
109
|
},
|
|
115
|
-
//
|
|
110
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
116
111
|
{
|
|
117
|
-
from:
|
|
112
|
+
from: [
|
|
113
|
+
FlowState.ERROR,
|
|
114
|
+
FlowState.IDLE,
|
|
115
|
+
FlowState.CONNECTING_WALLET,
|
|
116
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
117
|
+
FlowState.CHAIN_SELECTION,
|
|
118
|
+
FlowState.AMOUNT_INPUT,
|
|
119
|
+
],
|
|
118
120
|
to: FlowState.DEPOSIT_PROGRESS,
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
to: FlowState.CHAIN_SELECTION,
|
|
124
|
-
// If user goes back to chain selection
|
|
121
|
+
condition: function (context) {
|
|
122
|
+
return !context.hasActiveSession
|
|
123
|
+
&& !context.hasNordAccount;
|
|
124
|
+
}
|
|
125
125
|
},
|
|
126
|
-
//
|
|
126
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
127
127
|
{
|
|
128
|
-
from:
|
|
128
|
+
from: [
|
|
129
|
+
FlowState.ERROR,
|
|
130
|
+
FlowState.IDLE,
|
|
131
|
+
FlowState.CONNECTING_WALLET,
|
|
132
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
133
|
+
FlowState.CHAIN_SELECTION,
|
|
134
|
+
FlowState.AMOUNT_INPUT,
|
|
135
|
+
FlowState.DEPOSIT_PROGRESS,
|
|
136
|
+
],
|
|
129
137
|
to: FlowState.DEPOSIT_SUCCESS,
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
to: FlowState.ERROR,
|
|
135
|
-
// When deposit fails
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
from: FlowState.DEPOSIT_PROGRESS,
|
|
139
|
-
to: FlowState.AMOUNT_INPUT,
|
|
140
|
-
// When deposit fails but we want to allow retry
|
|
138
|
+
condition: function (context) {
|
|
139
|
+
return !context.hasActiveSession
|
|
140
|
+
&& context.hasNordAccount;
|
|
141
|
+
}
|
|
141
142
|
},
|
|
142
|
-
//
|
|
143
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
143
144
|
{
|
|
144
|
-
from:
|
|
145
|
+
from: [
|
|
146
|
+
FlowState.IDLE,
|
|
147
|
+
FlowState.CONNECTING_WALLET,
|
|
148
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
149
|
+
FlowState.CHAIN_SELECTION,
|
|
150
|
+
FlowState.AMOUNT_INPUT,
|
|
151
|
+
FlowState.DEPOSIT_PROGRESS,
|
|
152
|
+
FlowState.DEPOSIT_SUCCESS,
|
|
153
|
+
FlowState.ERROR,
|
|
154
|
+
],
|
|
145
155
|
to: FlowState.AUTH_LOADING,
|
|
146
|
-
condition: function (context) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
to: FlowState.FINAL_SUCCESS,
|
|
151
|
-
condition: function (context) { return context.hasActiveSession; }, // If active Nord session exists
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
from: FlowState.AUTH_LOADING,
|
|
155
|
-
to: FlowState.ERROR,
|
|
156
|
-
// When Nord auth fails to start
|
|
156
|
+
condition: function (context) {
|
|
157
|
+
return !context.hasActiveSession
|
|
158
|
+
&& context.hasNordAccount;
|
|
159
|
+
}
|
|
157
160
|
},
|
|
158
|
-
//
|
|
161
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
159
162
|
{
|
|
160
|
-
from:
|
|
163
|
+
from: [
|
|
164
|
+
FlowState.IDLE,
|
|
165
|
+
FlowState.CONNECTING_WALLET,
|
|
166
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
167
|
+
FlowState.CHAIN_SELECTION,
|
|
168
|
+
FlowState.AMOUNT_INPUT,
|
|
169
|
+
FlowState.DEPOSIT_PROGRESS,
|
|
170
|
+
FlowState.DEPOSIT_SUCCESS,
|
|
171
|
+
FlowState.AUTH_LOADING,
|
|
172
|
+
FlowState.ERROR,
|
|
173
|
+
],
|
|
161
174
|
to: FlowState.FINAL_SUCCESS,
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
to: FlowState.ERROR,
|
|
167
|
-
// When auth fails
|
|
175
|
+
condition: function (context) {
|
|
176
|
+
return context.hasActiveSession
|
|
177
|
+
&& context.hasNordAccount;
|
|
178
|
+
}
|
|
168
179
|
},
|
|
169
|
-
//
|
|
180
|
+
// Global recovery transition (can happen from any state upon recovery)
|
|
170
181
|
{
|
|
171
|
-
from:
|
|
182
|
+
from: [
|
|
183
|
+
FlowState.CONNECTING_WALLET,
|
|
184
|
+
FlowState.ETH_TO_SOL_AUTH,
|
|
185
|
+
FlowState.CHAIN_SELECTION,
|
|
186
|
+
FlowState.AMOUNT_INPUT,
|
|
187
|
+
FlowState.DEPOSIT_PROGRESS,
|
|
188
|
+
FlowState.DEPOSIT_SUCCESS,
|
|
189
|
+
FlowState.AUTH_LOADING,
|
|
190
|
+
FlowState.FINAL_SUCCESS,
|
|
191
|
+
FlowState.ERROR,
|
|
192
|
+
],
|
|
172
193
|
to: FlowState.IDLE,
|
|
173
|
-
// When restarting after error
|
|
174
194
|
},
|
|
175
195
|
// Global recovery transition (can happen from any state upon recovery)
|
|
176
196
|
{
|
|
177
197
|
from: [
|
|
198
|
+
FlowState.IDLE,
|
|
178
199
|
FlowState.CONNECTING_WALLET,
|
|
179
200
|
FlowState.ETH_TO_SOL_AUTH,
|
|
180
201
|
FlowState.CHAIN_SELECTION,
|
|
@@ -182,9 +203,9 @@ export var STATE_TRANSITIONS = [
|
|
|
182
203
|
FlowState.DEPOSIT_PROGRESS,
|
|
183
204
|
FlowState.DEPOSIT_SUCCESS,
|
|
184
205
|
FlowState.AUTH_LOADING,
|
|
206
|
+
FlowState.FINAL_SUCCESS,
|
|
185
207
|
],
|
|
186
|
-
to: FlowState.
|
|
187
|
-
// For recovery after interruption
|
|
208
|
+
to: FlowState.ERROR,
|
|
188
209
|
},
|
|
189
210
|
];
|
|
190
211
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/Modal/NordFlow/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAmB,MAAM,SAAS,CAAC;AAErD,MAAM,CAAC,IAAM,cAAc,GAAG,+BAA+B,CAAC;AAC9D,MAAM,CAAC,IAAM,eAAe,GAAG,EAAE,CAAC;AAClC,MAAM,CAAC,IAAM,kBAAkB,GAAG,IAAI,CAAC;AAEvC,MAAM,CAAC,IAAM,WAAW,GAAG,KAAK,CAAC;AACjC,MAAM,CAAC,IAAM,WAAW,GAAG,KA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OAAO,CAAC,gBAAgB;mBACrB,OAAO,CAAC,cAAc;QADzB,CACyB;KAC5B;IACD,uEAAuE;IACvE;QACE,IAAI,EAAE;YACJ,SAAS,CAAC,iBAAiB;YAC3B,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,YAAY;YACtB,SAAS,CAAC,gBAAgB;YAC1B,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,YAAY;YACtB,SAAS,CAAC,aAAa;YACvB,SAAS,CAAC,KAAK;SAChB;QACD,EAAE,EAAE,SAAS,CAAC,IAAI;KACnB;IAED,uEAAuE;IACvE;QACE,IAAI,EAAE;YACJ,SAAS,CAAC,IAAI;YACd,SAAS,CAAC,iBAAiB;YAC3B,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,YAAY;YACtB,SAAS,CAAC,gBAAgB;YAC1B,SAAS,CAAC,eAAe;YACzB,SAAS,CAAC,YAAY;YACtB,SAAS,CAAC,aAAa;SACxB;QACD,EAAE,EAAE,SAAS,CAAC,KAAK;KACpB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,IAAM,sBAAsB,GAAG,iCAAiC,CAAC;AAExE;;GAEG;AACH,MAAM,CAAC,IAAM,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,aAAa","sourcesContent":["import { FlowState, StateTransition } from './types';\n\nexport const ANIMATION_EASE = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const TYPING_INTERVAL = 50;\nexport const ANIMATION_DURATION = 3000;\n\nexport const MIN_DEPOSIT = 10000;\nexport const MAX_DEPOSIT = 10000;\n\nexport const INITIAL_APPS = Array.from({ length: 20 }, (_, i) => ({\n name: `App${i + 1}`,\n color: '#ff2b1f',\n progress: 0,\n}));\n\n/**\n * Available chains for deposit\n */\nexport const AVAILABLE_CHAINS = [\n {\n id: 'ethereum',\n name: 'Ethereum',\n logo: 'ethereum-logo.svg',\n },\n {\n id: 'solana',\n name: 'Solana',\n logo: 'solana-logo.svg',\n },\n];\n\nexport const CHAINS = [\n {\n id: 'ethereum',\n name: 'Ethereum',\n logo: '/images/chains/ethereum.svg',\n },\n {\n id: 'polygon',\n name: 'Polygon',\n logo: '/images/chains/polygon.svg',\n },\n {\n id: 'arbitrum',\n name: 'Arbitrum',\n logo: '/images/chains/arbitrum.svg',\n },\n {\n id: 'optimism',\n name: 'Optimism',\n logo: '/images/chains/optimism.svg',\n },\n];\n\n/**\n * State machine transitions\n * Defines all possible transitions between states and their conditions\n */\nexport const STATE_TRANSITIONS: StateTransition[] = [\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n ],\n to: FlowState.CONNECTING_WALLET,\n condition: (context) =>\n !context.hasActiveSession\n && !context.hasNordAccount\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n ],\n to: FlowState.ETH_TO_SOL_AUTH,\n condition: (context) =>\n !context.hasActiveSession\n && !context.hasNordAccount\n && context.walletType !== 'solana'\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n ],\n to: FlowState.CHAIN_SELECTION,\n condition: (context) =>\n !context.hasActiveSession\n && !context.hasNordAccount\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n ],\n to: FlowState.AMOUNT_INPUT,\n condition: (context) =>\n !context.hasActiveSession\n && !context.hasNordAccount\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n ],\n to: FlowState.DEPOSIT_PROGRESS,\n condition: (context) =>\n !context.hasActiveSession\n && !context.hasNordAccount\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.ERROR,\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n FlowState.DEPOSIT_PROGRESS,\n ],\n to: FlowState.DEPOSIT_SUCCESS,\n condition: (context) =>\n !context.hasActiveSession\n && context.hasNordAccount\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n FlowState.DEPOSIT_PROGRESS,\n FlowState.DEPOSIT_SUCCESS,\n FlowState.ERROR,\n ],\n to: FlowState.AUTH_LOADING,\n condition: (context) =>\n !context.hasActiveSession\n && context.hasNordAccount\n },\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n FlowState.DEPOSIT_PROGRESS,\n FlowState.DEPOSIT_SUCCESS,\n FlowState.AUTH_LOADING,\n FlowState.ERROR,\n ],\n to: FlowState.FINAL_SUCCESS,\n condition: (context) =>\n context.hasActiveSession\n && context.hasNordAccount\n },\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n FlowState.DEPOSIT_PROGRESS,\n FlowState.DEPOSIT_SUCCESS,\n FlowState.AUTH_LOADING,\n FlowState.FINAL_SUCCESS,\n FlowState.ERROR,\n ],\n to: FlowState.IDLE,\n },\n\n // Global recovery transition (can happen from any state upon recovery)\n {\n from: [\n FlowState.IDLE,\n FlowState.CONNECTING_WALLET,\n FlowState.ETH_TO_SOL_AUTH,\n FlowState.CHAIN_SELECTION,\n FlowState.AMOUNT_INPUT,\n FlowState.DEPOSIT_PROGRESS,\n FlowState.DEPOSIT_SUCCESS,\n FlowState.AUTH_LOADING,\n FlowState.FINAL_SUCCESS,\n ],\n to: FlowState.ERROR,\n },\n];\n\n/**\n * Local storage key for persisting flow state\n */\nexport const FLOW_STATE_STORAGE_KEY = 'n1_wallet_connection_flow_state';\n\n/**\n * Time in milliseconds after which a persisted state is considered stale\n */\nexport const STATE_EXPIRY_TIME = 30 * 60 * 1000; // 30 minutes\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { TransactionResult } from '../../../Logic/transactionManager';
|
|
3
|
+
export interface DepositContextValue {
|
|
4
|
+
amount: string;
|
|
5
|
+
isDepositing: boolean;
|
|
6
|
+
transactionId: string | null;
|
|
7
|
+
transactionResult: TransactionResult | null;
|
|
8
|
+
authStatus: 'loading' | 'success' | 'error';
|
|
9
|
+
authErrorMessage: string | null;
|
|
10
|
+
authStatusMessage: string | null;
|
|
11
|
+
updateAmount: (newAmount: string) => void;
|
|
12
|
+
startDeposit: () => Promise<void>;
|
|
13
|
+
completeDeposit: () => void;
|
|
14
|
+
performAuth: () => Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
interface DepositProviderProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Provider component for the deposit context
|
|
21
|
+
*/
|
|
22
|
+
export declare const DepositProvider: React.FC<DepositProviderProps>;
|
|
23
|
+
/**
|
|
24
|
+
* Hook to use the deposit context
|
|
25
|
+
*/
|
|
26
|
+
export declare const useDepositContext: () => DepositContextValue;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
11
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
12
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
+
function step(op) {
|
|
15
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
+
switch (op[0]) {
|
|
20
|
+
case 0: case 1: t = op; break;
|
|
21
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
+
default:
|
|
25
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
+
if (t[2]) _.ops.pop();
|
|
30
|
+
_.trys.pop(); continue;
|
|
31
|
+
}
|
|
32
|
+
op = body.call(thisArg, _);
|
|
33
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
38
|
+
import { createContext, useCallback, useContext, useEffect, useRef, useState } from 'react';
|
|
39
|
+
import { getExplorerUrl, } from '../../../Logic/transactionManager';
|
|
40
|
+
import { useN1WalletContext, useN1WalletInternalContext, } from '../../../Provider/hooks';
|
|
41
|
+
import { logger } from '../../../utils/logger';
|
|
42
|
+
import { FlowState } from '../types';
|
|
43
|
+
import { useFlowStateContext } from './FlowContext';
|
|
44
|
+
// Create the context with a default value
|
|
45
|
+
var DepositContext = createContext(undefined);
|
|
46
|
+
/**
|
|
47
|
+
* Provider component for the deposit context
|
|
48
|
+
*/
|
|
49
|
+
export var DepositProvider = function (_a) {
|
|
50
|
+
var children = _a.children;
|
|
51
|
+
// Get flow state context
|
|
52
|
+
var _b = useFlowStateContext(), state = _b.state, context = _b.context, transition = _b.transition, updateContext = _b.updateContext;
|
|
53
|
+
// Get wallet context
|
|
54
|
+
var _c = useN1WalletContext(), address = _c.address, nord = _c.nord, signMessageWithWalletKey = _c.signMessageWithWalletKey, signMessageWithSessionKey = _c.signMessageWithSessionKey, nordUser = _c.nordUser;
|
|
55
|
+
var sessionMode = useN1WalletInternalContext().sessionMode;
|
|
56
|
+
// chain
|
|
57
|
+
var _d = useState(context.selectedChain), selectedChain = _d[0], setSelectedChain = _d[1];
|
|
58
|
+
// transaction & deposit
|
|
59
|
+
var _e = useState(context.amount), amount = _e[0], setAmount = _e[1];
|
|
60
|
+
var _f = useState(false), isDepositing = _f[0], setIsDepositing = _f[1];
|
|
61
|
+
var _g = useState(context.transactionId), transactionId = _g[0], setTransactionId = _g[1];
|
|
62
|
+
var _h = useState(null), transactionResult = _h[0], setTransactionResult = _h[1];
|
|
63
|
+
// auth
|
|
64
|
+
var _j = useState('loading'), authStatus = _j[0], setAuthStatus = _j[1];
|
|
65
|
+
var _k = useState(null), authErrorMessage = _k[0], setAuthErrorMessage = _k[1];
|
|
66
|
+
var _l = useState(null), authStatusMessage = _l[0], setAuthStatusMessage = _l[1];
|
|
67
|
+
// Use refs to track previous values
|
|
68
|
+
var prevContextRef = useRef(context);
|
|
69
|
+
/**
|
|
70
|
+
* Handle an error by transitioning to error state
|
|
71
|
+
*/
|
|
72
|
+
var handleError = useCallback(function (error) {
|
|
73
|
+
logger.error('Flow error:', error);
|
|
74
|
+
transition(FlowState.ERROR, { error: error });
|
|
75
|
+
}, [transition]);
|
|
76
|
+
/**
|
|
77
|
+
* Authenticate session
|
|
78
|
+
*/
|
|
79
|
+
var performAuth = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var sessionPubKey, sessionId, sessionIdKey, error_1;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
_a.trys.push([0, 3, , 4]);
|
|
85
|
+
// Step 1: Tell user to sign transaction
|
|
86
|
+
setAuthStatusMessage('Please sign the transaction to authenticate your session');
|
|
87
|
+
if (!nordUser) {
|
|
88
|
+
throw new Error('Nord user is not initialized');
|
|
89
|
+
}
|
|
90
|
+
// Step 2: Call nordUser.refreshSession and get sessionId
|
|
91
|
+
setAuthStatusMessage('Session is being authenticated...');
|
|
92
|
+
sessionPubKey = nordUser.sessionPubKey;
|
|
93
|
+
if (!sessionPubKey) {
|
|
94
|
+
throw new Error('Session public key is not available');
|
|
95
|
+
}
|
|
96
|
+
// Refresh the session
|
|
97
|
+
return [4 /*yield*/, nordUser.refreshSession(sessionPubKey)];
|
|
98
|
+
case 1:
|
|
99
|
+
// Refresh the session
|
|
100
|
+
_a.sent();
|
|
101
|
+
return [4 /*yield*/, nordUser.updateAccountId()];
|
|
102
|
+
case 2:
|
|
103
|
+
_a.sent();
|
|
104
|
+
sessionId = nordUser.sessionId;
|
|
105
|
+
if (!sessionId) {
|
|
106
|
+
throw new Error('Failed to get session ID after refresh');
|
|
107
|
+
}
|
|
108
|
+
logger.debug('Session refreshed successfully', {
|
|
109
|
+
sessionId: sessionId.toString(),
|
|
110
|
+
});
|
|
111
|
+
// Step 3: Store sessionId in localStorage
|
|
112
|
+
if (address) {
|
|
113
|
+
sessionIdKey = "n1_sessionId_".concat(address);
|
|
114
|
+
localStorage.setItem(sessionIdKey, sessionId.toString());
|
|
115
|
+
logger.debug('Stored sessionId in localStorage', { key: sessionIdKey });
|
|
116
|
+
}
|
|
117
|
+
// Step 4: Update status to success
|
|
118
|
+
setAuthStatus('success');
|
|
119
|
+
// Step 5: Update context and transition to success
|
|
120
|
+
console.log('hasActiveSession', "asdasdsadsa");
|
|
121
|
+
// updateContext({ hasActiveSession: true });
|
|
122
|
+
setTimeout(function () {
|
|
123
|
+
transition(FlowState.FINAL_SUCCESS, { hasActiveSession: true, hasNordAccount: true });
|
|
124
|
+
}, 100);
|
|
125
|
+
return [3 /*break*/, 4];
|
|
126
|
+
case 3:
|
|
127
|
+
error_1 = _a.sent();
|
|
128
|
+
console.error('Authentication error:', error_1);
|
|
129
|
+
setAuthStatus('error');
|
|
130
|
+
setAuthErrorMessage(error_1 instanceof Error ? error_1.message : 'Unknown error occurred');
|
|
131
|
+
return [3 /*break*/, 4];
|
|
132
|
+
case 4: return [2 /*return*/];
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}); }, [updateContext, transition, address, nordUser]);
|
|
136
|
+
/**
|
|
137
|
+
* Update amount for deposit
|
|
138
|
+
*/
|
|
139
|
+
var updateAmount = useCallback(function (newAmount) {
|
|
140
|
+
setAmount(newAmount);
|
|
141
|
+
if (state === FlowState.AMOUNT_INPUT) {
|
|
142
|
+
updateContext({ amount: newAmount });
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
transition(state, { amount: newAmount });
|
|
146
|
+
}
|
|
147
|
+
}, [state, transition, updateContext]);
|
|
148
|
+
/**
|
|
149
|
+
* Start deposit process
|
|
150
|
+
*/
|
|
151
|
+
var startDeposit = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
152
|
+
var usdcToken, txId, accountInitialized, i, exists, result, depositError_1, errorMessage;
|
|
153
|
+
return __generator(this, function (_a) {
|
|
154
|
+
switch (_a.label) {
|
|
155
|
+
case 0:
|
|
156
|
+
if (isDepositing)
|
|
157
|
+
return [2 /*return*/];
|
|
158
|
+
logger.debug('Starting deposit process');
|
|
159
|
+
if (!amount || parseFloat(amount) <= 0) {
|
|
160
|
+
handleError(new Error('Invalid amount'));
|
|
161
|
+
return [2 /*return*/];
|
|
162
|
+
}
|
|
163
|
+
setIsDepositing(true);
|
|
164
|
+
transition(FlowState.DEPOSIT_PROGRESS);
|
|
165
|
+
_a.label = 1;
|
|
166
|
+
case 1:
|
|
167
|
+
_a.trys.push([1, 8, , 9]);
|
|
168
|
+
usdcToken = nord.tokens.find(function (t) { return t.symbol === 'USDC'; });
|
|
169
|
+
return [4 /*yield*/, nordUser.depositSpl(parseFloat(amount), usdcToken.tokenId)];
|
|
170
|
+
case 2:
|
|
171
|
+
txId = _a.sent();
|
|
172
|
+
accountInitialized = false;
|
|
173
|
+
i = 0;
|
|
174
|
+
_a.label = 3;
|
|
175
|
+
case 3:
|
|
176
|
+
if (!(i < 70)) return [3 /*break*/, 7];
|
|
177
|
+
return [4 /*yield*/, (nord === null || nord === void 0 ? void 0 : nord.accountExists(address))];
|
|
178
|
+
case 4:
|
|
179
|
+
exists = _a.sent();
|
|
180
|
+
if (exists) {
|
|
181
|
+
accountInitialized = true;
|
|
182
|
+
return [3 /*break*/, 7];
|
|
183
|
+
}
|
|
184
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 5000); })];
|
|
185
|
+
case 5:
|
|
186
|
+
_a.sent();
|
|
187
|
+
_a.label = 6;
|
|
188
|
+
case 6:
|
|
189
|
+
i++;
|
|
190
|
+
return [3 /*break*/, 3];
|
|
191
|
+
case 7:
|
|
192
|
+
if (!accountInitialized) {
|
|
193
|
+
throw new Error('Account failed to intialize on N1.');
|
|
194
|
+
}
|
|
195
|
+
logger.debug('Deposit successful using Nord-TS', txId);
|
|
196
|
+
result = {
|
|
197
|
+
success: true,
|
|
198
|
+
transactionId: txId,
|
|
199
|
+
amount: amount,
|
|
200
|
+
tokenSymbol: 'USDC',
|
|
201
|
+
fromAddress: address || 'Your Wallet',
|
|
202
|
+
toAddress: 'Exchange Account',
|
|
203
|
+
networkName: selectedChain,
|
|
204
|
+
status: 'Completed',
|
|
205
|
+
explorerUrl: getExplorerUrl(txId),
|
|
206
|
+
};
|
|
207
|
+
// Update state with transaction result
|
|
208
|
+
setTransactionId(txId);
|
|
209
|
+
setTransactionResult(result);
|
|
210
|
+
logger.debug('Transaction completed successfully');
|
|
211
|
+
transition(FlowState.DEPOSIT_SUCCESS, { transactionId: txId, hasNordAccount: true });
|
|
212
|
+
return [3 /*break*/, 9];
|
|
213
|
+
case 8:
|
|
214
|
+
depositError_1 = _a.sent();
|
|
215
|
+
logger.warn('Error using depositSpl, falling back to mock implementation:', depositError_1);
|
|
216
|
+
setIsDepositing(false);
|
|
217
|
+
errorMessage = depositError_1 instanceof Error
|
|
218
|
+
? depositError_1.message
|
|
219
|
+
: 'Failed to process deposit';
|
|
220
|
+
transition(FlowState.AMOUNT_INPUT, {
|
|
221
|
+
depositError: errorMessage
|
|
222
|
+
});
|
|
223
|
+
return [2 /*return*/]; // Exit early
|
|
224
|
+
case 9: return [2 /*return*/];
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
}); }, [
|
|
228
|
+
isDepositing,
|
|
229
|
+
selectedChain,
|
|
230
|
+
amount,
|
|
231
|
+
address,
|
|
232
|
+
sessionMode,
|
|
233
|
+
transition,
|
|
234
|
+
handleError,
|
|
235
|
+
nord,
|
|
236
|
+
signMessageWithWalletKey,
|
|
237
|
+
signMessageWithSessionKey,
|
|
238
|
+
nordUser,
|
|
239
|
+
]);
|
|
240
|
+
/**
|
|
241
|
+
* Complete the deposit process and move to the next screen
|
|
242
|
+
*/
|
|
243
|
+
var completeDeposit = useCallback(function () {
|
|
244
|
+
// Check if user has an active session to determine the next state
|
|
245
|
+
if (context.hasActiveSession) {
|
|
246
|
+
// If user has an active session, go directly to FINAL_SUCCESS
|
|
247
|
+
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
// Check if there's a sessionId stored in localStorage
|
|
251
|
+
var sessionIdKey = "n1_sessionId_".concat(address);
|
|
252
|
+
var storedSessionId = localStorage.getItem(sessionIdKey);
|
|
253
|
+
console.log('storedSessionId', storedSessionId, sessionIdKey);
|
|
254
|
+
if (storedSessionId !== null) {
|
|
255
|
+
// If we have a sessionId in localStorage (even if it's 0), go directly to FINAL_SUCCESS
|
|
256
|
+
transition(FlowState.FINAL_SUCCESS, { hasNordAccount: true, hasActiveSession: true });
|
|
257
|
+
}
|
|
258
|
+
else {
|
|
259
|
+
// If user doesn't have an active session and no sessionId in localStorage, go to NORD_AUTH
|
|
260
|
+
transition(FlowState.AUTH_LOADING, { hasActiveSession: true });
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
}, [context.hasActiveSession, transition, address]);
|
|
264
|
+
// Create the context value
|
|
265
|
+
var contextValue = {
|
|
266
|
+
amount: amount,
|
|
267
|
+
isDepositing: isDepositing,
|
|
268
|
+
transactionId: transactionId,
|
|
269
|
+
transactionResult: transactionResult,
|
|
270
|
+
authStatus: authStatus,
|
|
271
|
+
authErrorMessage: authErrorMessage,
|
|
272
|
+
authStatusMessage: authStatusMessage,
|
|
273
|
+
updateAmount: updateAmount,
|
|
274
|
+
startDeposit: startDeposit,
|
|
275
|
+
completeDeposit: completeDeposit,
|
|
276
|
+
performAuth: performAuth,
|
|
277
|
+
};
|
|
278
|
+
/**
|
|
279
|
+
* Update state based on context changes
|
|
280
|
+
*/
|
|
281
|
+
useEffect(function () {
|
|
282
|
+
var prevContext = prevContextRef.current;
|
|
283
|
+
// Only update state if the relevant context values have actually changed
|
|
284
|
+
if (context.selectedChain !== prevContext.selectedChain) {
|
|
285
|
+
setSelectedChain(context.selectedChain);
|
|
286
|
+
}
|
|
287
|
+
if (context.amount !== prevContext.amount) {
|
|
288
|
+
setAmount(context.amount);
|
|
289
|
+
}
|
|
290
|
+
if (context.transactionId !== prevContext.transactionId) {
|
|
291
|
+
setTransactionId(context.transactionId);
|
|
292
|
+
}
|
|
293
|
+
// Update the ref to the current context
|
|
294
|
+
prevContextRef.current = context;
|
|
295
|
+
}, [context]);
|
|
296
|
+
return (_jsx(DepositContext.Provider, { value: contextValue, children: children }));
|
|
297
|
+
};
|
|
298
|
+
/**
|
|
299
|
+
* Hook to use the deposit context
|
|
300
|
+
*/
|
|
301
|
+
export var useDepositContext = function () {
|
|
302
|
+
var context = useContext(DepositContext);
|
|
303
|
+
if (context === undefined) {
|
|
304
|
+
throw new Error('useDepositContext must be used within a DepositProvider');
|
|
305
|
+
}
|
|
306
|
+
return context;
|
|
307
|
+
};
|
|
308
|
+
//# sourceMappingURL=DepositContext.js.map
|