Skip to content

Commit

Permalink
fix: mf-6588 resend evm redpacket
Browse files Browse the repository at this point in the history
  • Loading branch information
swkatmask committed Jan 23, 2025
1 parent c98b787 commit 3377abb
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { Trans } from '@lingui/react/macro'
import { RoutePaths } from '@masknet/plugin-redpacket'
import { ApplicationBoardModal } from '@masknet/shared'
import { NetworkPluginID, RedPacketMetaKey } from '@masknet/shared-base'
import { ActionButton, makeStyles, type ActionButtonProps } from '@masknet/theme'
import { useEnvironmentContext } from '@masknet/web3-hooks-base'
import { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import type { ChainId } from '@masknet/web3-shared-evm'
import { useMediaQuery, type Theme } from '@mui/material'
import { type ChainId as SolanaChainId } from '@masknet/web3-shared-solana'
import { useMediaQuery, type Theme } from '@mui/material'
import { memo, useCallback, useContext } from 'react'
import { useNavigate } from 'react-router-dom'
import { useAsyncFn } from 'react-use'
import { CompositionTypeContext } from '../contexts/CompositionTypeContext.js'
import { useRefundCallback, useSolanaRefundCallback } from '../hooks/useRefundCallback.js'
import { openComposition } from '../openComposition.js'
import { useEnvironmentContext } from '@masknet/web3-hooks-base'
import { useNavigate } from 'react-router-dom'
import { RoutePaths } from '@masknet/plugin-redpacket'
import { ApplicationBoardModal } from '@masknet/shared'
import type { HistoryInfo } from '../../types.js'

const useStyles = makeStyles()((theme) => {
const smallQuery = `@media (max-width: ${theme.breakpoints.values.sm}px)`
Expand Down Expand Up @@ -47,6 +48,7 @@ interface TokenInfo {
symbol: string
decimals: number
amount?: string
address: string
}
const RedPacketStatus = FireflyRedPacketAPI.RedPacketStatus

Expand All @@ -57,7 +59,9 @@ interface Props extends ActionButtonProps {
claim_strategy?: FireflyRedPacketAPI.StrategyPayload[]
shareFrom?: string
themeId?: string
isRandom: boolean
tokenInfo: TokenInfo
history: HistoryInfo
redpacketMsg?: string
chainId: ChainId | SolanaChainId
totalAmount?: string
Expand All @@ -76,7 +80,9 @@ export const RedPacketActionButton = memo(function RedPacketActionButton({
claim_strategy,
shareFrom,
themeId,
isRandom,
tokenInfo,
history,
redpacketMsg,
chainId,
totalAmount,
Expand Down Expand Up @@ -126,18 +132,36 @@ export const RedPacketActionButton = memo(function RedPacketActionButton({
chainId,
symbol: tokenInfo.symbol,
decimals: tokenInfo.decimals,
address: tokenInfo.address,
},
contract_address: rpid,
rpid,
shares: totalAmount,
shares: history.total_numbers ? +history.total_numbers : 5,
total: tokenInfo.amount,
is_random: isRandom,
duration: history.duration,
},
compositionType,
{ claimRequirements: claim_strategy },
)
ApplicationBoardModal.close()
navigate(RoutePaths.Exit)
}, [navigate])
}, [
navigate,
account,
shareFrom,
themeId,
createdAt,
tokenInfo.amount,
tokenInfo.address,
compositionType,
claim_strategy,
rpid,
totalAmount,
isRandom,
redpacketMsg,
chainId,
])

const redpacketStatus = refunded || solanaRefunded ? RedPacketStatus.Refund : propRedpacketStatus

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { t } from '@lingui/core/macro'
import { Trans } from '@lingui/react/macro'
import { TokenIcon } from '@masknet/shared'
import { NetworkPluginID } from '@masknet/shared-base'
import { openWindow, useEverSeen } from '@masknet/shared-base-ui'
import { ActionButton, makeStyles, ShadowRootTooltip, TextOverflowTooltip } from '@masknet/theme'
import {
Expand All @@ -26,10 +27,10 @@ import { memo, useCallback } from 'react'
import { useNavigate } from 'react-router-dom'
import { RoutePaths } from '../../constants.js'
import { RedPacketRPC } from '../../messages.js'
import type { HistoryInfo } from '../../types.js'
import { formatTokenAmount } from '../helpers/formatTokenAmount.js'
import { useCreateRedPacketReceipt } from '../hooks/useCreateRedPacketReceipt.js'
import { RedPacketActionButton } from './RedPacketActionButton.js'
import { formatTokenAmount } from '../helpers/formatTokenAmount.js'
import { NetworkPluginID } from '@masknet/shared-base'

const DEFAULT_BACKGROUND = NETWORK_DESCRIPTORS.find((x) => x.chainId === ChainId.Mainnet)!.backgroundGradient!
const useStyles = makeStyles<{ background?: string; backgroundIcon?: string }>()((
Expand Down Expand Up @@ -150,29 +151,6 @@ const useStyles = makeStyles<{ background?: string; backgroundIcon?: string }>()
}
})

interface HistoryInfo {
rp_msg: string
redpacket_id: string
received_time?: string
token_decimal: number
total_amounts?: string
token_symbol: string
token_amounts?: string
token_logo: string
chain_id: number
creator?: string
claim_numbers?: string
total_numbers?: string
claim_amounts?: string
create_time?: number
redpacket_status?: FireflyRedPacketAPI.RedPacketStatus
ens_name?: string
claim_strategy?: FireflyRedPacketAPI.StrategyPayload[]
share_from?: string
theme_id?: string
trans_hash: string
}

interface RedPacketRecordProps {
history: HistoryInfo
showDetailLink?: boolean
Expand Down Expand Up @@ -351,7 +329,7 @@ export const RedPacketRecord = memo(function RedPacketRecord({
}}>
{t`View`}
</ActionButton>
: redpacket_status && !(isViewStatus && !redpacketRecord) ?
: redpacket_status && !(isViewStatus && !redpacketRecord) && createSuccessResult ?
<RedPacketActionButton
className={classes.actionButton}
redpacketStatus={redpacket_status}
Expand All @@ -361,11 +339,15 @@ export const RedPacketRecord = memo(function RedPacketRecord({
shareFrom={share_from}
themeId={theme_id}
redpacketMsg={rp_msg}
isRandom={createSuccessResult.ifrandom}
duration={history.duration}
tokenInfo={{
symbol: tokenSymbol,
decimals: token_decimal,
amount: total_amounts,
address: createSuccessResult.token_address,
}}
history={history}
chainId={chainId}
totalAmount={total_amounts}
createdAt={create_time}
Expand Down
25 changes: 25 additions & 0 deletions packages/plugins/RedPacket/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { BN, web3 } from '@coral-xyz/anchor'
import type { FireflyRedPacketAPI } from '@masknet/web3-providers/types'
import type { NonFungibleToken } from '@masknet/web3-shared-base'
import type { ChainId, SchemaType } from '@masknet/web3-shared-evm'

Expand Down Expand Up @@ -84,3 +85,27 @@ export interface RedPacketAccount {
claimedUsers: web3.PublicKey[] // List of users who claimed
claimedAmountRecords: BN[] // List of claimed amounts
}

export interface HistoryInfo {
rp_msg: string
redpacket_id: string
received_time?: string
token_decimal: number
total_amounts?: string
token_symbol: string
token_amounts?: string
token_logo: string
chain_id: number
creator?: string
claim_numbers?: string
total_numbers?: string
claim_amounts?: string
create_time?: number
redpacket_status?: FireflyRedPacketAPI.RedPacketStatus
ens_name?: string
claim_strategy?: FireflyRedPacketAPI.StrategyPayload[]
share_from?: string
theme_id?: string
trans_hash: string
duration: number
}

0 comments on commit 3377abb

Please sign in to comment.