-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/JustaName-id/JustaName-sdk…
… into angelo/engr-730-add-openpassport-in-widget
- Loading branch information
Showing
29 changed files
with
1,111 additions
and
6,092 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/@justaname.id/react/src/lib/hooks/primaryName/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export * from './usePrimaryName'; | ||
export * from './usePrimaryNameBatch'; | ||
export * from './useSetPrimaryName'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
packages/@justaname.id/react/src/lib/hooks/primaryName/useSetPrimaryName.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use client'; | ||
|
||
import { SetPrimaryNameRoute } from '@justaname.id/sdk'; | ||
import { UseMutateAsyncFunction, useMutation } from '@tanstack/react-query'; | ||
import { useMemo } from 'react'; | ||
import { useJustaName, useSubnameSignature } from '../../providers'; | ||
import { useMountedAccount } from '../account/useMountedAccount'; | ||
import { usePrimaryName } from './usePrimaryName'; | ||
|
||
export interface UseSetPrimaryNameFunctionParams { | ||
name: string; | ||
} | ||
|
||
export type UseSetPrimaryNameParams = Omit< | ||
SetPrimaryNameRoute['params'], | ||
'name' | ||
>; | ||
|
||
export interface UseSetPrimaryNameResult { | ||
setPrimaryName: UseMutateAsyncFunction< | ||
SetPrimaryNameRoute['response'], | ||
Error, | ||
UseSetPrimaryNameFunctionParams | ||
>; | ||
isSetPrimaryNamePending: boolean; | ||
} | ||
|
||
export const useSetPrimaryName = ( | ||
params?: UseSetPrimaryNameParams | ||
): UseSetPrimaryNameResult => { | ||
const { justaname, chainId } = useJustaName(); | ||
const { address } = useMountedAccount(); | ||
const { getSignature } = useSubnameSignature(); | ||
const {refetchPrimaryName} = usePrimaryName({ | ||
address: address || '', | ||
enabled: !!address, | ||
}); | ||
const _chainId = useMemo( | ||
() => params?.chainId || chainId, | ||
[params?.chainId, chainId] | ||
); | ||
|
||
const mutate = useMutation({ | ||
mutationFn: async (_params: UseSetPrimaryNameFunctionParams) => { | ||
if (!address) { | ||
throw new Error('No address found'); | ||
} | ||
|
||
const _name = _params.name; | ||
const signature = await getSignature(); | ||
const primaryNameSet = await justaname.subnames.setPrimaryName( | ||
{ | ||
address, | ||
name: _name, | ||
chainId: _chainId, | ||
}, | ||
{ | ||
xAddress: address, | ||
xSignature: signature.signature, | ||
xMessage: signature.message, | ||
} | ||
); | ||
refetchPrimaryName(); | ||
return primaryNameSet; | ||
}, | ||
}); | ||
|
||
return { | ||
setPrimaryName: mutate.mutateAsync, | ||
isSetPrimaryNamePending: mutate.isPending, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.