@@ -14,7 +14,13 @@ import AccountDisplay from '../AccountDisplay/AccountDisplay'
14
14
import ThresholdSelection from '../../pages/Creation/ThresholdSelection'
15
15
import SignatorySelection from '../select/SignatorySelection'
16
16
import Summary from '../../pages/Creation/Summary'
17
- import { useApi } from '../../contexts/ApiContext'
17
+ import {
18
+ isContextIn ,
19
+ isContextOf ,
20
+ noHydrationKeys_1 ,
21
+ noHydrationKeys_2 ,
22
+ useApi
23
+ } from '../../contexts/ApiContext'
18
24
import { useAccounts } from '../../contexts/AccountsContext'
19
25
import { useSigningCallback } from '../../hooks/useSigningCallback'
20
26
import { AccountBadge } from '../../types'
@@ -44,7 +50,8 @@ type Step = 'selection' | 'summary' | 'call1' | 'call2'
44
50
const ChangeMultisig = ( { onClose, className } : Props ) => {
45
51
const { selectedNetwork } = useNetwork ( )
46
52
const modalRef = useRef < HTMLDivElement | null > ( null )
47
- const { api, chainInfo, compatibilityToken, apiDescriptor } = useApi ( )
53
+ const ctx = useApi ( )
54
+ const { api, chainInfo, compatibilityToken } = ctx
48
55
const { selectedMultiProxy, getMultisigAsAccountBaseInfo, getMultisigByAddress } = useMultiProxy ( )
49
56
const signCallBack2 = useSigningCallback ( {
50
57
onSuccess : onClose ,
@@ -89,7 +96,7 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
89
96
const [ callError , setCallError ] = useState ( '' )
90
97
91
98
const secondCall = useMemo ( ( ) => {
92
- if ( ! api || ! compatibilityToken || ! selectedNetwork ) {
99
+ if ( ! ctx . api || ! compatibilityToken || ! selectedNetwork ) {
93
100
// console.error('api is not ready')
94
101
return
95
102
}
@@ -122,79 +129,47 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
122
129
selectedMultisig . signatories . filter ( ( sig ) => sig !== selectedAccount . address )
123
130
)
124
131
125
- const addProxyTx =
126
- apiDescriptor === 'hydration'
127
- ? api . tx . Proxy . add_proxy ( {
128
- delegate : newMultisigAddress ,
132
+ const addProxyTx = isContextOf ( ctx , 'hydration' )
133
+ ? ctx . api . tx . Proxy . add_proxy ( {
134
+ delegate : newMultisigAddress ,
135
+ proxy_type : Enum ( 'Any' ) ,
136
+ delay : 0
137
+ } )
138
+ : isContextIn ( ctx , noHydrationKeys_1 )
139
+ ? ctx . api . tx . Proxy . add_proxy ( {
140
+ delegate : MultiAddress . Id ( newMultisigAddress ) ,
129
141
proxy_type : Enum ( 'Any' ) ,
130
142
delay : 0
131
143
} )
132
- : apiDescriptor === 'acala'
133
- ? api . tx . Proxy . add_proxy ( {
134
- delegate : MultiAddress . Id ( newMultisigAddress ) ,
135
- proxy_type : Enum ( 'Any' ) ,
136
- delay : 0
137
- } )
138
- : apiDescriptor === 'khala'
139
- ? api . tx . Proxy . add_proxy ( {
140
- delegate : MultiAddress . Id ( newMultisigAddress ) ,
141
- proxy_type : Enum ( 'Any' ) ,
142
- delay : 0
143
- } )
144
- : apiDescriptor === 'kusama'
145
- ? api . tx . Proxy . add_proxy ( {
146
- delegate : MultiAddress . Id ( newMultisigAddress ) ,
147
- proxy_type : Enum ( 'Any' ) ,
148
- delay : 0
149
- } )
150
- : apiDescriptor === 'phala'
151
- ? api . tx . Proxy . add_proxy ( {
152
- delegate : MultiAddress . Id ( newMultisigAddress ) ,
153
- proxy_type : Enum ( 'Any' ) ,
154
- delay : 0
155
- } )
156
- : api . tx . Proxy . add_proxy ( {
157
- delegate : MultiAddress . Id ( newMultisigAddress ) ,
158
- proxy_type : Enum ( 'Any' ) ,
159
- delay : 0
160
- } )
161
-
162
- const proxyTx =
163
- apiDescriptor === 'hydration'
164
- ? api . tx . Proxy . proxy ( {
165
- real : selectedMultiProxy ?. proxy ,
144
+ : isContextIn ( ctx , noHydrationKeys_2 ) &&
145
+ ctx . api . tx . Proxy . add_proxy ( {
146
+ delegate : MultiAddress . Id ( newMultisigAddress ) ,
147
+ proxy_type : Enum ( 'Any' ) ,
148
+ delay : 0
149
+ } )
150
+
151
+ if ( ! addProxyTx ) return
152
+
153
+ const proxyTx = isContextOf ( ctx , 'hydration' )
154
+ ? ctx . api . tx . Proxy . proxy ( {
155
+ real : selectedMultiProxy ?. proxy ,
156
+ force_proxy_type : undefined ,
157
+ call : addProxyTx . decodedCall
158
+ } )
159
+ : isContextIn ( ctx , noHydrationKeys_1 )
160
+ ? ctx . api . tx . Proxy . proxy ( {
161
+ real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
162
+ force_proxy_type : undefined ,
163
+ call : addProxyTx . decodedCall
164
+ } )
165
+ : isContextIn ( ctx , noHydrationKeys_2 ) &&
166
+ ctx . api . tx . Proxy . proxy ( {
167
+ real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
166
168
force_proxy_type : undefined ,
167
169
call : addProxyTx . decodedCall
168
170
} )
169
- : apiDescriptor === 'acala'
170
- ? api . tx . Proxy . proxy ( {
171
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
172
- force_proxy_type : undefined ,
173
- call : addProxyTx . decodedCall
174
- } )
175
- : apiDescriptor === 'khala'
176
- ? api . tx . Proxy . proxy ( {
177
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
178
- force_proxy_type : undefined ,
179
- call : addProxyTx . decodedCall
180
- } )
181
- : apiDescriptor === 'kusama'
182
- ? api . tx . Proxy . proxy ( {
183
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
184
- force_proxy_type : undefined ,
185
- call : addProxyTx . decodedCall
186
- } )
187
- : apiDescriptor === 'phala'
188
- ? api . tx . Proxy . proxy ( {
189
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
190
- force_proxy_type : undefined ,
191
- call : addProxyTx . decodedCall
192
- } )
193
- : api . tx . Proxy . proxy ( {
194
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
195
- force_proxy_type : undefined ,
196
- call : addProxyTx . decodedCall
197
- } )
171
+
172
+ if ( ! proxyTx ) return
198
173
199
174
// call with the old multisig to delete the new one
200
175
return getAsMultiTx ( {
@@ -205,22 +180,22 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
205
180
compatibilityToken
206
181
} )
207
182
} , [
208
- api ,
209
- chainInfo ,
183
+ ctx ,
210
184
compatibilityToken ,
211
- getSortAddress ,
212
- newMultisigAddress ,
213
- newThreshold ,
214
- oldThreshold ,
185
+ selectedNetwork ,
215
186
selectedAccount ,
216
187
selectedMultiProxy ?. proxy ,
188
+ chainInfo ,
217
189
selectedMultisig ,
218
- selectedNetwork ,
219
- apiDescriptor
190
+ oldThreshold ,
191
+ newThreshold ,
192
+ newMultisigAddress ,
193
+ getSortAddress ,
194
+ api
220
195
] )
221
196
222
197
const firstCall = useMemo ( ( ) => {
223
- if ( ! api || ! compatibilityToken ) {
198
+ if ( ! ctx ?. api || ! api || ! compatibilityToken ) {
224
199
// console.error('api is not ready')
225
200
return
226
201
}
@@ -248,79 +223,48 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
248
223
const otherNewSignatories = getSortAddress (
249
224
newSignatories . filter ( ( sig ) => sig !== selectedAccount . address )
250
225
)
251
- const removeProxyTx =
252
- apiDescriptor === 'hydration'
253
- ? api . tx . Proxy . remove_proxy ( {
254
- delegate : selectedMultisig ?. address ,
226
+
227
+ const removeProxyTx = isContextOf ( ctx , 'hydration' )
228
+ ? ctx . api . tx . Proxy . remove_proxy ( {
229
+ delegate : selectedMultisig ?. address ,
230
+ proxy_type : Enum ( 'Any' ) ,
231
+ delay : 0
232
+ } )
233
+ : isContextIn ( ctx , noHydrationKeys_1 )
234
+ ? ctx . api . tx . Proxy . remove_proxy ( {
235
+ delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
236
+ proxy_type : Enum ( 'Any' ) ,
237
+ delay : 0
238
+ } )
239
+ : isContextIn ( ctx , noHydrationKeys_2 ) &&
240
+ ctx . api . tx . Proxy . remove_proxy ( {
241
+ delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
255
242
proxy_type : Enum ( 'Any' ) ,
256
243
delay : 0
257
244
} )
258
- : apiDescriptor === 'acala'
259
- ? api . tx . Proxy . remove_proxy ( {
260
- delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
261
- proxy_type : Enum ( 'Any' ) ,
262
- delay : 0
263
- } )
264
- : apiDescriptor === 'khala'
265
- ? api . tx . Proxy . remove_proxy ( {
266
- delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
267
- proxy_type : Enum ( 'Any' ) ,
268
- delay : 0
269
- } )
270
- : apiDescriptor === 'kusama'
271
- ? api . tx . Proxy . remove_proxy ( {
272
- delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
273
- proxy_type : Enum ( 'Any' ) ,
274
- delay : 0
275
- } )
276
- : apiDescriptor === 'phala'
277
- ? api . tx . Proxy . remove_proxy ( {
278
- delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
279
- proxy_type : Enum ( 'Any' ) ,
280
- delay : 0
281
- } )
282
- : api . tx . Proxy . remove_proxy ( {
283
- delegate : MultiAddress . Id ( selectedMultisig ?. address ) ,
284
- proxy_type : Enum ( 'Any' ) ,
285
- delay : 0
286
- } )
287
-
288
- const proxyTx =
289
- apiDescriptor === 'hydration'
290
- ? api . tx . Proxy . proxy ( {
291
- real : selectedMultiProxy ?. proxy ,
245
+
246
+ if ( ! removeProxyTx ) return
247
+
248
+ const proxyTx = isContextOf ( ctx , 'hydration' )
249
+ ? ctx . api . tx . Proxy . proxy ( {
250
+ real : selectedMultiProxy ?. proxy ,
251
+ force_proxy_type : undefined ,
252
+ call : removeProxyTx . decodedCall
253
+ } )
254
+ : isContextIn ( ctx , noHydrationKeys_1 )
255
+ ? ctx . api . tx . Proxy . proxy ( {
256
+ real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
292
257
force_proxy_type : undefined ,
293
258
call : removeProxyTx . decodedCall
294
259
} )
295
- : apiDescriptor === 'acala'
296
- ? api . tx . Proxy . proxy ( {
297
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
298
- force_proxy_type : undefined ,
299
- call : removeProxyTx . decodedCall
300
- } )
301
- : apiDescriptor === 'khala'
302
- ? api . tx . Proxy . proxy ( {
303
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
304
- force_proxy_type : undefined ,
305
- call : removeProxyTx . decodedCall
306
- } )
307
- : apiDescriptor === 'kusama'
308
- ? api . tx . Proxy . proxy ( {
309
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
310
- force_proxy_type : undefined ,
311
- call : removeProxyTx . decodedCall
312
- } )
313
- : apiDescriptor === 'phala'
314
- ? api . tx . Proxy . proxy ( {
315
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
316
- force_proxy_type : undefined ,
317
- call : removeProxyTx . decodedCall
318
- } )
319
- : api . tx . Proxy . proxy ( {
320
- real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
321
- force_proxy_type : undefined ,
322
- call : removeProxyTx . decodedCall
323
- } )
260
+ : isContextIn ( ctx , noHydrationKeys_2 ) &&
261
+ api . tx . Proxy . proxy ( {
262
+ real : MultiAddress . Id ( selectedMultiProxy ?. proxy ) ,
263
+ force_proxy_type : undefined ,
264
+ call : removeProxyTx . decodedCall
265
+ } )
266
+
267
+ if ( ! proxyTx ) return
324
268
325
269
return getAsMultiTx ( {
326
270
api,
@@ -330,16 +274,16 @@ const ChangeMultisig = ({ onClose, className }: Props) => {
330
274
compatibilityToken
331
275
} )
332
276
} , [
277
+ ctx ,
333
278
api ,
279
+ compatibilityToken ,
280
+ selectedAccount ,
281
+ selectedMultisig ?. address ,
282
+ selectedMultiProxy ?. proxy ,
334
283
chainInfo ,
335
- getSortAddress ,
336
284
newSignatories ,
337
285
newThreshold ,
338
- selectedAccount ,
339
- selectedMultiProxy ,
340
- selectedMultisig ,
341
- compatibilityToken ,
342
- apiDescriptor
286
+ getSortAddress
343
287
] )
344
288
345
289
const { multisigProposalNeededFunds : firstCallNeededFunds , reserved : firstCallReserved } =
0 commit comments