-
Notifications
You must be signed in to change notification settings - Fork 424
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: enhancement of number input checking rule * fix: remove the title attribute of gasSelector * fix: gas ui * feat: useApprovalUtils * fix: remove screen height * fix: remove
- Loading branch information
1 parent
a7e0f21
commit cae735e
Showing
9 changed files
with
130 additions
and
30 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
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,13 @@ | ||
/** | ||
* Regex for input number | ||
* 1. Can't have more than one dot | ||
* 2. Can't have more than one leading zero | ||
* 3. Can't have non-numeric characters | ||
*/ | ||
export const INPUT_NUMBER_RE = /^(?!0{2,})[0-9]*(?!.*\..*\.)[0-9.]*$/; | ||
|
||
// filter start with 0 or 0. | ||
// replace start with . to 0. | ||
export const filterNumber = (value: string = '') => { | ||
return value.replace(/^0*(\d+)/, '$1').replace(/^\./, '0.'); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useWallet } from '@/ui/utils'; | ||
import React from 'react'; | ||
|
||
type AccountWithAliasName = { | ||
address: string; | ||
alias?: string; | ||
}; | ||
|
||
export const useApprovalAlias = () => { | ||
const [accounts, setAccounts] = React.useState<AccountWithAliasName[]>([]); | ||
const wallet = useWallet(); | ||
|
||
const accountMap = React.useMemo(() => { | ||
return accounts.reduce((acc, account) => { | ||
acc[account.address] = account; | ||
return acc; | ||
}, {} as Record<string, AccountWithAliasName>); | ||
}, [accounts]); | ||
|
||
const add = React.useCallback( | ||
async (address: string) => { | ||
if (accounts.some((account) => account.address === address)) { | ||
return accounts; | ||
} | ||
const alias = await wallet.getAlianName(address); | ||
setAccounts([...accounts, { address, alias }]); | ||
}, | ||
[accounts] | ||
); | ||
|
||
const update = React.useCallback((address: string, alias: string) => { | ||
setAccounts((accounts) => { | ||
return accounts.map((account) => { | ||
if (account.address === address) { | ||
wallet.updateAlianName(address, alias); | ||
return { ...account, alias }; | ||
} | ||
return account; | ||
}); | ||
}); | ||
}, []); | ||
|
||
return { accountMap, add, update }; | ||
}; |
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,30 @@ | ||
import React, { createContext, useContext } from 'react'; | ||
import { useApprovalAlias } from './useApprovalAlias'; | ||
|
||
/** | ||
* useApprovalUtils | ||
* @description some global state for approval page | ||
*/ | ||
const useApprovalUtilsState = () => { | ||
const alias = useApprovalAlias(); | ||
|
||
return { alias }; | ||
}; | ||
|
||
const ApprovalUtilsContext = createContext< | ||
ReturnType<typeof useApprovalUtilsState> | ||
>({} as any); | ||
|
||
export const useApprovalUtils = () => { | ||
return useContext(ApprovalUtilsContext); | ||
}; | ||
|
||
export const ApprovalUtilsProvider = ({ children }) => { | ||
const value = useApprovalUtilsState(); | ||
|
||
return ( | ||
<ApprovalUtilsContext.Provider value={value}> | ||
{children} | ||
</ApprovalUtilsContext.Provider> | ||
); | ||
}; |
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