From 1197c500562f0985815a835decdf98c8b47042ac Mon Sep 17 00:00:00 2001 From: Wukong Sun Date: Fri, 24 Jan 2025 00:50:56 +0800 Subject: [PATCH] fix: mf-6479 mf-6583 redpacket sender (#12068) * fix: mf-6479 mf-6583 redpacket sender * fix: collection name overflow --- packages/plugin-infra/src/entry-content-script.ts | 1 + .../src/site-adaptor/useLastRecognizedIdentity.ts | 4 ++++ .../src/SiteAdaptor/components/ConditionSettings.tsx | 1 + .../RedPacket/src/SiteAdaptor/contexts/RedPacketContext.tsx | 5 +---- .../src/SiteAdaptor/hooks/useCreateFTRedpacketCallback.ts | 4 +++- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/plugin-infra/src/entry-content-script.ts b/packages/plugin-infra/src/entry-content-script.ts index a2aaf7293ff8..ebab24093a53 100644 --- a/packages/plugin-infra/src/entry-content-script.ts +++ b/packages/plugin-infra/src/entry-content-script.ts @@ -52,6 +52,7 @@ export { useCurrentPersonaInformation, useCurrentVisitingIdentity, useCurrentVisitingSocialIdentity, + getLastRecognizedIdentity, useLastRecognizedIdentity, useLastRecognizedSocialIdentity, usePostLink, diff --git a/packages/plugin-infra/src/site-adaptor/useLastRecognizedIdentity.ts b/packages/plugin-infra/src/site-adaptor/useLastRecognizedIdentity.ts index f84dde20a956..81c800801210 100644 --- a/packages/plugin-infra/src/site-adaptor/useLastRecognizedIdentity.ts +++ b/packages/plugin-infra/src/site-adaptor/useLastRecognizedIdentity.ts @@ -5,3 +5,7 @@ import { lastRecognizedProfile } from './context.js' export function useLastRecognizedIdentity() { return useSubscription(lastRecognizedProfile ?? UNDEFINED) } + +export function getLastRecognizedIdentity() { + return lastRecognizedProfile.getCurrentValue() +} diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/components/ConditionSettings.tsx b/packages/plugins/RedPacket/src/SiteAdaptor/components/ConditionSettings.tsx index 35ba6152771d..eed11614a98d 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/components/ConditionSettings.tsx +++ b/packages/plugins/RedPacket/src/SiteAdaptor/components/ConditionSettings.tsx @@ -115,6 +115,7 @@ const useStyles = makeStyles()((theme) => { display: '-webkit-box', WebkitLineClamp: 2, WebkitBoxOrient: 'vertical', + overflow: 'hidden', }, tokenIcon: { width: 24, diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/contexts/RedPacketContext.tsx b/packages/plugins/RedPacket/src/SiteAdaptor/contexts/RedPacketContext.tsx index 67c5f012089f..7b8d351e763f 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/contexts/RedPacketContext.tsx +++ b/packages/plugins/RedPacket/src/SiteAdaptor/contexts/RedPacketContext.tsx @@ -1,6 +1,5 @@ import { t } from '@lingui/core/macro' import { useLastRecognizedIdentity } from '@masknet/plugin-infra/content-script' -import { useCurrentLinkedPersona } from '@masknet/shared' import { EMPTY_LIST, type NetworkPluginID } from '@masknet/shared-base' import { useChainContext } from '@masknet/web3-hooks-base' import { EVMChainResolver } from '@masknet/web3-providers' @@ -141,9 +140,7 @@ export const RedPacketProvider = memo(function RedPacketProvider({ children }: P const [token = nativeToken, setToken] = useState>() const myIdentity = useLastRecognizedIdentity() - const linkedPersona = useCurrentLinkedPersona() - - const creator = myIdentity?.identifier?.userId || linkedPersona?.nickname || 'Unknown User' + const creator = myIdentity?.identifier?.userId || 'Unknown User' const amount = rightShift(rawAmount || '0', token?.decimals) const totalAmount = useMemo(() => multipliedBy(amount, isRandom ? 1 : (shares ?? '0')), [amount, shares, isRandom]) diff --git a/packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateFTRedpacketCallback.ts b/packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateFTRedpacketCallback.ts index 8c0c9135f273..19e20b9ec456 100644 --- a/packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateFTRedpacketCallback.ts +++ b/packages/plugins/RedPacket/src/SiteAdaptor/hooks/useCreateFTRedpacketCallback.ts @@ -9,6 +9,7 @@ import { isNativeTokenAddress, useRedPacketConstants, type GasConfig } from '@ma import { BigNumber } from 'bignumber.js' import { useCallback, useEffect, useMemo, useRef } from 'react' import { useCreateCallback, useCreateParams, type RedPacketSettings } from './useCreateCallback.js' +import { getLastRecognizedIdentity } from '@masknet/plugin-infra/content-script' export function useCreateFTRedpacketCallback( redpacketPubkey: string, @@ -78,10 +79,11 @@ export function useCreateFTRedpacketCallback( // the events log is not available if (!events?.CreationSuccess?.returnValues.id) return + const senderName = settings.name || getLastRecognizedIdentity()?.identifier?.userId const redpacketPayload = { sender: { address: account, - name: settings.name, + name: senderName, message: settings.message, }, is_random: settings.isRandom,