-
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 anthony/cleanup
- Loading branch information
Showing
25 changed files
with
918 additions
and
135 deletions.
There are no files selected for viewing
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
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
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 +1,2 @@ | ||
export * from './get-primary-name-by-address'; | ||
export * from './set-primary-name'; |
21 changes: 21 additions & 0 deletions
21
packages/@justaname.id/sdk/src/lib/types/primary-name/set-primary-name.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,21 @@ | ||
import { ChainId, IRequest, IRoute } from '../common'; | ||
import { SIWEHeaders } from '../headers'; | ||
import { PrimaryNameGetByAddressResponse } from './get-primary-name-by-address'; | ||
|
||
export interface SetPrimaryNameRequest extends IRequest { | ||
name: string; | ||
|
||
address: string; | ||
|
||
chainId: ChainId; | ||
|
||
signature?: string; | ||
} | ||
|
||
export interface SetPrimaryNameRoute | ||
extends IRoute< | ||
SetPrimaryNameRequest, | ||
PrimaryNameGetByAddressResponse, | ||
SIWEHeaders, | ||
'chainId' | ||
> {} |
12 changes: 12 additions & 0 deletions
12
packages/@justweb3/ui/src/lib/components/BackBtn/BackBtn.module.css
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,12 @@ | ||
/* BackBtn.module.css */ | ||
|
||
.btnCard { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 24px; | ||
height: 24px; | ||
border-radius: 50%; | ||
background-color: var(--justweb3-foreground-color-4); | ||
cursor: pointer; | ||
} |
25 changes: 25 additions & 0 deletions
25
packages/@justweb3/ui/src/lib/components/BackBtn/index.tsx
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,25 @@ | ||
import { FC } from 'react'; | ||
import { ArrowIcon } from '../../icons'; | ||
import styles from './BackBtn.module.css'; | ||
|
||
interface BackBtnProps { | ||
onClick: (e: React.MouseEvent<HTMLDivElement>) => void; | ||
style?: React.CSSProperties; | ||
} | ||
|
||
export const BackBtn: FC<BackBtnProps> = ({ onClick, style }) => { | ||
return ( | ||
<div className={styles.btnCard} onClick={onClick} style={style}> | ||
<ArrowIcon | ||
width={16} | ||
color={'var(--justweb3-foreground-color-2)'} | ||
style={{ | ||
|
||
transform: 'rotate(180deg)', | ||
}} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
export default BackBtn; |
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,3 +1,4 @@ | ||
export * from './OrLine'; | ||
export * from './BackBtn'; | ||
export * from './ClickableItem'; | ||
export * from './ExpandableText'; | ||
export * from './OrLine'; |
31 changes: 31 additions & 0 deletions
31
packages/@justweb3/ui/src/lib/icons/components/general/Configuration.tsx
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,31 @@ | ||
import type { SVGProps } from 'react'; | ||
export default function Configuration(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
fill="none" | ||
viewBox="0 0 20 20" | ||
{...props} | ||
> | ||
<mask | ||
id="configuration_svg__a" | ||
width={20} | ||
height={20} | ||
x={0} | ||
y={0} | ||
maskUnits="userSpaceOnUse" | ||
style={{ | ||
maskType: 'alpha', | ||
}} | ||
> | ||
<path fill="#D9D9D9" d="M0 0h20v20H0z" /> | ||
</mask> | ||
<g mask="url(#configuration_svg__a)"> | ||
<path | ||
fill={props.fill || 'var(--justweb3-primary-color)'} | ||
d="M9.167 18.104 3.333 14.75a1.624 1.624 0 0 1-.833-1.437V6.688a1.62 1.62 0 0 1 .833-1.438l5.834-3.354q.395-.23.833-.23t.833.23l5.834 3.354q.395.23.614.604.219.375.219.834v6.625a1.62 1.62 0 0 1-.833 1.437l-5.834 3.354q-.396.23-.833.23-.438 0-.833-.23m0-7.625v5.709l.833.479.833-.48V10.48l5-2.896v-.875l-.896-.52L10 9.042 5.063 6.188l-.896.52v.875z" | ||
/> | ||
</g> | ||
</svg> | ||
); | ||
} |
Oops, something went wrong.