Skip to content

Commit

Permalink
fix: solana transaction and tips (#12028)
Browse files Browse the repository at this point in the history
* fix: solana transaction and tips

* refactor: type alias

* fix: add raydium new token list
  • Loading branch information
swkatmask authored Jan 10, 2025
1 parent 298b552 commit 2f6b42a
Show file tree
Hide file tree
Showing 39 changed files with 672 additions and 441 deletions.
4 changes: 2 additions & 2 deletions packages/mask/shared-ui/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ export const GeneratorServices: AsyncGeneratorVersionOf<GeneratorServicesType> =
function add<T extends object>(key: string, generator = false): AsyncVersionOf<T> {
const channel = message.events[key].bind(Environment.ManifestBackground)

const RPC = (generator ? AsyncGeneratorCall : AsyncCall) as any as typeof AsyncCall
const service = RPC<T>(null, {
const asyncCall = (generator ? AsyncGeneratorCall : AsyncCall) as any as typeof AsyncCall
const service = asyncCall<T>(null, {
key,
encoder,
log,
Expand Down
38 changes: 15 additions & 23 deletions packages/plugins/Tips/src/components/TipDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,25 @@ export function TipDialog({ open = false, onClose }: TipDialogProps) {
const isTokenTip = tipType === TokenType.Fungible
const shareText = useMemo(() => {
const recipientName = recipient?.label || recipientEns
const promote = _(msg`Install https://mask.io/download-links to send your first tip.`)
if (isTokenTip) {
return (
_(
msg`I just tipped ${amount} ${select(token?.symbol ? 'namedToken' : 'token', {
namedToken: token?.symbol || '',
other: 'token',
})} to @${recipientUserId}'s ${select(recipientName ? 'name' : 'address', {
name: 'wallet',
address: 'wallet address',
other: 'wallet',
})} ${recipientName || recipientAddress}`,
) + `\n\n${promote}`
return _(
msg`I just tipped ${amount} ${select(token?.symbol ? 'namedToken' : 'token', {
namedToken: token?.symbol || '',
other: 'token',
})} to @${recipientUserId}'s ${select(recipientName ? 'name' : 'address', {
name: 'wallet',
address: 'wallet address',
other: 'wallet',
})} ${recipientName || recipientAddress}\n\nInstall https://mask.io/download-links to send your first tip.`,
)
} else {
const NFT_Name = nonFungibleTokenContract?.name || 'NFT'
return (
_(
msg`I just tipped a ${NFT_Name} to @${recipientUserId}'s ${select(
recipientName ? 'name' : 'address',
{
name: 'wallet',
address: 'wallet address',
other: 'wallet',
},
)} ${recipientAddress}`,
) + `\n\n${promote}`
return _(
msg`I just tipped a ${NFT_Name} to @${recipientUserId}'s ${select(recipientName ? 'name' : 'address', {
name: 'wallet',
address: 'wallet address',
other: 'wallet',
})} ${recipientAddress}\n\nInstall https://mask.io/download-links to send your first tip.`,
)
}
}, [amount, isTokenTip, nonFungibleTokenContract?.name, token, recipient, recipientUserId, _, recipientEns])
Expand Down
14 changes: 5 additions & 9 deletions packages/plugins/Tips/src/components/TipsButton/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { useTipsAccounts } from './useTipsAccounts.js'

interface Props extends HTMLProps<HTMLDivElement> {
// This is workaround solution, link issue mf-2536 and pr #7576.
// Should refactor social account to support multi-account for one post.
// Should refactor social account to support post by multiple authors.
accounts?: Array<SocialAccount<Web3Helper.ChainIdAll>>
recipient?: string
receiver?: ProfileIdentifier
Expand All @@ -26,19 +26,15 @@ interface Props extends HTMLProps<HTMLDivElement> {
onStatusUpdate?(disabled: boolean): void
}

const useStyles = makeStyles<{ iconSize: number }>()((theme, props) => ({
const useStyles = makeStyles()({
tipButton: {
cursor: 'pointer',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
fontFamily: '-apple-system, system-ui, sans-serif',
},
icon: {
width: props.iconSize,
height: props.iconSize,
},
}))
})

export function TipButton(props: Props) {
const {
Expand All @@ -51,7 +47,7 @@ export function TipButton(props: Props) {
onStatusUpdate,
...rest
} = props
const { classes, cx } = useStyles({ iconSize })
const { classes, cx } = useStyles()

const { data: personaPubkey, isPending: loadingPersona } = useProfilePublicKey(receiver?.userId)
const receiverUserId = receiver?.userId
Expand Down Expand Up @@ -124,7 +120,7 @@ export function TipButton(props: Props) {

return (
<div className={cx(className, classes.tipButton)} {...rest} role="button" onClick={createTipTask}>
<Icons.TipCoin className={classes.icon} />
<Icons.TipCoin size={iconSize} />
{children}
</div>
)
Expand Down
33 changes: 19 additions & 14 deletions packages/plugins/Tips/src/contexts/Tip/useRecipientValidate.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
import { useMemo } from 'react'
import { useAsync } from 'react-use'
import { msg } from '@lingui/macro'
import { useLingui } from '@lingui/react'
import { NetworkPluginID } from '@masknet/shared-base'
import { useAddressType, useChainContext } from '@masknet/web3-hooks-base'
import { GoPlusLabs } from '@masknet/web3-providers'
import { AddressType } from '@masknet/web3-shared-evm'
import { NetworkPluginID } from '@masknet/shared-base'
import { AddressType, type ChainId } from '@masknet/web3-shared-evm'
import { useQuery } from '@tanstack/react-query'
import { useMemo } from 'react'
import type { ValidationTuple } from '../../types/index.js'
import { msg } from '@lingui/macro'
import { useLingui } from '@lingui/react'
import { TargetRuntimeContext } from '../TargetRuntimeContext.js'

export function useRecipientValidate(recipientAddress: string): {
loading: boolean
validation: ValidationTuple
} {
const { _ } = useLingui()
const { chainId } = useChainContext<NetworkPluginID.PLUGIN_EVM>()
const { value: addressType, loading } = useAddressType(NetworkPluginID.PLUGIN_EVM, recipientAddress, {
const { targetPluginID } = TargetRuntimeContext.useContainer()
const { chainId } = useChainContext()
const { value: addressType, loading } = useAddressType(targetPluginID, recipientAddress, {
chainId,
})
const { value: security } = useAsync(async () => {
return GoPlusLabs.getAddressSecurity(chainId, recipientAddress)
}, [chainId, recipientAddress])

const isMaliciousAddress = security && Object.values(security).filter((x) => x === '1').length > 0
const isEvm = targetPluginID === NetworkPluginID.PLUGIN_EVM
const { data: security } = useQuery({
enabled: isEvm,
queryKey: ['go-plus', 'address-security', chainId, recipientAddress],
queryFn: () => GoPlusLabs.getAddressSecurity(chainId as ChainId, recipientAddress),
})

const validation: ValidationTuple = useMemo(() => {
if (!isEvm) return [true]
if (addressType === AddressType.Contract)
return [false, _(msg`The receiving address is a contract address. Please check again.`)]
const isMaliciousAddress = security && Object.values(security).filter((x) => x === '1').length > 0
if (isMaliciousAddress) return [false, _(msg`The receiving address may be a malicious address.`)]
return [true]
}, [addressType, isMaliciousAddress, _])
}, [isEvm, addressType, security, _])
return {
loading,
validation,
Expand Down
24 changes: 24 additions & 0 deletions packages/plugins/Tips/src/locale/en-US.json

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

16 changes: 12 additions & 4 deletions packages/plugins/Tips/src/locale/en-US.po

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

24 changes: 24 additions & 0 deletions packages/plugins/Tips/src/locale/ja-JP.json

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

16 changes: 12 additions & 4 deletions packages/plugins/Tips/src/locale/ja-JP.po

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

24 changes: 24 additions & 0 deletions packages/plugins/Tips/src/locale/ko-KR.json

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

16 changes: 12 additions & 4 deletions packages/plugins/Tips/src/locale/ko-KR.po

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

Loading

0 comments on commit 2f6b42a

Please sign in to comment.