Skip to content

Commit 9cf70d1

Browse files
authored
fix: mf-6653 narrow down nft default chains (#12159)
* fix: mf-6650 show tab arrow * fix: mf-6653 narrow down nft default chains * fix: claim error
1 parent eb8e003 commit 9cf70d1

File tree

6 files changed

+50
-45
lines changed

6 files changed

+50
-45
lines changed

packages/plugins/RedPacket/src/SiteAdaptor/NftRedPacket/index.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ export function NftRedPacket({ payload, currentPluginID }: NftRedPacketProps) {
7777
useEffect(() => {
7878
retryAvailability()
7979
}, [account])
80-
console.log('availability', availability)
8180
const network = useNetwork(pluginID, payload.chainId)
8281
const outdated = !!(availability?.isClaimedAll || availability?.isCompleted || availability?.expired)
8382

@@ -152,12 +151,14 @@ export function NftRedPacket({ payload, currentPluginID }: NftRedPacketProps) {
152151

153152
const { showSnackbar } = useCustomSnackbar()
154153
const claim = useCallback(async () => {
155-
const hash = await claimCallback()
156-
await checkResult()
157-
if (typeof hash === 'string') {
158-
retryAvailability()
159-
} else if (hash instanceof Error) {
160-
showSnackbar(hash.message, {
154+
try {
155+
const hash = await claimCallback()
156+
await checkResult()
157+
if (typeof hash === 'string') {
158+
retryAvailability()
159+
}
160+
} catch (err) {
161+
showSnackbar((err as Error).message, {
161162
variant: 'error',
162163
})
163164
}

packages/plugins/RedPacket/src/SiteAdaptor/hooks/useClaimNftRedpacketCallback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function useClaimNftRedpacketCallback(payload: RedPacketNftJSONPayload, t
1919
const signedMsg = useMemo(() => {
2020
return signMessage(account, payload.privateKey).signature ?? ''
2121
}, [account, payload.privateKey])
22-
return useAsyncFn(async (): Promise<string | undefined | Error> => {
22+
return useAsyncFn(async () => {
2323
if (!nftRedPacketContract || !id || !account || !totalAmount || !signedMsg) return
2424

2525
const transaction = nftRedPacketContract.methods.claim(id, signedMsg, account)

packages/plugins/RedPacket/src/SiteAdaptor/views/NftHistory.tsx

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@ const useStyles = makeStyles()((theme) => {
2222
return {
2323
root: {
2424
display: 'flex',
25-
width: 568,
26-
padding: 0,
25+
width: '100%',
26+
minHeight: 0,
2727
boxSizing: 'border-box',
28-
height: 474,
2928
flexDirection: 'column',
3029
margin: '0 auto',
3130
overflow: 'auto',
@@ -38,6 +37,16 @@ const useStyles = makeStyles()((theme) => {
3837
display: 'none',
3938
},
4039
},
40+
content: {
41+
minHeight: 0,
42+
flexGrow: 1,
43+
padding: theme.spacing(0, 2),
44+
overflow: 'auto',
45+
scrollbarWidth: 'none',
46+
'&::-webkit-scrollbar': {
47+
display: 'none',
48+
},
49+
},
4150
item: {
4251
width: '100%',
4352
padding: 0,
@@ -97,24 +106,26 @@ export function NftHistory() {
97106

98107
return (
99108
<div className={classes.root}>
100-
<NetworkTab chains={NFT_DEFAULT_CHAINS} hideArrowButton pluginID={NetworkPluginID.PLUGIN_EVM} />
101-
{isLoading ?
102-
<LoadingStatus className={classes.placeholder} iconSize={30} />
103-
: !histories?.length ?
104-
<EmptyStatus className={classes.placeholder} iconSize={36}>
105-
<Trans>
106-
You haven't created any NFT lucky drop yet. Try to create one and share fortune with your
107-
friends.
108-
</Trans>
109-
</EmptyStatus>
110-
: <List style={{ padding: '16px 0 0' }}>
111-
{histories.map((history) => (
112-
<ListItem className={classes.item} key={history.txid}>
113-
<NftRedPacketRecord collections={collections} history={history} onSend={onSend} />
114-
</ListItem>
115-
))}
116-
</List>
117-
}
109+
<NetworkTab chains={NFT_DEFAULT_CHAINS} pluginID={NetworkPluginID.PLUGIN_EVM} />
110+
<div className={classes.content}>
111+
{isLoading ?
112+
<LoadingStatus className={classes.placeholder} iconSize={30} />
113+
: !histories?.length ?
114+
<EmptyStatus className={classes.placeholder} iconSize={36}>
115+
<Trans>
116+
You haven't created any NFT lucky drop yet. Try to create one and share fortune with your
117+
friends.
118+
</Trans>
119+
</EmptyStatus>
120+
: <List style={{ padding: '16px 0 0' }}>
121+
{histories.map((history) => (
122+
<ListItem className={classes.item} key={history.txid}>
123+
<NftRedPacketRecord collections={collections} history={history} onSend={onSend} />
124+
</ListItem>
125+
))}
126+
</List>
127+
}
128+
</div>
118129
</div>
119130
)
120131
}

packages/plugins/RedPacket/src/constants.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,15 @@ export const enum RoutePaths {
4242
export const MAX_FILE_SIZE = 1.5 * 1024 * 1024
4343
export const DURATION = 60 * 60 * 24
4444

45+
// Chains that supported by the intersection of SimpleHash, Chainbase, and our deployed chains.
4546
export const NFT_DEFAULT_CHAINS = [
4647
ChainId.Mainnet,
4748
ChainId.BSC,
4849
ChainId.Polygon,
4950
ChainId.Arbitrum,
50-
ChainId.xDai,
51-
ChainId.Fantom,
5251
ChainId.Avalanche,
53-
ChainId.Celo,
5452
ChainId.Optimism,
55-
ChainId.Aurora,
56-
ChainId.Fuse,
57-
ChainId.Boba,
58-
ChainId.Moonriver,
59-
ChainId.Conflux,
60-
ChainId.Harmony,
61-
ChainId.Metis,
62-
ChainId.Astar,
6353
ChainId.Base,
64-
ChainId.Scroll,
65-
ChainId.XLayer,
66-
ChainId.Sei,
6754
]
6855

6956
function createTheme(themeId: string, cover: string): FireflyRedPacketAPI.ThemeGroupSettings {

packages/web3-providers/src/Chainbase/apis/RedPacketAPI.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type { RedPacketBaseAPI } from '../../entry-types.js'
1515

1616
export class ChainbaseRedPacketAPI implements RedPacketBaseAPI.Provider<ChainId, SchemaType> {
1717
/**
18-
* @see https://docs.chainbase.com/reference/supported-chains
18+
* @see https://docs.chainbase.com/platform/supported-networks/supported-networks
1919
*/
2020
static isSupportedChain(chainId: ChainId) {
2121
const supported = [
@@ -25,9 +25,14 @@ export class ChainbaseRedPacketAPI implements RedPacketBaseAPI.Provider<ChainId,
2525
ChainId.Avalanche,
2626
ChainId.Arbitrum,
2727
ChainId.Base,
28+
ChainId.Optimism,
2829
/** zkSync */ 324,
2930
].includes(chainId)
30-
console.error('Unsupported chain by ChainBase, see https://docs.chainbase.com/reference/supported-chains')
31+
if (process.env.NODE_ENV === 'development' && !supported) {
32+
console.error(
33+
`Unsupported chain ${chainId} by Chainbase\n, see https://docs.chainbase.com/platform/supported-networks/supported-networks`,
34+
)
35+
}
3136
return supported
3237
}
3338
static async getHistoryTransactions(

packages/web3-shared/evm/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ export enum ChainId {
5050
xDai = 100,
5151

5252
// Avalanche
53+
/** C-Chain */
5354
Avalanche = 43114,
5455
Avalanche_Fuji = 43113,
5556

0 commit comments

Comments
 (0)