-
Notifications
You must be signed in to change notification settings - Fork 316
feat: mysterybox whitelist check #5698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ec25834
feat: update whitelist check function when opening maskbox
Randolph314 24efc31
refactor: adjust naming & code style (#5691)
guanbinrui 4ee76de
feat: change qualification to rootHash in URL
Randolph314 ea2e16b
fix: failed to open box (#5694)
guanbinrui b4725bf
Merge branch 'develop' into feat/mysterybox-whitelist-check
Randolph314 5787280
feat: catch error when call merkleProof api
Randolph314 f14de6d
feat: change holderTokenAmount judgement
Randolph314 33991b8
chore: delete console.log
Randolph314 e041058
Merge branch 'develop' into feat/mysterybox-whitelist-check
Randolph314 a007092
feat: change nft style when sharing claim success
Randolph314 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -260,7 +260,8 @@ | |
| "xlarge", | ||
| "xlink", | ||
| "zerion", | ||
| "zubin" | ||
| "zubin", | ||
| "merkel" | ||
| ], | ||
| "ignoreWords": [ | ||
| "aicanft", | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 './rss3' | ||
| export * from './merkleProof' |
This file contains hidden or 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,16 @@ | ||
| import urlcat from 'urlcat' | ||
| import { MERKLE_PROOF_ENDPOINT } from '../constants' | ||
|
|
||
| export async function getMerkleProof(leaf: string, root: string) { | ||
| try { | ||
| const response = await fetch( | ||
| urlcat(MERKLE_PROOF_ENDPOINT, { | ||
| leaf, | ||
| root: root.replace(/^0x/, ''), | ||
| }), | ||
| ) | ||
| return (await response.json()) as { proof?: string[]; message?: string; module?: string } | ||
| } catch (err: any) { | ||
| throw new Error(err?.message) | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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
13 changes: 0 additions & 13 deletions
13
packages/mask/src/plugins/MaskBox/hooks/useIsWhitelisted.ts
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
packages/mask/src/plugins/MaskBox/hooks/useMaskBoxQualificationContract.ts
This file contains hidden or 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,8 @@ | ||
| import type { AbiItem } from 'web3-utils' | ||
| import { useContract } from '@masknet/web3-shared-evm' | ||
| import type { MaskBoxQualification } from '@masknet/web3-contracts/types/MaskBoxQualification' | ||
| import MASK_BOX_QUALIFICATION_CONTRACT from '@masknet/web3-contracts/abis/MaskBoxQualification.json' | ||
|
|
||
| export function useMaskBoxQualificationContract(address?: string) { | ||
| return useContract<MaskBoxQualification>(address, MASK_BOX_QUALIFICATION_CONTRACT as AbiItem[]) | ||
| } |
This file contains hidden or 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,16 @@ | ||
| import { useAsyncRetry } from 'react-use' | ||
| import { useAccount } from '@masknet/web3-shared-evm' | ||
| import { getMerkleProof } from '../apis' | ||
|
|
||
| export function useMerkelProof(root?: string) { | ||
| const account = useAccount() | ||
| return useAsyncRetry(async () => { | ||
| if (!root) return | ||
|
|
||
| const leaf = Buffer.from( | ||
| (account.replace(/0x/, '').match(/.{2}/g) ?? []).map((x) => Number.parseInt(x, 16)), | ||
| ).toString('base64') | ||
|
|
||
| return getMerkleProof(leaf, root) | ||
| }, [account, root]) | ||
| } |
This file contains hidden or 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
13 changes: 13 additions & 0 deletions
13
packages/mask/src/plugins/MaskBox/hooks/useQualification.ts
This file contains hidden or 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 @@ | ||
| import { useAsyncRetry } from 'react-use' | ||
| import { useMaskBoxQualificationContract } from './useMaskBoxQualificationContract' | ||
|
|
||
| export function useQualification(address?: string, account?: string, proof?: string) { | ||
| const qualificationContract = useMaskBoxQualificationContract(address) | ||
| const { value: qualification = { qualified: false, error_msg: '' } } = useAsyncRetry(async () => { | ||
| if (!qualificationContract || !account) return null | ||
| return qualificationContract.methods.is_qualified(account, proof ?? '0x00').call({ | ||
| from: account, | ||
| }) | ||
| }, [account, qualificationContract, proof]) | ||
| return qualification | ||
| } |
8 changes: 0 additions & 8 deletions
8
packages/mask/src/plugins/MaskBox/hooks/useWhitelistContract.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then why you need to add a try-catch anyway?