Skip to content

Commit

Permalink
fix: resend rp on solana (#12052)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuanyang233 authored Jan 21, 2025
1 parent 2a7b58e commit 343f4b8
Show file tree
Hide file tree
Showing 14 changed files with 108 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function useSubmit(onClose: () => void, reason: 'timeline' | 'popup' | 'r
// Don't await this, otherwise the dialog won't disappear
activatedSiteAdaptorUI?.automation.nativeCompositionDialog?.attachImage?.(mediaObject, {
recover: true,
relatedTextPayload: decoratedText || defaultText,
relatedTextPayload: `${decoratedText || defaultText} #MaskLuckyDrop`,
reason,
})
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ export function CreateSolRedPacket() {

if (!token) return null

const messageMaxLength = isFirefly ? 40 : 100
const messageMaxLength = 200

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { createWithSplToken } from '../helpers/createWithSplToken.js'
import { getTokenProgram } from '../helpers/getTokenAccount.js'
import { useEstimateGasWithCreateSolRedpacket } from '../hooks/useEstimateGasWithCreateSolRedpacket.js'
import { useHandleSolanaCreateOrSelect } from '../hooks/useHandleSolanaCreateOrSelect.js'
import { RedPacketRPC } from '../../messages.js'

const useStyles = makeStyles()((theme) => ({
message: {
Expand Down Expand Up @@ -191,6 +192,14 @@ export function SolanaRedPacketConfirm() {
tokenProgram: tokenProgram?.toBase58(),
}

RedPacketRPC.addRedPacket({
chainId,
id: result.accountId.toBase58(),
from: '',
password,
contract_version: 4,
payload,
})
handleCreated(payload)
}, [isNativeToken, settings, isRandom, publicKey, message, creator, theme])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ interface Props extends ActionButtonProps {
/** timestamp in seconds */
createdAt?: number
canResend?: boolean

canSend?: boolean
onResend?(): void
}

Expand All @@ -77,6 +79,7 @@ export const RedPacketActionButton = memo(function RedPacketActionButton({
createdAt,
canResend,
onResend,
canSend,
...rest
}: Props) {
const { classes, cx } = useStyles()
Expand Down Expand Up @@ -132,7 +135,7 @@ export const RedPacketActionButton = memo(function RedPacketActionButton({
await shareCallback()
else if (redpacketStatus === RedPacketStatus.Refunding)
pluginID === NetworkPluginID.PLUGIN_SOLANA ? await refundSolanaCallback() : await refundCallback()
}, [redpacketStatus, shareCallback, refundCallback, canResend, onResend, refundSolanaCallback, pluginID])
}, [redpacketStatus, shareCallback, refundCallback, canResend, onResend, refundSolanaCallback, pluginID, canSend])

return (
<ActionButton
Expand All @@ -147,7 +150,11 @@ export const RedPacketActionButton = memo(function RedPacketActionButton({
redpacketStatus === RedPacketStatus.Refund
}
size="large">
<span>{statusToTransMap[redpacketStatus]}</span>
<span>
{canSend ?
<Trans>Send</Trans>
: statusToTransMap[redpacketStatus]}
</span>
</ActionButton>
)
})
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,14 @@ export const RedPacketRecord = memo(function RedPacketRecord({
const tokenSymbol = token_symbol
const contractAddress = useRedPacketConstant(chainId, 'HAPPY_RED_PACKET_ADDRESS_V4')
const { data: redpacketRecord } = useQuery({
queryKey: ['redpacket', 'by-tx-hash', history.trans_hash],
queryFn: history.trans_hash ? () => RedPacketRPC.getRedPacketRecord(history.trans_hash!) : skipToken,
queryKey: ['redpacket', 'by-tx-hash', pluginID, history.trans_hash],
queryFn:
history.trans_hash ?
() =>
RedPacketRPC.getRedPacketRecord(
pluginID === NetworkPluginID.PLUGIN_SOLANA ? history.redpacket_id : history.trans_hash!,
)
: skipToken,
})
const { data: createSuccessResult } = useCreateRedPacketReceipt(
pluginID === NetworkPluginID.PLUGIN_SOLANA ? history.redpacket_id : (history.trans_hash ?? ''),
Expand All @@ -227,7 +233,8 @@ export const RedPacketRecord = memo(function RedPacketRecord({

const isViewStatus = redpacket_status === FireflyRedPacketAPI.RedPacketStatus.View
const canResend = isViewStatus && !!redpacketRecord && !!createSuccessResult

// TODO: remove this after the Solana redpacket is integrated into the backend.
const canSend = !!isViewStatus && pluginID === NetworkPluginID.PLUGIN_SOLANA && !!redpacketRecord
const timestamp = create_time || (received_time ? +received_time : undefined)

// Claimed amount or total amount of the red packet
Expand Down Expand Up @@ -319,38 +326,43 @@ export const RedPacketRecord = memo(function RedPacketRecord({
totalAmount={total_amounts}
createdAt={create_time}
canResend={canResend}
canSend={canSend}
onResend={() => {
if (!canResend) return
onSelect?.({
txid: history.trans_hash,
contract_address: contractAddress!,
rpid: history.redpacket_id,
shares: history.total_numbers ? +history.total_numbers : 1,
is_random: createSuccessResult.ifrandom,
creation_time: history.create_time!,
contract_version: 4,
sender: {
address: account,
name: createSuccessResult.name,
message: createSuccessResult.message,
},
total: history.total_amounts ?? '0',
duration: +createSuccessResult.duration,
token: {
type: TokenType.Fungible,
schema:
isNativeTokenAddress(createSuccessResult.token_address) ?
SchemaType.Native
: SchemaType.ERC20,
id: createSuccessResult.token_address,
chainId: history.chain_id,
address: createSuccessResult.token_address,
symbol: history.token_symbol,
decimals: history.token_decimal,
name: history.token_symbol,
},
password: redpacketRecord.password,
})
if (canSend && redpacketRecord.payload) {
onSelect?.(redpacketRecord.payload)
} else {
if (!canResend) return
onSelect?.({
txid: history.trans_hash,
contract_address: contractAddress!,
rpid: history.redpacket_id,
shares: history.total_numbers ? +history.total_numbers : 1,
is_random: createSuccessResult.ifrandom,
creation_time: history.create_time!,
contract_version: 4,
sender: {
address: account,
name: createSuccessResult.name,
message: createSuccessResult.message,
},
total: history.total_amounts ?? '0',
duration: +createSuccessResult.duration,
token: {
type: TokenType.Fungible,
schema:
isNativeTokenAddress(createSuccessResult.token_address) ?
SchemaType.Native
: SchemaType.ERC20,
id: createSuccessResult.token_address,
chainId: history.chain_id,
address: createSuccessResult.token_address,
symbol: history.token_symbol,
decimals: history.token_decimal,
name: history.token_symbol,
},
password: redpacketRecord.password,
})
}
}}
/>
: null}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { t } from '@lingui/core/macro'
import { ApplicationBoardModal } from '@masknet/shared'
import { RedPacketMetaKey, type NetworkPluginID } from '@masknet/shared-base'
import { useChainContext } from '@masknet/web3-hooks-base'
Expand Down Expand Up @@ -50,20 +49,11 @@ export function useHandleCreateOrSelect({ senderName, onClose }: Options) {
payload.sender.name === senderName
}

const post = t`Hi friends, I just created a token Lucky Drop. Download mask.io to claim. Follow @realMaskNetwork for Web3 updates and insights.
🧧🧧🧧 Try sending Lucky Drop to your friends with Mask io.`
openComposition(
RedPacketMetaKey,
reduceUselessPayloadInfo(payload),
compositionType,
{
payloadImage,
claimRequirements,
publicKey,
},
post,
)
openComposition(RedPacketMetaKey, reduceUselessPayloadInfo(payload), compositionType, {
payloadImage,
claimRequirements,
publicKey,
})
Telemetry.captureEvent(EventType.Access, EventID.EntryAppLuckCreate)
ApplicationBoardModal.close()
onClose?.()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { t } from '@lingui/core/macro'
import { ApplicationBoardModal } from '@masknet/shared'
import { SolanaRedPacketMetaKey } from '@masknet/shared-base'
import type { FireflyRedPacketAPI, RedPacketJSONPayload } from '@masknet/web3-providers/types'
Expand Down Expand Up @@ -27,20 +26,11 @@ export function useHandleSolanaCreateOrSelect({ senderName, onClose }: Options)
payload.sender.name === senderName
}

const post = t`Hi friends, I just created a token Lucky Drop. Download mask.io to claim. Follow @realMaskNetwork for Web3 updates and insights.
🧧🧧🧧 Try sending Lucky Drop to your friends with Mask io.`
openComposition(
SolanaRedPacketMetaKey,
reduceUselessPayloadInfo(payload),
compositionType,
{
payloadImage,
claimRequirements,
publicKey,
},
post,
)
openComposition(SolanaRedPacketMetaKey, reduceUselessPayloadInfo(payload), compositionType, {
payloadImage,
claimRequirements,
publicKey,
})
Telemetry.captureEvent(EventType.Access, EventID.EntryAppLuckCreate)
ApplicationBoardModal.close()
onClose?.()
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/RedPacket/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const RED_PACKET_MAX_SHARES = 255

export const SOL_REDPACKET_MAX_SHARES = 200
export const SOL_REDPACKET_CREATE_DEFAULT_GAS = '1000000'
export const DEFAULT_DURATION = 1000 * 60 * 60 * 24 // 24 hours
export const DEFAULT_DURATION = 60 * 60 * 24 // 24 hours
export const enum RoutePaths {
Create = '/create',
CreateErc20RedPacket = '/create/erc20',
Expand Down
11 changes: 6 additions & 5 deletions packages/plugins/RedPacket/src/locale/en-US.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions packages/plugins/RedPacket/src/locale/ja-JP.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions packages/plugins/RedPacket/src/locale/ko-KR.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions packages/plugins/RedPacket/src/locale/zh-CN.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions packages/plugins/RedPacket/src/locale/zh-TW.po

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/web3-providers/src/RedPacket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface RedPacketRecord {
from: string
password?: string
contract_version: number
payload?: RedPacketJSONPayload
}

export interface RedPacketRecordInDatabase extends RedPacketRecord {
Expand Down

0 comments on commit 343f4b8

Please sign in to comment.