Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/mask/shared-ui/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,15 @@
"plugin_red_packet_hint": "You can withdraw the remaining balance 24 hours after the Lucky Drop is sent.",
"plugin_red_packet_token": "Token",
"plugin_red_packet_message_label": "Title",
"plugin_red_packet_create_with_token": "Creating Lucky Drop with {{symbol}}",
"plugin_red_packet_create": "Create a Lucky Drop",
"plugin_red_packet_create_with_token": "Create a Lucky Drop with {{amount}} {{symbol}}",
"plugin_red_packet_history_duration": "Time: {{startTime}} ~ {{endTime}} (UTC+8)",
"plugin_red_packet_history_total_amount": "Total Amount: {{amount}} {{symbol}}",
"plugin_red_packet_history_total_claimed_amount": "Total: <span><strong>{{claimedAmount}}/{{amount}}</strong></span> {{symbol}}",
"plugin_red_packet_history_claimed": "Claimed: <strong>{{claimedShares}}/{{shares}}</strong> Share",
"plugin_red_packet_history_split_mode": "Split Mode: {{mode}}",
"plugin_red_packet_history_send": "Send",
"plugin_nft_red_packet_create": "Create an NFT Lucky Drop",
"plugin_red_packet_nft_account_name": "Wallet account",
"plugin_red_packet_nft_attached_message": "Attached Message",
"plugin_red_packet_nft_total_amount": "Total Amount",
Expand Down Expand Up @@ -535,6 +537,7 @@
"plugin_ito_region_ban": "This Pool is banned by its creator at your region",
"plugin_ito_next": "Next",
"plugin_ito_back": "Back",
"plugin_ito_transaction_dialog_summary_with_no_token": "Create an ITO.",
"plugin_ito_transaction_dialog_summary": "Create an ITO with {{amount}} {{symbol}}.",
"plugin_ito_swap": "Swap",
"plugin_ito_send_tip": "You can find your ITOs in the Past tab.",
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/shared-ui/locales/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
"plugin_red_packet_refunding_for": "{{balance}} {{symbol}} の投げ銭を払い戻し中",
"plugin_red_packet_amount_per_share": "1株当たりの金額",
"plugin_red_packet_send_symbol": "{{symbol}} を送る",
"plugin_red_packet_create_with_token": "{{symbol}} で投げ銭を作成する",
"plugin_red_packet_create_with_token": "{{amount}} {{symbol}} で投げ銭を作成する",
"plugin_gitcoin_readme": "このサービスを利用するにあたり、寄付金額の 5% が <fund>Gitcoin grants development fund</fund> に寄付されます",
"plugin_gitcoin_select_a_token": "トークンを選択する",
"plugin_gitcoin_enter_an_amount": "量を決める",
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/shared-ui/locales/ko-KR.json
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@
"plugin_red_packet_hint": "레드 패킷이 공유된 후 24시간 후에 나머지 잔액을 인출할 수 있습니다.",
"plugin_red_packet_token": "토큰",
"plugin_red_packet_message_label": "제목",
"plugin_red_packet_create_with_token": "{{symbol}} 으로 빨간 백 만드는 중",
"plugin_red_packet_create_with_token": "{{amount}} {{symbol}} 으로 빨간 백 만드는 중",
"plugin_red_packet_history_duration": "시간: {{startTime}} ~ {{endTime}} (UTC+8)",
"plugin_red_packet_history_total_amount": "총액: {{amount}} {{symbol}}",
"plugin_red_packet_history_total_claimed_amount": "전체: <span><strong>{{claimedAmount}}/{{amount}}</strong></span> {{symbol}}",
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/shared-ui/locales/qya-AA.json
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@
"plugin_red_packet_hint": "crwdns4771:0crwdne4771:0",
"plugin_red_packet_token": "crwdns4773:0crwdne4773:0",
"plugin_red_packet_message_label": "crwdns8157:0crwdne8157:0",
"plugin_red_packet_create_with_token": "crwdns4775:0{{symbol}}crwdne4775:0",
"plugin_red_packet_create_with_token": "crwdns4775:0{{amount}} {{symbol}}crwdne4775:0",
"plugin_red_packet_history_duration": "crwdns4777:0{{startTime}}crwdnd4777:0{{endTime}}crwdne4777:0",
"plugin_red_packet_history_total_amount": "crwdns4779:0{{amount}}crwdnd4779:0{{symbol}}crwdne4779:0",
"plugin_red_packet_history_total_claimed_amount": "crwdns4781:0{{claimedAmount}}crwdnd4781:0{{amount}}crwdnd4781:0{{symbol}}crwdne4781:0",
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/shared-ui/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@
"plugin_red_packet_hint": "你可以在红包发送的24小时后提取红包余额。",
"plugin_red_packet_token": "代币",
"plugin_red_packet_message_label": "标题",
"plugin_red_packet_create_with_token": "使用 {{symbol}} 创建红包",
"plugin_red_packet_create_with_token": "使用 {{amount}} {{symbol}} 创建红包",
"plugin_red_packet_history_duration": "时间: {{startTime}} ~ {{endTime}} (UTC+8)",
"plugin_red_packet_history_total_amount": "总额: {{amount}} {{symbol}}",
"plugin_red_packet_history_total_claimed_amount": "总额: <span><strong>{{claimedAmount}}/{{amount}}</strong></span> {{symbol}}",
Expand Down
2 changes: 1 addition & 1 deletion packages/mask/shared-ui/locales/zh-TW.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@
"plugin_red_packet_back": "返回",
"plugin_red_packet_token": "代幣",
"plugin_red_packet_message_label": "標題",
"plugin_red_packet_create_with_token": "使用 {{symbol}} 建立紅包",
"plugin_red_packet_create_with_token": "使用 {{amount}} {{symbol}} 建立紅包",
"plugin_red_packet_history_duration": "時間: {{startTime}} ~ {{endTime}} (UTC+8)",
"plugin_red_packet_history_total_amount": "總額: {{amount}} {{symbol}}",
"plugin_red_packet_history_total_claimed_amount": "總共: <span><strong>{{claimedAmount}}/{{amount}}</strong></span> {{symbol}}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,8 @@ export default function RedPacketDialog(props: RedPacketDialogProps) {
open: true,
state: createState,
summary: t('plugin_red_packet_create_with_token', {
symbol: `${formatBalance(createSettings?.total, createSettings?.token?.decimals)} ${
createSettings?.token.symbol
}`,
amount: formatBalance(createSettings?.total, createSettings?.token?.decimals),
symbol: createSettings?.token.symbol,
}),
})
}, [createState /* update tx dialog only if state changed */])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import type { TransactionReceipt } from 'web3-core'
import { first, last } from 'lodash-unified'
import {
ChainId,
useNativeTokenDetailed,
EthereumRpcType,
useChainId,
formatBalance,
NativeTokenDetailed,
ERC20TokenDetailed,
Expand All @@ -10,7 +13,7 @@ import {
} from '@masknet/web3-shared-evm'
import { pow10 } from '@masknet/web3-shared-base'
import type Services from '../../../../extension/service'
import { first, last } from 'lodash-unified'
import { getContractMethodDescription } from './contractMethodDescription'

function getTokenAmountDescription(amount = '0', tokenDetailed?: FungibleTokenDetailed, negative?: boolean) {
const symbol = negative ? '- ' : ''
Expand All @@ -22,6 +25,7 @@ function getTokenAmountDescription(amount = '0', tokenDetailed?: FungibleTokenDe
}

function getTransactionDescription(
chainId: ChainId,
nativeTokenDetailed?: NativeTokenDetailed | ERC20TokenDetailed,
tokenDetailed?: ERC20TokenDetailed,
computedPayload?: UnboxPromise<ReturnType<typeof Services.Ethereum.getSendTransactionComputedPayload>> | null,
Expand Down Expand Up @@ -73,15 +77,22 @@ function getTransactionDescription(
const amountOut = formatBalance(computedPayload.parameters.amountOutMin, tokenDetailed?.decimals, 2)
return `Swap ${amountIn} ${nativeTokenDetailed?.symbol} for ${amountOut} ${tokenDetailed?.symbol}`
default:
return `${computedPayload.name ?? 'Contract Interaction'} ${
computedPayload._tx.value
? getTokenAmountDescription(
computedPayload._tx.value as string | undefined,
nativeTokenDetailed,
true,
)
: ''
}`
const description = getContractMethodDescription(
{ name: computedPayload.name ?? '', chainId, address: computedPayload._tx.to ?? '' },
computedPayload,
)
return (
description ??
`${computedPayload.name ?? 'Contract Interaction'} ${
computedPayload._tx.value
? getTokenAmountDescription(
computedPayload._tx.value as string | undefined,
nativeTokenDetailed,
true,
)
: ''
}`
)
}
case EthereumRpcType.CONTRACT_DEPLOYMENT:
return `Contract Deployment ${getTokenAmountDescription(
Expand All @@ -105,6 +116,7 @@ export interface RecentTransactionDescriptionProps {
}

export function RecentTransactionDescription(props: RecentTransactionDescriptionProps) {
const chainId = useChainId()
const { hash, computedPayload } = props
const { loading: getNativeTokenLoading, value: nativeTokenDetailed } = useNativeTokenDetailed()
let inputTokenAddress: string | undefined = ''
Expand Down Expand Up @@ -139,6 +151,7 @@ export function RecentTransactionDescription(props: RecentTransactionDescription
return !getNativeTokenLoading && !getERC20TokenLoading && !getInputERC20TokenLoading ? (
<span>
{getTransactionDescription(
chainId,
inputTokenAddress ? inputTokenDetailed : nativeTokenDetailed,
tokenDetailed,
computedPayload,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { getITOConstants, isSameAddress, useERC20TokenDetailed, formatBalance } from '@masknet/web3-shared-evm'
import { useI18N } from '../../../../../utils'
import type { ContractMethodInfo, ComputedPayload } from '../type'

export function getITO_Description({ name, address, chainId }: ContractMethodInfo, computedPayload: ComputedPayload) {
const { ITO2_CONTRACT_ADDRESS } = getITOConstants(chainId)
if (!isSameAddress(address, ITO2_CONTRACT_ADDRESS)) return undefined

switch (name) {
case 'fill_pool':
return (
<FillPoolDescription
tokenAddress={computedPayload?.parameters?._token_addr ?? ''}
tokenAmount={computedPayload?.parameters?._total_tokens}
/>
)
default:
return undefined
}
}

interface FillPoolDescriptionProps {
tokenAddress: string
tokenAmount: string
}

function FillPoolDescription(props: FillPoolDescriptionProps) {
const { tokenAddress, tokenAmount } = props

const { value: token } = useERC20TokenDetailed(tokenAddress)
const { t } = useI18N()

return (
<span>
{token && tokenAddress
? t('plugin_ito_transaction_dialog_summary', {
amount: formatBalance(tokenAmount, token.decimals),
symbol: token.symbol,
})
: t('plugin_ito_transaction_dialog_summary_with_no_token')}
</span>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { getNftRedPacketConstants, isSameAddress } from '@masknet/web3-shared-evm'
import { i18n } from '../../../../../../shared-ui/locales_legacy'
import type { ContractMethodInfo, ComputedPayload } from '../type'

export function getNFTRedpacketDescription(
{ name, address, chainId }: ContractMethodInfo,
computedPayload: ComputedPayload,
) {
const { RED_PACKET_NFT_ADDRESS } = getNftRedPacketConstants(chainId)

if (!isSameAddress(address, RED_PACKET_NFT_ADDRESS)) return undefined

switch (name) {
case 'create_red_packet':
return i18n.t('plugin_nft_red_packet_create')
default:
return undefined
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import {
getRedPacketConstants,
isSameAddress,
useERC20TokenDetailed,
formatBalance,
isNativeTokenAddress,
useNativeTokenDetailed,
} from '@masknet/web3-shared-evm'
import { useI18N } from '../../../../../utils'
import type { ContractMethodInfo, ComputedPayload } from '../type'

export function getRedpacketDescription(
{ name, address, chainId }: ContractMethodInfo,
computedPayload: ComputedPayload,
) {
const { HAPPY_RED_PACKET_ADDRESS_V4 } = getRedPacketConstants(chainId)

if (!isSameAddress(address, HAPPY_RED_PACKET_ADDRESS_V4)) return undefined

switch (name) {
case 'create_red_packet':
return (
<CreateRedpacketDescription
tokenAddress={computedPayload?.parameters?._token_addr ?? ''}
tokenAmount={computedPayload?.parameters?._total_tokens}
/>
)
default:
return undefined
}
}

interface CreateRedpacketDescriptionProps {
tokenAddress: string
tokenAmount: string
}

export function CreateRedpacketDescription(props: CreateRedpacketDescriptionProps) {
const { tokenAddress, tokenAmount } = props
const { t } = useI18N()

const { value: nativeToken } = useNativeTokenDetailed()
const { value: tokenDetailed } = useERC20TokenDetailed(tokenAddress)
const token = isNativeTokenAddress(tokenAddress) ? nativeToken : tokenDetailed

return (
<span>
{token && tokenAddress
? t('plugin_red_packet_create_with_token', {
amount: formatBalance(tokenAmount, token.decimals),
symbol: token.symbol,
})
: t('plugin_red_packet_create')}
</span>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { getRedpacketDescription } from './getRedpacketDescription'
import { getITO_Description } from './getITO_Description'
import { getNFTRedpacketDescription } from './getNFTRedpacketDescription'
import type { ContractMethodInfo, ComputedPayload } from '../type'

export function getContractMethodDescription(contractMethodInfo: ContractMethodInfo, computedPayload: ComputedPayload) {
return (
getRedpacketDescription(contractMethodInfo, computedPayload) ??
getITO_Description(contractMethodInfo, computedPayload) ??
getNFTRedpacketDescription(contractMethodInfo, computedPayload)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { ChainId } from '@masknet/web3-shared-evm'
import type Services from '../../../../extension/service'

export interface ContractMethodInfo {
name: string
address: string
chainId: ChainId
}

export type ComputedPayload = UnboxPromise<ReturnType<typeof Services.Ethereum.getSendTransactionComputedPayload>>