Skip to content

Commit a555a1f

Browse files
committed
FrontEnd Update
1 parent aebf856 commit a555a1f

File tree

5 files changed

+242
-89
lines changed

5 files changed

+242
-89
lines changed

web_app/Source_webapp/src/ABI/IdentityOwnershipRegisterationABI.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
},
3030
{
3131
"indexed": false,
32-
"internalType": "uint256",
32+
"internalType": "string",
3333
"name": "nodeId",
34-
"type": "uint256"
34+
"type": "string"
3535
}
3636
],
3737
"name": "IdentityRegistered",
@@ -90,9 +90,9 @@
9090
"type": "address"
9191
},
9292
{
93-
"internalType": "uint256",
93+
"internalType": "string",
9494
"name": "nodeId",
95-
"type": "uint256"
95+
"type": "string"
9696
},
9797
{
9898
"internalType": "bool",
@@ -106,9 +106,9 @@
106106
{
107107
"inputs": [
108108
{
109-
"internalType": "uint256",
109+
"internalType": "string",
110110
"name": "",
111-
"type": "uint256"
111+
"type": "string"
112112
}
113113
],
114114
"name": "nodeExists",
@@ -125,9 +125,9 @@
125125
{
126126
"inputs": [
127127
{
128-
"internalType": "uint256",
128+
"internalType": "string",
129129
"name": "_nodeId",
130-
"type": "uint256"
130+
"type": "string"
131131
}
132132
],
133133
"name": "registerIdentity",

web_app/Source_webapp/src/store/contract/contract-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const commitmentContractAddress =
55
'0x96259fba1f845b42c257f72088dd38c7e8540504'
66

77
export const identityOwnershipRegisterationContractAddress =
8-
'0x4d0975e26897b4f417bbb9bc6d2e0f8dd614de70'
8+
'0xeda2f758e39cd6fbde49924bb4d8f1a8a07ed4a3'
99

1010
import commitmentManagementABI from '../../ABI/CommitmentManagemantABI.json'
1111
import identityOwnershipRegisterationABI from '../../ABI/IdentityOwnershipRegisterationABI.json'

web_app/Source_webapp/src/store/contract/useContractStore.ts

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ interface ContractStore {
1212
commitmentContract: Contract
1313
identityOwnershipRegisterationContract: Contract
1414
getErrorMessage: (error: any) => string
15-
RegisterIdentity: (nodeId: string) => Promise<{status: boolean, tx?: any, error?: string}>
15+
RegisterIdentity: (
16+
nodeId: string
17+
) => Promise<{ status: boolean; tx?: any; error?: string }>
18+
RegisterOwnership: (
19+
identityAddress: string
20+
) => Promise<{ status: boolean; tx?: any; error?: string }>
1621
storeZKP: (
1722
nodeId: string,
1823
deviceId: string,
@@ -31,6 +36,9 @@ interface ContractStore {
3136
firmwareVersion: string,
3237
commitmentData: string
3338
) => Promise<boolean | string>
39+
bindIdentityOwnership: (
40+
ownershipAddress: string
41+
) => Promise<{ status: boolean; tx?: any; error?: string }>
3442
}
3543

3644
export function createContractStore(walletProvider: any) {
@@ -71,12 +79,15 @@ export function createContractStore(walletProvider: any) {
7179
return errorMessage
7280
},
7381

74-
RegisterIdentity: async (nodeId: string): Promise<{status: boolean, tx?: any, error?: string}> => {
82+
RegisterIdentity: async (
83+
nodeId: string
84+
): Promise<{ status: boolean; tx?: any; error?: string }> => {
7585
const { identityOwnershipRegisterationContract, getErrorMessage } =
7686
get()
7787
try {
7888
set({ loading: true })
7989
const signer = await provider.getSigner()
90+
console.log('Signer wallet address:', await signer.getAddress())
8091
const tx = await (
8192
identityOwnershipRegisterationContract.connect(
8293
signer
@@ -89,6 +100,49 @@ export function createContractStore(walletProvider: any) {
89100
}
90101
},
91102

103+
RegisterOwnership: async (
104+
identityAddress: string
105+
): Promise<{ status: boolean; tx?: any; error?: string }> => {
106+
const { identityOwnershipRegisterationContract, getErrorMessage } =
107+
get()
108+
try {
109+
set({ loading: true })
110+
const signer = await provider.getSigner()
111+
console.log('Signer wallet address:', await signer.getAddress())
112+
const tx = await (
113+
identityOwnershipRegisterationContract.connect(
114+
signer
115+
) as any
116+
).registerOwnership(identityAddress)
117+
return { status: true, tx: tx }
118+
} catch (error) {
119+
set({ loading: false })
120+
return { status: false, error: getErrorMessage(error) }
121+
}
122+
},
123+
124+
bindIdentityOwnership: async (
125+
ownershipAddress: string
126+
): Promise<{ status: boolean; tx?: any; error?: string }> => {
127+
const { identityOwnershipRegisterationContract, getErrorMessage } =
128+
get()
129+
try {
130+
set({ loading: true })
131+
const signer = await provider.getSigner()
132+
console.log('Signer wallet address:', await signer.getAddress())
133+
console.log('ownershipAddress wallet address:', ownershipAddress)
134+
const tx = await (
135+
identityOwnershipRegisterationContract.connect(
136+
signer
137+
) as any
138+
).bindIdentityOwnership(ownershipAddress)
139+
return { status: true, tx: tx }
140+
} catch (error) {
141+
set({ loading: false })
142+
return { status: false, error: getErrorMessage(error) }
143+
}
144+
},
145+
92146
storeZKP: async (
93147
nodeId,
94148
deviceId,

web_app/Source_webapp/src/views/account/Settings/components/DigitalIdentity.tsx

Lines changed: 113 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Button from '@/components/ui/Button'
22
import Notification from '@/components/ui/Notification'
33
import toast from '@/components/ui/toast'
44
import {
5+
apiEditUserProfile,
56
apiGetMyProfile,
67
apiGetNodeTheme,
78
apiSetMyIdentityWallet,
@@ -28,6 +29,7 @@ const WalletSettings = () => {
2829
const [requestIdentityLoading, setRequestIdentityLoading] = useState(false)
2930
const [requestOwnershipLoading, setRequestOwnershipLoading] =
3031
useState(false)
32+
const [bindWalletsLoading, setBindWalletsLoading] = useState(false)
3133
const [faucetData, setFaucetData] = useState<any>({
3234
address: '',
3335
balance: 0,
@@ -42,7 +44,8 @@ const WalletSettings = () => {
4244
const themeColor = useAppSelector((state) => state.theme.themeBackground)
4345

4446
const contractStore = useContractStore()
45-
const { RegisterIdentity } = contractStore((state) => state)
47+
const { RegisterIdentity, RegisterOwnership, bindIdentityOwnership } =
48+
contractStore((state) => state)
4649

4750
async function getBalance() {
4851
const balance = await getWalletBalance()
@@ -169,8 +172,6 @@ const WalletSettings = () => {
169172
setRequestIdentityLoading(true)
170173

171174
try {
172-
console.log('Maghol:', address)
173-
console.log('Maghol 2:', nodeId)
174175
const res = await RegisterIdentity(nodeId)
175176
if (res.status == true) {
176177
await apiSetMyIdentityWallet(String(address))
@@ -233,17 +234,39 @@ const WalletSettings = () => {
233234
}
234235

235236
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+
236246
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)
246249
)
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+
}
247270
} catch (error: any) {
248271
setRequestOwnershipLoading(false)
249272
disconnect()
@@ -277,6 +300,65 @@ const WalletSettings = () => {
277300
setRequestOwnershipLoading(false)
278301
}
279302

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+
280362
return (
281363
<>
282364
{(loading == false && (
@@ -354,6 +436,10 @@ const WalletSettings = () => {
354436
onClick={() =>
355437
handleRequestFaucet('identity')
356438
}
439+
disabled={
440+
isConnected == false ||
441+
walletType == 'ownership'
442+
}
357443
variant="solid"
358444
size="xs"
359445
>
@@ -419,8 +505,9 @@ const WalletSettings = () => {
419505
variant="solid"
420506
size="sm"
421507
disabled={
422-
isConnected &&
423-
walletType == 'identity'
508+
(isConnected &&
509+
walletType == 'identity') ||
510+
!userProfile.identityWallet
424511
}
425512
onClick={() =>
426513
connectWallet('ownership')
@@ -439,6 +526,10 @@ const WalletSettings = () => {
439526
onClick={() =>
440527
handleRequestFaucet('ownership')
441528
}
529+
disabled={
530+
isConnected == false ||
531+
walletType == 'identity'
532+
}
442533
variant="solid"
443534
size="xs"
444535
>
@@ -452,6 +543,14 @@ const WalletSettings = () => {
452543
size="sm"
453544
variant="solid"
454545
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}
455554
>
456555
Bind Identity and Ownership Wallets
457556
</Button>

0 commit comments

Comments
 (0)