@@ -2,6 +2,7 @@ import Button from '@/components/ui/Button'
2
2
import Notification from '@/components/ui/Notification'
3
3
import toast from '@/components/ui/toast'
4
4
import {
5
+ apiEditUserProfile ,
5
6
apiGetMyProfile ,
6
7
apiGetNodeTheme ,
7
8
apiSetMyIdentityWallet ,
@@ -28,6 +29,7 @@ const WalletSettings = () => {
28
29
const [ requestIdentityLoading , setRequestIdentityLoading ] = useState ( false )
29
30
const [ requestOwnershipLoading , setRequestOwnershipLoading ] =
30
31
useState ( false )
32
+ const [ bindWalletsLoading , setBindWalletsLoading ] = useState ( false )
31
33
const [ faucetData , setFaucetData ] = useState < any > ( {
32
34
address : '' ,
33
35
balance : 0 ,
@@ -42,7 +44,8 @@ const WalletSettings = () => {
42
44
const themeColor = useAppSelector ( ( state ) => state . theme . themeBackground )
43
45
44
46
const contractStore = useContractStore ( )
45
- const { RegisterIdentity } = contractStore ( ( state ) => state )
47
+ const { RegisterIdentity, RegisterOwnership, bindIdentityOwnership } =
48
+ contractStore ( ( state ) => state )
46
49
47
50
async function getBalance ( ) {
48
51
const balance = await getWalletBalance ( )
@@ -169,8 +172,6 @@ const WalletSettings = () => {
169
172
setRequestIdentityLoading ( true )
170
173
171
174
try {
172
- console . log ( 'Maghol:' , address )
173
- console . log ( 'Maghol 2:' , nodeId )
174
175
const res = await RegisterIdentity ( nodeId )
175
176
if ( res . status == true ) {
176
177
await apiSetMyIdentityWallet ( String ( address ) )
@@ -233,17 +234,39 @@ const WalletSettings = () => {
233
234
}
234
235
235
236
setRequestOwnershipLoading ( true )
237
+
238
+ if ( theProfile . identityWallet == null ) {
239
+ return toast . push (
240
+ < Notification title = "Error" type = "danger" >
241
+ Please register your identity wallet first.
242
+ </ Notification >
243
+ )
244
+ }
245
+
236
246
try {
237
- await apiSetMyOwnerShipWallet ( String ( address ) )
238
- toast . push (
239
- < Notification
240
- title = { 'Ownership wallet set successfully' }
241
- type = "success"
242
- /> ,
243
- {
244
- placement : 'top-center' ,
245
- }
247
+ const res = await RegisterOwnership (
248
+ String ( theProfile . identityWallet )
246
249
)
250
+
251
+ if ( res . status == true ) {
252
+ await apiSetMyOwnerShipWallet ( String ( address ) )
253
+ toast . push (
254
+ < Notification
255
+ title = { 'Ownership wallet set successfully' }
256
+ type = "success"
257
+ /> ,
258
+ {
259
+ placement : 'top-center' ,
260
+ }
261
+ )
262
+ } else {
263
+ toast . push (
264
+ < Notification title = { res . error } type = "danger" /> ,
265
+ {
266
+ placement : 'top-center' ,
267
+ }
268
+ )
269
+ }
247
270
} catch ( error : any ) {
248
271
setRequestOwnershipLoading ( false )
249
272
disconnect ( )
@@ -277,6 +300,65 @@ const WalletSettings = () => {
277
300
setRequestOwnershipLoading ( false )
278
301
}
279
302
303
+ async function handleBindIdentityAndOwnerShip ( ) {
304
+ setBindWalletsLoading ( true )
305
+ try {
306
+ if (
307
+ ! userProfile . ownerShipWallets &&
308
+ userProfile . ownerShipWallets . length == 0
309
+ ) {
310
+ toast . push (
311
+ < Notification title = "Error" type = "danger" >
312
+ Please register your ownership wallet first.
313
+ </ Notification > ,
314
+ { placement : 'top-center' }
315
+ )
316
+ setBindWalletsLoading ( false )
317
+ return
318
+ }
319
+
320
+ const res = await bindIdentityOwnership (
321
+ String ( userProfile . ownerShipWallets [ 0 ] )
322
+ )
323
+ if ( res . status == true ) {
324
+ toast . push (
325
+ < Notification
326
+ title = "Identity and ownership wallets bound successfully"
327
+ type = "success"
328
+ /> ,
329
+ { placement : 'top-center' }
330
+ )
331
+ try {
332
+ await apiEditUserProfile ( userProfile . id , {
333
+ walletsBounded : true ,
334
+ } )
335
+ } catch ( error ) {
336
+ console . error ( 'Error updating wallet bound status:' , error )
337
+ toast . push (
338
+ < Notification title = "Error" type = "danger" >
339
+ Failed to update wallet bound status. Please try
340
+ again.
341
+ </ Notification > ,
342
+ {
343
+ placement : 'top-center' ,
344
+ }
345
+ )
346
+ }
347
+ } else {
348
+ toast . push ( < Notification title = { res . error } type = "danger" /> , {
349
+ placement : 'top-center' ,
350
+ } )
351
+ }
352
+ } catch ( error ) {
353
+ console . error ( 'Error binding wallets:' , error )
354
+ toast . push (
355
+ < Notification title = "Error binding wallets" type = "danger" /> ,
356
+ { placement : 'top-center' }
357
+ )
358
+ }
359
+ setBindWalletsLoading ( false )
360
+ }
361
+
280
362
return (
281
363
< >
282
364
{ ( loading == false && (
@@ -354,6 +436,10 @@ const WalletSettings = () => {
354
436
onClick = { ( ) =>
355
437
handleRequestFaucet ( 'identity' )
356
438
}
439
+ disabled = {
440
+ isConnected == false ||
441
+ walletType == 'ownership'
442
+ }
357
443
variant = "solid"
358
444
size = "xs"
359
445
>
@@ -419,8 +505,9 @@ const WalletSettings = () => {
419
505
variant = "solid"
420
506
size = "sm"
421
507
disabled = {
422
- isConnected &&
423
- walletType == 'identity'
508
+ ( isConnected &&
509
+ walletType == 'identity' ) ||
510
+ ! userProfile . identityWallet
424
511
}
425
512
onClick = { ( ) =>
426
513
connectWallet ( 'ownership' )
@@ -439,6 +526,10 @@ const WalletSettings = () => {
439
526
onClick = { ( ) =>
440
527
handleRequestFaucet ( 'ownership' )
441
528
}
529
+ disabled = {
530
+ isConnected == false ||
531
+ walletType == 'identity'
532
+ }
442
533
variant = "solid"
443
534
size = "xs"
444
535
>
@@ -452,6 +543,14 @@ const WalletSettings = () => {
452
543
size = "sm"
453
544
variant = "solid"
454
545
className = "w-fit mx-auto mt-1"
546
+ disabled = {
547
+ ! userProfile . identityWallet ||
548
+ ! userProfile . ownerShipWallets ||
549
+ userProfile . ownerShipWallets . length == 0 ||
550
+ ( isConnected && walletType == 'ownership' )
551
+ }
552
+ loading = { bindWalletsLoading }
553
+ onClick = { handleBindIdentityAndOwnerShip }
455
554
>
456
555
Bind Identity and Ownership Wallets
457
556
</ Button >
0 commit comments