Skip to content

Commit a51b91f

Browse files
authored
chore: update solana redpacket idl (#12055)
1 parent 2841268 commit a51b91f

File tree

25 files changed

+137
-95
lines changed

25 files changed

+137
-95
lines changed

cspell.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,5 +240,5 @@
240240
],
241241
"ignoreRegExpList": ["/[A-Za-z0-9]{44}/", "/[A-Za-z0-9]{46}/", "/[A-Za-z0-9]{59}/"],
242242
"overrides": [],
243-
"words": ["cashtags", "endregion", "linkedin", "luma", "muln", "tiktok", "tweetnacl", "waitlist", "youtube"]
243+
"words": ["cashtags", "endregion", "linkedin", "luma", "muln", "tiktok", "tweetnacl", "txid", "waitlist", "youtube"]
244244
}

packages/mask/content-script/components/CompositionDialog/Composition.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@ import { useAsync } from 'react-use'
33
import { DialogContent, alpha } from '@mui/material'
44
import { makeStyles } from '@masknet/theme'
55
import { useCurrentPersonaConnectStatus, InjectedDialog, PersonaAction } from '@masknet/shared'
6-
import { CrossIsolationMessages, EMPTY_OBJECT, MaskMessages, currentPersonaIdentifier } from '@masknet/shared-base'
6+
import {
7+
CrossIsolationMessages,
8+
EMPTY_OBJECT,
9+
MaskMessages,
10+
RedPacketMetaKey,
11+
SolanaRedPacketMetaKey,
12+
currentPersonaIdentifier,
13+
} from '@masknet/shared-base'
714
import { useValueRef } from '@masknet/shared-base-ui'
815
import { Telemetry } from '@masknet/web3-telemetry'
916
import { EventID, EventType } from '@masknet/web3-telemetry/types'
@@ -110,7 +117,8 @@ export function Composition({ type = 'timeline', requireClipboardPermission }: P
110117
})
111118
}, [open])
112119

113-
const onSubmit_ = useSubmit(onClose, reason)
120+
const hasRedpacket = Object.keys(initialMeta).some((x) => [RedPacketMetaKey, SolanaRedPacketMetaKey].includes(x))
121+
const onSubmit_ = useSubmit(onClose, reason, hasRedpacket)
114122

115123
const UI = useRef<CompositionRef>(null)
116124
const networkSupport = activatedSiteAdaptorUI!.injection.newPostComposition?.supportedOutputTypes

packages/mask/content-script/components/CompositionDialog/useSubmit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { SteganographyPayload } from './SteganographyPayload.js'
1919
import { msg } from '@lingui/core/macro'
2020
import { useLingui, type I18nContext } from '@lingui/react'
2121

22-
export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'reply') {
22+
export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'reply', hasRedpacket?: boolean) {
2323
const { _ } = useLingui()
2424
const lastRecognizedIdentity = useLastRecognizedIdentity()
2525

@@ -63,7 +63,7 @@ export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'r
6363
// Don't await this, otherwise the dialog won't disappear
6464
activatedSiteAdaptorUI?.automation.nativeCompositionDialog?.attachImage?.(mediaObject, {
6565
recover: true,
66-
relatedTextPayload: `${decoratedText || defaultText} #MaskLuckyDrop`,
66+
relatedTextPayload: `${decoratedText || defaultText} ${hasRedpacket ? '#MaskLuckyDrop' : ''}`,
6767
reason,
6868
})
6969
} else {

packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/SolanaRedPacketFrame.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@ export function SolanaRedPacketFrame({ payload }: Omit<SolanaRedPacketCardProps,
1515
if (draft.token) {
1616
draft.token.runtime = NetworkPluginID.PLUGIN_SOLANA
1717
}
18-
if (!draft.accountId) {
19-
draft.accountId = draft.rpid.replace(/^solana-/, '')
20-
}
21-
draft.network = 'devnet'
18+
draft.accountId = draft.rpid
2219
})
2320
}, [payload])
2421
const payloadChainId =

packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedPacket/hooks/useAvailability.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ export function useSolanaAvailability(payload: SolanaRedPacketJSONPayload, chain
1212
const account = useAccount(NetworkPluginID.PLUGIN_SOLANA)
1313

1414
const { data, refetch: checkAvailability } = useQuery({
15-
queryKey: ['red-packet', 'solana-availability', payload.accountId, payload.network],
15+
queryKey: ['red-packet', 'solana-availability', payload.rpid, payload.network],
1616
queryFn: async () => {
17-
if (!payload.accountId) return null
17+
if (!payload.rpid) return null
1818
const program = await getRpProgram(payload.network)
19-
const result = await program.account.redPacket.fetch(payload.accountId)
19+
const result = await program.account.redPacket.fetch(payload.rpid)
2020
return result
2121
},
2222
refetchInterval(query) {
@@ -32,7 +32,7 @@ export function useSolanaAvailability(payload: SolanaRedPacketJSONPayload, chain
3232

3333
const { data: claimRecord, refetch: checkClaimRecord } = useClaimRecord(
3434
account,
35-
payload.accountId,
35+
payload.rpid,
3636
payload?.network ?? 'mainnet-beta',
3737
)
3838
const refresh = useCallback(() => {

packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedpacketDialog/CreateRedpacket.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Trans } from '@lingui/react/macro'
21
import { msg } from '@lingui/core/macro'
32
import { useLingui } from '@lingui/react'
3+
import { Trans } from '@lingui/react/macro'
44
import { Icons } from '@masknet/icons'
55
import {
66
FormattedBalance,
@@ -11,9 +11,10 @@ import {
1111
useAvailableBalance,
1212
WalletConnectedBoundary,
1313
} from '@masknet/shared'
14-
import { EnhanceableSite, getEnhanceableSiteType, NetworkPluginID } from '@masknet/shared-base'
14+
import { NetworkPluginID } from '@masknet/shared-base'
1515
import { ActionButton, makeStyles, RadioIndicator } from '@masknet/theme'
1616
import { useChainContext, useEnvironmentContext, useNativeTokenPrice } from '@masknet/web3-hooks-base'
17+
import { SolanaChainResolver } from '@masknet/web3-providers'
1718
import {
1819
formatBalance,
1920
formatCurrency,
@@ -24,17 +25,18 @@ import {
2425
rightShift,
2526
ZERO,
2627
} from '@masknet/web3-shared-base'
27-
import { isNativeTokenAddress, type ChainId, type SchemaType } from '@masknet/web3-shared-solana'
28+
import { type ChainId, isNativeTokenAddress, type SchemaType } from '@masknet/web3-shared-solana'
2829
import { alpha, Box, InputBase, inputBaseClasses, Typography, useTheme } from '@mui/material'
30+
import type { Cluster } from '@solana/web3.js'
2931
import { BigNumber } from 'bignumber.js'
3032
import { type ChangeEvent, useCallback, useMemo } from 'react'
3133
import { useNavigate } from 'react-router-dom'
3234
import {
3335
MAX_CUSTOM_THEMES,
34-
SOL_REDPACKET_MAX_SHARES,
3536
RED_PACKET_MIN_SHARES,
3637
RoutePaths,
3738
SOL_REDPACKET_CREATE_DEFAULT_GAS,
39+
SOL_REDPACKET_MAX_SHARES,
3840
} from '../../constants.js'
3941
import { PreviewRedPacket } from '../components/PreviewRedPacket.js'
4042
import { useSolRedpacket } from '../contexts/SolRedpacketContext.js'
@@ -172,9 +174,7 @@ const useStyles = makeStyles()((theme) => ({
172174

173175
export function CreateSolRedPacket() {
174176
const { _ } = useLingui()
175-
const { account } = useChainContext()
176-
const { chainId, setChainId } = useChainContext()
177-
const isFirefly = getEnhanceableSiteType() === EnhanceableSite.Firefly
177+
const { account, chainId, setChainId } = useChainContext<NetworkPluginID.PLUGIN_SOLANA>()
178178
const { classes, cx } = useStyles()
179179
const theme = useTheme()
180180
const navigate = useNavigate()
@@ -243,6 +243,7 @@ export function CreateSolRedPacket() {
243243
const totalAmount = multipliedBy(amount, isRandom ? 1 : (shares ?? '0'))
244244
const minTotalAmount = new BigNumber(isRandom ? 1 : (shares ?? 0))
245245
const isDivisible = !totalAmount.dividedBy(shares).isLessThan(1)
246+
const cluster = SolanaChainResolver.network(chainId) as Cluster
246247

247248
// balance
248249
const { data: defaultGasFee = ZERO, isFetching: estimateGasLoading } = useEstimateGasWithCreateSolRedpacket(
@@ -254,6 +255,7 @@ export function CreateSolRedPacket() {
254255
message,
255256
creator,
256257
token,
258+
cluster,
257259
)
258260

259261
const gasFee = defaultGasFee.multipliedBy(isNativeTokenAddress(token?.address) ? 5 : 10)

packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedpacketDialog/MainDialog.tsx

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { DialogContent } from '@mui/material'
33
import { MemoryRouter } from 'react-router-dom'
44

55
import { RestorableScrollContext } from '@masknet/shared'
6-
import { SOLWeb3ContextProvider } from '@masknet/web3-hooks-base'
76
import { RoutePaths } from '../../constants.js'
87
import { RouterDialog } from '../components/RouterDialog.js'
98
import { SolRedPacketRoutes } from './Routes.js'
109
import { SOLRedPacketProvider } from '../contexts/SolRedpacketContext.js'
1110
import { RedPacketTabs } from '../../types.js'
12-
import { ChainId } from '@masknet/web3-shared-solana'
1311

1412
interface RedPacketDialogProps {
1513
onClose: () => void
@@ -48,27 +46,25 @@ export function SolRedPacketMainDialog({ onClose }: RedPacketDialogProps) {
4846

4947
return (
5048
<MemoryRouter initialEntries={initialEntries} initialIndex={initialIndex}>
51-
<SOLWeb3ContextProvider chainId={ChainId.Devnet}>
52-
<SOLRedPacketProvider>
53-
<RouterDialog
54-
pageMap={{
55-
[RedPacketTabs.tokens]: RoutePaths.CreateSolanaRedPacket,
56-
[RedPacketTabs.collectibles]: RoutePaths.CreateNftRedPacket,
57-
}}
58-
open
59-
onClose={onClose}
60-
classes={{ paper: classes.paper }}
61-
maxWidth="xs"
62-
fullWidth
63-
independent>
64-
<DialogContent className={classes.content}>
65-
<RestorableScrollContext>
66-
<SolRedPacketRoutes />
67-
</RestorableScrollContext>
68-
</DialogContent>
69-
</RouterDialog>
70-
</SOLRedPacketProvider>
71-
</SOLWeb3ContextProvider>
49+
<SOLRedPacketProvider>
50+
<RouterDialog
51+
pageMap={{
52+
[RedPacketTabs.tokens]: RoutePaths.CreateSolanaRedPacket,
53+
[RedPacketTabs.collectibles]: RoutePaths.CreateNftRedPacket,
54+
}}
55+
open
56+
onClose={onClose}
57+
classes={{ paper: classes.paper }}
58+
maxWidth="xs"
59+
fullWidth
60+
independent>
61+
<DialogContent className={classes.content}>
62+
<RestorableScrollContext>
63+
<SolRedPacketRoutes />
64+
</RestorableScrollContext>
65+
</DialogContent>
66+
</RouterDialog>
67+
</SOLRedPacketProvider>
7268
</MemoryRouter>
7369
)
7470
}

packages/plugins/RedPacket/src/SiteAdaptor/SolanaRedpacketDialog/RedpacketConfirm.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export function SolanaRedPacketConfirm() {
124124
})
125125
}, [settings, isNativeToken])
126126

127+
const cluster = SolanaChainResolver.network(chainId) as SolanaWeb3.Cluster
127128
const { data: defaultGasFee = ZERO, isLoading: estimateLoading } = useEstimateGasWithCreateSolRedpacket(
128129
shares,
129130
new BigNumber(settings.total).toNumber(),
@@ -132,6 +133,7 @@ export function SolanaRedPacketConfirm() {
132133
message,
133134
creator,
134135
token,
136+
cluster,
135137
)
136138

137139
const gasFee = defaultGasFee.multipliedBy(isNativeToken ? 5 : 10)
@@ -142,7 +144,7 @@ export function SolanaRedPacketConfirm() {
142144
const claimer = new SolanaWeb3.PublicKey(publicKey)
143145
const total = new BigNumber(settings.total).toNumber()
144146
const tokenMint = token?.address ? new SolanaWeb3.PublicKey(token.address) : null
145-
const tokenProgram = tokenMint ? await getTokenProgram(tokenMint) : undefined
147+
const tokenProgram = tokenMint ? await getTokenProgram(tokenMint, cluster) : undefined
146148

147149
const result = await (isNativeToken ?
148150
createWithNativeToken(
@@ -154,6 +156,7 @@ export function SolanaRedPacketConfirm() {
154156
claimer,
155157
creator,
156158
message,
159+
cluster,
157160
)
158161
: tokenMint ?
159162
createWithSplToken(
@@ -166,6 +169,7 @@ export function SolanaRedPacketConfirm() {
166169
claimer,
167170
creator,
168171
message,
172+
cluster,
169173
)
170174
: null)
171175
if (!result) return
@@ -185,7 +189,7 @@ export function SolanaRedPacketConfirm() {
185189
duration: DEFAULT_DURATION,
186190
creation_time: Date.now(),
187191
token,
188-
network: SolanaChainResolver.network(chainId),
192+
network: cluster,
189193
contract_address: idl.address,
190194
contract_version: 4,
191195
txid: result.signature,

packages/plugins/RedPacket/src/SiteAdaptor/helpers/createWithNativeToken.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { BN, web3 } from '@coral-xyz/anchor'
2+
import { ZERO } from '@masknet/web3-shared-base'
3+
import type { Cluster } from '@solana/web3.js'
4+
import { BigNumber } from 'bignumber.js'
25
import { getRpProgram } from './getRpProgram.js'
36
import { getSolanaConnection } from './getSolanaProvider.js'
4-
import { BigNumber } from 'bignumber.js'
5-
import { ZERO } from '@masknet/web3-shared-base'
67

78
const MAX_NUM = 200 // Maximum number of red packets (constant)
89

@@ -16,13 +17,14 @@ export async function createWithNativeToken(
1617
pubkeyForClaimSignature: web3.PublicKey, // Public key to be used for claim signature
1718
author: string, // Author of the red packet
1819
message: string, // Message to be included in the red packet
20+
cluster: Cluster | undefined,
1921
) {
2022
// Ensure the totalNumber and totalAmount are within the acceptable range
2123
if (totalNumber > MAX_NUM) {
2224
throw new Error(`Total number of red packets cannot exceed ${MAX_NUM}`)
2325
}
2426

25-
const program = await getRpProgram()
27+
const program = await getRpProgram(cluster)
2628

2729
const createTime = Math.floor(Date.now() / 1000)
2830
const nativeTokenRedPacket = web3.PublicKey.findProgramAddressSync(
@@ -66,10 +68,11 @@ export async function getEstimatedGasByCreateWithNativeToken(
6668
pubkeyForClaimSignature: web3.PublicKey,
6769
message: string,
6870
author: string,
71+
cluster: Cluster | undefined,
6972
): Promise<BigNumber> {
70-
const program = await getRpProgram()
73+
const program = await getRpProgram(cluster)
7174
const createTime = Math.floor(Date.now() / 1000)
72-
const connection = await getSolanaConnection('devnet')
75+
const connection = await getSolanaConnection(cluster)
7376

7477
const transaction = await program.methods
7578
.createRedPacketWithNativeToken(

packages/plugins/RedPacket/src/SiteAdaptor/helpers/createWithSplToken.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { BN, web3 } from '@coral-xyz/anchor'
22
import { ZERO } from '@masknet/web3-shared-base'
33
import { ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token'
4+
import type { Cluster } from '@solana/web3.js'
45
import { BigNumber } from 'bignumber.js'
56
import { getRpProgram } from './getRpProgram.js'
67
import { getSolanaConnection } from './getSolanaProvider.js'
@@ -17,18 +18,19 @@ export async function createWithSplToken(
1718
pubkeyForClaimSignature: web3.PublicKey,
1819
author: string,
1920
message: string,
21+
cluster: Cluster | undefined,
2022
) {
2123
// Ensure the totalNumber and totalAmount are within the acceptable range
2224
if (totalNumber > MAX_NUM) {
2325
throw new Error(`Total number of red packets cannot exceed ${MAX_NUM}`)
2426
}
2527

26-
const program = await getRpProgram()
28+
const program = await getRpProgram(cluster)
2729

28-
const tokenAccount = await getTokenAccount(tokenMint)
30+
const tokenAccount = await getTokenAccount(tokenMint, cluster)
2931
if (!tokenAccount) throw new Error('Token account not found')
3032

31-
const tokenProgram = await getTokenProgram(tokenMint)
33+
const tokenProgram = await getTokenProgram(tokenMint, cluster)
3234
if (!tokenProgram) throw new Error('Token program not found')
3335

3436
const createTime = Math.floor(Date.now() / 1000)
@@ -81,20 +83,21 @@ export async function getEstimatedGasByCreateWithSplToken(
8183
pubkeyForClaimSignature: web3.PublicKey,
8284
message: string,
8385
author: string,
86+
cluster: Cluster | undefined,
8487
) {
8588
// Ensure the totalNumber and totalAmount are within the acceptable range
8689
if (totalNumber > MAX_NUM) {
8790
throw new Error(`Total number of red packets cannot exceed ${MAX_NUM}`)
8891
}
8992

90-
const program = await getRpProgram()
93+
const program = await getRpProgram(cluster)
9194

9295
const connection = await getSolanaConnection('devnet')
9396

94-
const tokenAccount = await getTokenAccount(tokenMint)
97+
const tokenAccount = await getTokenAccount(tokenMint, cluster)
9598
if (!tokenAccount) throw new Error('Token account not found')
9699

97-
const tokenProgram = await getTokenProgram(tokenMint)
100+
const tokenProgram = await getTokenProgram(tokenMint, cluster)
98101
if (!tokenProgram) throw new Error('Token program not found')
99102

100103
const createTime = Math.floor(Date.now() / 1000)

0 commit comments

Comments
 (0)