diff --git a/packages/mask/src/extension/background-script/SocialNetworkService.ts b/packages/mask/src/extension/background-script/SocialNetworkService.ts index 84be88b859fc..e8c93b3c7e18 100644 --- a/packages/mask/src/extension/background-script/SocialNetworkService.ts +++ b/packages/mask/src/extension/background-script/SocialNetworkService.ts @@ -42,7 +42,16 @@ export async function openProfilePage(network: string, userId?: string) { export async function openShareLink(SNSIdentifier: string, post: string) { const url = (await getNetworkWorker(SNSIdentifier)).utils.getShareLinkURL?.(post) if (!url) return - browser.tabs.create({ active: true, url: url.toString() }) + const width = 700 + const height = 520 + browser.windows.create({ + url: url.toString(), + width, + height, + type: 'popup', + left: (screen.width - width) / 2, + top: (screen.height - height) / 2, + }) } const key = 'openSNSAndActivatePlugin' diff --git a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx index 7b75dddbcfc4..d53bbbbd27ac 100644 --- a/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx +++ b/packages/mask/src/plugins/ArtBlocks/SNSAdaptor/PurchaseDialog.tsx @@ -85,24 +85,20 @@ export function PurchaseDialog(props: ActionBarProps) { }, [project.pricePerTokenInWei, token.value?.decimals]) const postLink = usePostLink() - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - [ - t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_artblocks_share' - : 'plugin_artblocks_share_no_official_account', - { - name: project.name, - price: price, - symbol: token.value?.symbol, - }, - ), - '#mask_io #artblocks_io #nft', - postLink, - ].join('\n'), - ) - .toString() + const shareText = [ + t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_artblocks_share' + : 'plugin_artblocks_share_no_official_account', + { + name: project.name, + price: price, + symbol: token.value?.symbol, + }, + ), + '#mask_io #artblocks_io #nft', + postLink, + ].join('\n') const { setDialog: setTransactionDialog } = useRemoteControlledDialog( WalletMessages.events.transactionDialogUpdated, @@ -130,7 +126,7 @@ export function PurchaseDialog(props: ActionBarProps) { if (purchaseState.type === TransactionStateType.UNKNOWN) return setTransactionDialog({ open: true, - shareLink, + shareText, state: purchaseState, summary: `Minting a new collectible from '${project.name}' collection.`, }) diff --git a/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/CheckoutDialog.tsx b/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/CheckoutDialog.tsx index 65b43c08f6cd..33cebe8fafbf 100644 --- a/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/CheckoutDialog.tsx +++ b/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/CheckoutDialog.tsx @@ -103,24 +103,20 @@ export function CheckoutDialog(props: CheckoutDialogProps) { }, [purchaseCallback]) const assetLink = resolveAssetLinkOnCryptoartAI(asset?.value?.creator?.username, asset?.value?.token_id, chainId) - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - token - ? t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_cryptoartai_share' - : 'plugin_cryptoartai_share_no_official_account', - { - amount: asset?.value?.priceInEth, - symbol: token?.value?.symbol, - title: asset?.value?.title, - assetLink: assetLink, - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ) - : '', - ) - .toString() + const shareText = token + ? t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_cryptoartai_share' + : 'plugin_cryptoartai_share_no_official_account', + { + amount: asset?.value?.priceInEth, + symbol: token?.value?.symbol, + title: asset?.value?.title, + assetLink: assetLink, + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }, + ) + : '' const { setDialog: setTransactionDialog } = useRemoteControlledDialog( WalletMessages.events.transactionDialogUpdated, @@ -139,7 +135,7 @@ export function CheckoutDialog(props: CheckoutDialogProps) { if (purchaseState.type === TransactionStateType.UNKNOWN) return setTransactionDialog({ open: true, - shareLink, + shareText, state: purchaseState, summary: t('plugin_cryptoartai_buy') + ' ' + asset?.value?.title, }) diff --git a/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/MakeOfferDialog.tsx b/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/MakeOfferDialog.tsx index 858d11125bce..ebe26afb17a2 100644 --- a/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/MakeOfferDialog.tsx +++ b/packages/mask/src/plugins/CryptoartAI/SNSAdaptor/MakeOfferDialog.tsx @@ -113,24 +113,20 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { }, [placeBidCallback, amount]) const assetLink = resolveAssetLinkOnCryptoartAI(assetSource?.creator?.username, assetSource?.token_id, chainId) - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - token - ? t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_cryptoartai_offer_share' - : 'plugin_cryptoartai_offer_share_no_official_account', - { - amount: amount, - symbol: token?.value?.symbol, - title: assetSource?.title, - assetLink: assetLink, - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ) - : '', - ) - .toString() + const shareText = token + ? t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_cryptoartai_offer_share' + : 'plugin_cryptoartai_offer_share_no_official_account', + { + amount: amount, + symbol: token?.value?.symbol, + title: assetSource?.title, + assetLink: assetLink, + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }, + ) + : '' const { setDialog: setTransactionDialog } = useRemoteControlledDialog( WalletMessages.events.transactionDialogUpdated, @@ -152,7 +148,7 @@ export function MakeOfferDialog(props: MakeOfferDialogProps) { if (placeBidState.type === TransactionStateType.UNKNOWN) return setTransactionDialog({ open: true, - shareLink, + shareText, state: placeBidState, summary: (assetSource?.is24Auction diff --git a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx index c72a5604c348..edf2dcfd6c97 100644 --- a/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx +++ b/packages/mask/src/plugins/Gitcoin/SNSAdaptor/DonateDialog.tsx @@ -122,25 +122,19 @@ export function DonateDialog(props: DonateDialogProps) { // #region transaction dialog const cashTag = isTwitter(activatedSocialNetworkUI) ? '$' : '' - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - token - ? [ - `I just donated ${title} with ${formatBalance(amount, token.decimals)} ${cashTag}${ - token.symbol - }. ${ - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? `Follow @${ - isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') - } (mask.io) to donate Gitcoin grants.` - : '' - }`, - '#mask_io', - postLink, - ].join('\n') - : '', - ) - .toString() + const shareText = token + ? [ + `I just donated ${title} with ${formatBalance(amount, token.decimals)} ${cashTag}${token.symbol}. ${ + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? `Follow @${ + isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') + } (mask.io) to donate Gitcoin grants.` + : '' + }`, + '#mask_io', + postLink, + ].join('\n') + : '' // close the transaction dialog const { setDialog: setTransactionDialog } = useRemoteControlledDialog( @@ -158,7 +152,7 @@ export function DonateDialog(props: DonateDialogProps) { if (donateState.type === TransactionStateType.UNKNOWN) return setTransactionDialog({ open: true, - shareLink, + shareText, state: donateState, summary: `Donating ${formatBalance(amount, token.decimals)} ${token.symbol} for ${title}.`, }) diff --git a/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx b/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx index 8405a18a51f8..ffe367b22391 100644 --- a/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx +++ b/packages/mask/src/plugins/ITO/SNSAdaptor/ITO.tsx @@ -297,21 +297,17 @@ export function ITO(props: ITO_Props) { const isBuyer = chainId === payload.chain_id && (isGreaterThan(availability?.swapped ?? 0, 0) || Boolean(availability?.claimed)) - const shareSuccessLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_ito_claim_success_share' - : 'plugin_ito_claim_success_share_no_official_account', - { - user: sellerName, - link: postLink, - symbol: token.symbol, - account: isFacebook(activatedSocialNetworkUI) ? t('facebook_account') : t('twitter_account'), - }, - ), - ) - .toString() + const successShareText = t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_ito_claim_success_share' + : 'plugin_ito_claim_success_share_no_official_account', + { + user: sellerName, + link: postLink, + symbol: token.symbol, + account: isFacebook(activatedSocialNetworkUI) ? t('facebook_account') : t('twitter_account'), + }, + ) const canWithdraw = useMemo( () => !availability?.destructed && @@ -330,8 +326,8 @@ export function ITO(props: ITO_Props) { const refundAllAmount = tradeInfo?.buyInfo && isZero(tradeInfo?.buyInfo.amount_sold) const onShareSuccess = useCallback(async () => { - window.open(shareSuccessLink, '_blank', 'noopener noreferrer') - }, [shareSuccessLink]) + activatedSocialNetworkUI.utils.share?.(successShareText) + }, [successShareText]) // #endregion const retryITOCard = useCallback(() => { @@ -340,7 +336,7 @@ export function ITO(props: ITO_Props) { }, [retryPoolTradeInfo, retryAvailability]) // #region claim - const [claimState, claimCallback, resetClaimCallback] = useClaimCallback([pid], payload.contract_address) + const [claimState, claimCallback] = useClaimCallback([pid], payload.contract_address) const onClaimButtonClick = useCallback(() => { claimCallback() }, [claimCallback]) @@ -376,24 +372,20 @@ export function ITO(props: ITO_Props) { // #endregion - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_ito_claim_foreshow_share' - : 'plugin_ito_claim_foreshow_share_no_official_account', - { - link: postLink, - name: token.name, - symbol: token.symbol ?? 'token', - account: isFacebook(activatedSocialNetworkUI) ? t('facebook_account') : t('twitter_account'), - }, - ), - ) - .toString() + const shareText = t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_ito_claim_foreshow_share' + : 'plugin_ito_claim_foreshow_share_no_official_account', + { + link: postLink, + name: token.name, + symbol: token.symbol ?? 'token', + account: isFacebook(activatedSocialNetworkUI) ? t('facebook_account') : t('twitter_account'), + }, + ) const onShare = useCallback(async () => { - window.open(shareLink, '_blank', 'noopener noreferrer') - }, [shareLink]) + activatedSocialNetworkUI.utils.share?.(shareText) + }, [shareText]) const onUnlock = useCallback(async () => { setClaimDialogStatus(SwapStatus.Unlock) setOpenClaimDialog(true) @@ -751,7 +743,7 @@ export function ITO(props: ITO_Props) { {t('plugin_ito_unlock_in_advance')} - {shareLink ? ( + {shareText ? ( { + const onShare = () => { onClose() - window.open(shareSuccessLink, '_blank', 'noopener noreferrer') - }, [shareSuccessLink]) + activatedSocialNetworkUI.utils.share?.(shareText) + } if (!contractDetailed) return null diff --git a/packages/mask/src/plugins/Pets/SNSAdaptor/PetShareDialog.tsx b/packages/mask/src/plugins/Pets/SNSAdaptor/PetShareDialog.tsx index c717d2599246..eb89b5696c8a 100644 --- a/packages/mask/src/plugins/Pets/SNSAdaptor/PetShareDialog.tsx +++ b/packages/mask/src/plugins/Pets/SNSAdaptor/PetShareDialog.tsx @@ -29,18 +29,11 @@ interface PetSetDialogProps { export function PetShareDialog({ onClose }: PetSetDialogProps) { const { t } = useI18N() const { classes } = useStyles() - const shareLink = activatedSocialNetworkUI.utils.getShareLinkURL?.('') const onShareClick = useCallback(() => { - if (shareLink) { - const search = '?text=' + Share_Twitter_TXT - shareLink.search = search - shareLink.href = shareLink.origin + shareLink.pathname + shareLink.search - const share = shareLink.toString() - window.open(share, '_blank', 'noopener noreferrer') - } + activatedSocialNetworkUI.utils.share?.(Share_Twitter_TXT) onClose() - }, [shareLink]) + }, [onClose]) return ( diff --git a/packages/mask/src/plugins/PoolTogether/UI/DepositDialog.tsx b/packages/mask/src/plugins/PoolTogether/UI/DepositDialog.tsx index d30fb9b5a2f1..bce5d39ccd42 100644 --- a/packages/mask/src/plugins/PoolTogether/UI/DepositDialog.tsx +++ b/packages/mask/src/plugins/PoolTogether/UI/DepositDialog.tsx @@ -189,24 +189,20 @@ export function DepositDialog() { // #region transaction dialog const cashTag = isTwitter(activatedSocialNetworkUI) ? '$' : '' - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - token - ? t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_pooltogether_share' - : 'plugin_pooltogether_share_no_official_account', - { - amount: rawAmount, - cashTag: cashTag, - symbol: token.symbol, - pool: pool?.name ?? `${pool?.tokens.underlyingToken.symbol} Pool`, - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ) - : '', - ) - .toString() + const shareText = token + ? t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_pooltogether_share' + : 'plugin_pooltogether_share_no_official_account', + { + amount: rawAmount, + cashTag: cashTag, + symbol: token.symbol, + pool: pool?.name ?? `${pool?.tokens.underlyingToken.symbol} Pool`, + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }, + ) + : '' // on close transaction dialog const { setDialog: setTransactionDialogOpen } = useRemoteControlledDialog( @@ -230,7 +226,7 @@ export function DepositDialog() { if (depositState.type === TransactionStateType.UNKNOWN) return setTransactionDialogOpen({ open: true, - shareLink, + shareText, state: depositState, summary: `Depositing ${formatBalance(amount, token.decimals)}${token.symbol} on ${pool?.name} pool.`, }) diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx index 42c1191e8f6c..589980fe5af0 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/OperationFooter.tsx @@ -2,7 +2,6 @@ import { WalletMessages } from '@masknet/plugin-wallet' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { TransactionState, TransactionStateType, useAccount, useChainIdValid } from '@masknet/web3-shared-evm' import { Box } from '@mui/material' -import { useCallback } from 'react' import ActionButton from '../../../../extension/options-page/DashboardComponents/ActionButton' import { useI18N } from '../../../../utils' import { EthereumWalletConnectedBoundary } from '../../../../web3/UI/EthereumWalletConnectedBoundary' @@ -13,7 +12,7 @@ interface OperationFooterProps { canRefund: boolean claimState: TransactionState refundState: TransactionState - shareLink?: string + onShare?(): void onClaimOrRefund: () => void | Promise } export function OperationFooter({ @@ -21,7 +20,7 @@ export function OperationFooter({ canRefund, claimState, refundState, - shareLink, + onShare, onClaimOrRefund, }: OperationFooterProps) { const { classes } = useStyles() @@ -35,11 +34,6 @@ export function OperationFooter({ ) // #endregion - const handleShare = useCallback(() => { - if (!shareLink) return - window.open(shareLink, '_blank', 'noopener noreferrer') - }, [shareLink]) - const ObtainButton = () => { if (!canClaim && !canRefund) return null @@ -87,7 +81,7 @@ export function OperationFooter({ }}> {canRefund ? null : ( - + {t('share')} )} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx index 8a5b11f35cea..814db696b16e 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacket/index.tsx @@ -84,18 +84,15 @@ export function RedPacket(props: RedPacketProps) { payload.contract_version > 3 ? web3.eth.accounts.sign(account, payload.password).signature : payload.password, ) - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - (listOfStatus.includes(RedPacketStatus.claimed) || claimState.type === TransactionStateType.CONFIRMED - ? isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? t('plugin_red_packet_share_message_official_account', shareTextOption) - : t('plugin_red_packet_share_message_not_twitter', shareTextOption) - : isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? t('plugin_red_packet_share_unclaimed_message_official_account', shareTextOption) - : t('plugin_red_packet_share_unclaimed_message_not_twitter', shareTextOption) - ).trim(), - ) - .toString() + const shareText = ( + listOfStatus.includes(RedPacketStatus.claimed) || claimState.type === TransactionStateType.CONFIRMED + ? isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? t('plugin_red_packet_share_message_official_account', shareTextOption) + : t('plugin_red_packet_share_message_not_twitter', shareTextOption) + : isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? t('plugin_red_packet_share_unclaimed_message_official_account', shareTextOption) + : t('plugin_red_packet_share_unclaimed_message_not_twitter', shareTextOption) + ).trim() const [refundState, refundCallback, resetRefundCallback] = useRefundCallback( payload.contract_version, @@ -117,7 +114,7 @@ export function RedPacket(props: RedPacketProps) { canClaim && setTransactionDialog({ open: true, - shareLink: shareLink!, + shareText, state, summary: t('plugin_red_packet_claiming_from', { name: payload.sender.name }), }) @@ -172,6 +169,11 @@ export function RedPacket(props: RedPacketProps) { }) }, [availability, canRefund, token, t, payload, listOfStatus]) + const handleShare = useCallback(() => { + if (!shareText || !activatedSocialNetworkUI.utils.share) return + activatedSocialNetworkUI.utils.share(shareText) + }, [shareText]) + // the red packet can fetch without account if (!availability || !token) return ( @@ -218,7 +220,7 @@ export function RedPacket(props: RedPacketProps) { canRefund={canRefund} claimState={claimState} refundState={refundState} - shareLink={shareLink} + onShare={handleShare} onClaimOrRefund={onClaimOrRefund} /> )} diff --git a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx index e86274a905a1..4da7da3685e9 100644 --- a/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx +++ b/packages/mask/src/plugins/RedPacket/SNSAdaptor/RedPacketNft.tsx @@ -292,37 +292,33 @@ export function RedPacketNft({ payload }: RedPacketNftProps) { // #region on share const postLink = usePostLink() const networkType = useNetworkType() - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - availability?.isClaimed - ? t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_red_packet_nft_share_claimed_message' - : 'plugin_red_packet_nft_share_claimed_message_not_twitter', - { - sender: payload.senderName, - payload: postLink, - network: resolveNetworkName(networkType), - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ).trim() - : t( - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? 'plugin_red_packet_nft_share_foreshow_message' - : 'plugin_red_packet_nft_share_foreshow_message_not_twitter', - { - sender: payload.senderName, - payload: postLink, - network: resolveNetworkName(networkType), - account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), - }, - ).trim(), - ) - .toString() + const shareText = availability?.isClaimed + ? t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_red_packet_nft_share_claimed_message' + : 'plugin_red_packet_nft_share_claimed_message_not_twitter', + { + sender: payload.senderName, + payload: postLink, + network: resolveNetworkName(networkType), + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }, + ).trim() + : t( + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? 'plugin_red_packet_nft_share_foreshow_message' + : 'plugin_red_packet_nft_share_foreshow_message_not_twitter', + { + sender: payload.senderName, + payload: postLink, + network: resolveNetworkName(networkType), + account: isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account'), + }, + ).trim() const onShare = useCallback(() => { - if (shareLink) window.open(shareLink, '_blank', 'noopener noreferrer') - }, [shareLink]) + if (shareText) activatedSocialNetworkUI.utils.share?.(shareText) + }, [shareText]) // #endregion if (availabilityError) diff --git a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx index d7f4277ddb2b..c3accaad1d32 100644 --- a/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx +++ b/packages/mask/src/plugins/Trader/SNSAdaptor/trader/Trader.tsx @@ -287,32 +287,26 @@ export function Trader(props: TraderProps) { // #region remote controlled transaction dialog const cashTag = isTwitter(activatedSocialNetworkUI) ? '$' : '' - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - focusedTrade?.value && inputToken && outputToken - ? [ - `I just swapped ${formatBalance( - focusedTrade.value.inputAmount, - inputToken.decimals, - 6, - )} ${cashTag}${inputToken.symbol} for ${formatBalance( - focusedTrade.value.outputAmount, - outputToken.decimals, - 6, - )} ${cashTag}${outputToken.symbol}.${ - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? `Follow @${ - isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') - } (mask.io) to swap cryptocurrencies on ${ - isTwitter(activatedSocialNetworkUI) ? 'Twitter' : 'Facebook' - }.` - : '' - }`, - '#mask_io', - ].join('\n') - : '', - ) - .toString() + const shareText = + focusedTrade?.value && inputToken && outputToken + ? [ + `I just swapped ${formatBalance(focusedTrade.value.inputAmount, inputToken.decimals, 6)} ${cashTag}${ + inputToken.symbol + } for ${formatBalance(focusedTrade.value.outputAmount, outputToken.decimals, 6)} ${cashTag}${ + outputToken.symbol + }.${ + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? `Follow @${ + isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') + } (mask.io) to swap cryptocurrencies on ${ + isTwitter(activatedSocialNetworkUI) ? 'Twitter' : 'Facebook' + }.` + : '' + }`, + '#mask_io', + ].join('\n') + : '' + // #endregion // #region close the transaction dialog @@ -336,7 +330,7 @@ export function Trader(props: TraderProps) { if (tradeState?.type === TransactionStateType.UNKNOWN) return setTransactionDialog({ open: true, - shareLink, + shareText, state: tradeState, }) }, [tradeState /* update tx dialog only if state changed */]) diff --git a/packages/mask/src/plugins/Wallet/SNSAdaptor/TransactionDialog.tsx b/packages/mask/src/plugins/Wallet/SNSAdaptor/TransactionDialog.tsx index 684036b4a0aa..3d0d3a010904 100644 --- a/packages/mask/src/plugins/Wallet/SNSAdaptor/TransactionDialog.tsx +++ b/packages/mask/src/plugins/Wallet/SNSAdaptor/TransactionDialog.tsx @@ -13,6 +13,7 @@ import { useI18N } from '../../../utils' import { useRemoteControlledDialog } from '@masknet/shared-base-ui' import { InjectedDialog } from '../../../components/shared/InjectedDialog' import { WalletMessages } from '../messages' +import { activatedSocialNetworkUI } from '../../../social-network' const useStyles = makeStyles()((theme) => ({ content: { @@ -49,24 +50,24 @@ function TransactionDialogUI(props: TransactionDialogUIProps) { // #region remote controlled dialog const [state, setState] = useState(null) - const [shareLink, setShareLink] = useState('') + const [shareText, setShareText] = useState('') const [summary, setSummary] = useState('') const [title, setTitle] = useState(t('plugin_wallet_transaction')) const { open, closeDialog } = useRemoteControlledDialog(WalletMessages.events.transactionDialogUpdated, (ev) => { if (ev.open) { setState(ev.state) setSummary(ev.summary ?? '') - setShareLink(ev.shareLink ?? '') + setShareText(ev.shareText ?? '') setTitle(ev.title ?? t('plugin_wallet_transaction')) } else { setSummary('') - setShareLink('') + setShareText('') } }) const onShare = useCallback(() => { - if (shareLink) window.open(shareLink, '_blank', 'noopener noreferrer') + if (shareText) activatedSocialNetworkUI.utils.share?.(shareText) closeDialog() - }, [shareLink, closeDialog]) + }, [shareText, closeDialog]) // #endregion if (!state) return null @@ -140,8 +141,8 @@ function TransactionDialogUI(props: TransactionDialogUIProps) { size="large" variant="contained" fullWidth - onClick={state.type === TransactionStateType.FAILED || !shareLink ? closeDialog : onShare}> - {state.type === TransactionStateType.FAILED || !shareLink ? t('dismiss') : t('share')} + onClick={state.type === TransactionStateType.FAILED || !shareText ? closeDialog : onShare}> + {state.type === TransactionStateType.FAILED || !shareText ? t('dismiss') : t('share')} ) : null} diff --git a/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx b/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx index 339d35ee64bf..96e30a9465bd 100644 --- a/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx +++ b/packages/mask/src/plugins/dHEDGE/UI/InvestDialog.tsx @@ -144,24 +144,18 @@ export function InvestDialog() { // #region transaction dialog const cashTag = isTwitter(activatedSocialNetworkUI) ? '$' : '' - const shareLink = activatedSocialNetworkUI.utils - .getShareLinkURL?.( - token - ? [ - `I just invested ${formatBalance(amount, token.decimals)} ${cashTag}${token.symbol} in ${ - pool?.name - }. ${ - isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) - ? `Follow @${ - isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') - } (mask.io) to invest dHEDGE pools.` - : '' - }`, - '#mask_io', - ].join('\n') - : '', - ) - .toString() + const shareText = token + ? [ + `I just invested ${formatBalance(amount, token.decimals)} ${cashTag}${token.symbol} in ${pool?.name}. ${ + isTwitter(activatedSocialNetworkUI) || isFacebook(activatedSocialNetworkUI) + ? `Follow @${ + isTwitter(activatedSocialNetworkUI) ? t('twitter_account') : t('facebook_account') + } (mask.io) to invest dHEDGE pools.` + : '' + }`, + '#mask_io', + ].join('\n') + : '' // on close transaction dialog const { setDialog: setTransactionDialogOpen } = useRemoteControlledDialog( @@ -185,7 +179,7 @@ export function InvestDialog() { if (investState.type === TransactionStateType.UNKNOWN) return setTransactionDialogOpen({ open: true, - shareLink, + shareText, state: investState, summary: `Investing ${formatBalance(amount, token.decimals)}${token.symbol} on ${pool?.name} pool.`, }) diff --git a/packages/mask/src/social-network-adaptor/facebook.com/shared.ts b/packages/mask/src/social-network-adaptor/facebook.com/shared.ts index de5a2e1d6648..18a3e5fa00c0 100644 --- a/packages/mask/src/social-network-adaptor/facebook.com/shared.ts +++ b/packages/mask/src/social-network-adaptor/facebook.com/shared.ts @@ -18,6 +18,10 @@ export const facebookShared: SocialNetwork.Shared & SocialNetwork.Base = { isValidUsername: (v) => !!isValidFacebookUsername(v), textPayloadPostProcessor: undefined, getPostURL, + share(message) { + const url = this.getShareLinkURL!(message) + window.open(url, '_blank', 'noopener noreferrer') + }, getShareLinkURL(message) { const url = new URL('https://www.facebook.com/sharer/sharer.php') url.searchParams.set('quote', message) diff --git a/packages/mask/src/social-network-adaptor/minds.com/shared.ts b/packages/mask/src/social-network-adaptor/minds.com/shared.ts index 5175080fd0c8..bbc72b7a3382 100644 --- a/packages/mask/src/social-network-adaptor/minds.com/shared.ts +++ b/packages/mask/src/social-network-adaptor/minds.com/shared.ts @@ -16,6 +16,10 @@ export const mindsShared: SocialNetwork.Shared & SocialNetwork.Base = { isValidUsername: usernameValidator, textPayloadPostProcessor: undefined, getPostURL, + share(message) { + const url = this.getShareLinkURL!(message) + window.open(url, '_blank', 'noopener noreferrer') + }, getShareLinkURL(message) { return new URL(`https://www.minds.com/newsfeed/subscriptions?intentUrl=${encodeURIComponent(message)}`) }, diff --git a/packages/mask/src/social-network-adaptor/twitter.com/shared.ts b/packages/mask/src/social-network-adaptor/twitter.com/shared.ts index dcb4ef53063f..de652947450b 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/shared.ts +++ b/packages/mask/src/social-network-adaptor/twitter.com/shared.ts @@ -2,6 +2,7 @@ import { PostIdentifier, ProfileIdentifier } from '@masknet/shared-base' import type { SocialNetwork } from '../../social-network/types' import { createSNSAdaptorSpecializedPostContext } from '../../social-network/utils/create-post-context' import { deconstructPayload } from '../../utils' +import { createCenterWindowConfig } from '../utils' import { twitterBase } from './base' import { twitterEncoding } from './encoding' import { usernameValidator } from './utils/user' @@ -25,6 +26,11 @@ export const twitterShared: SocialNetwork.Shared & SocialNetwork.Base = { }, }, getPostURL, + share(text) { + const config = createCenterWindowConfig(700, 520) + const url = this.getShareLinkURL!(text) + window.open(url, 'share', config) || window.location.assign(url) + }, getShareLinkURL(message) { return new URL(`https://twitter.com/intent/tweet?text=${encodeURIComponent(message)}`) }, diff --git a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts index dfd3382cd18d..c9796191f7f6 100644 --- a/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts +++ b/packages/mask/src/social-network-adaptor/twitter.com/utils/selector.ts @@ -73,7 +73,14 @@ export const rootSelector: () => LiveSelector = () => querySelector( // `aside *` selectors are for mobile mode export const composeAnchorSelector: () => LiveSelector = () => - querySelector('header[role=banner] a[href="/compose/tweet"],aside a[href="/compose/tweet"]') + querySelector( + [ + 'header[role=banner] a[href="/compose/tweet"]', + 'aside a[href="/compose/tweet"]', + // can't see the compose button on share popup, use the tweetButton instead + '[role=main] [role=button][data-testid=tweetButton]', + ].join(), + ) export const composeAnchorTextSelector: () => LiveSelector = () => querySelector( 'header[role=banner] a[href="/compose/tweet"] div[dir],aside a[href="/compose/tweet"] div[dir]', diff --git a/packages/mask/src/social-network-adaptor/utils.ts b/packages/mask/src/social-network-adaptor/utils.ts index 1349c4980437..a0e6273f3514 100644 --- a/packages/mask/src/social-network-adaptor/utils.ts +++ b/packages/mask/src/social-network-adaptor/utils.ts @@ -23,3 +23,18 @@ export const getCurrentIdentifier = () => { globalUIState.profiles.value[0] ) } + +export const createCenterWindowConfig = (width: number, height: number) => { + const x = window.screenX + (window.innerWidth - width) / 2 + const y = window.screenY + (window.innerHeight - height) / 2 + return [ + `screenX=${x}`, + `screenY=${y}`, + 'toolbar=1', + 'status=1', + 'resizable=1', + 'scrollbars=1', + `height=${height}`, + `width=${width}`, + ].join(',') +} diff --git a/packages/mask/src/social-network/types.ts b/packages/mask/src/social-network/types.ts index 4eccad036093..6c963317b517 100644 --- a/packages/mask/src/social-network/types.ts +++ b/packages/mask/src/social-network/types.ts @@ -41,6 +41,8 @@ export namespace SocialNetwork { textPayloadPostProcessor?: PayloadEncoding /** Given a text, return a URL that will allow user to share this text */ getShareLinkURL?(text: string): URL + /** Handle share */ + share?(text: string): void createPostContext: ReturnType } export interface Shared { diff --git a/packages/plugins/Wallet/src/messages.ts b/packages/plugins/Wallet/src/messages.ts index b06410e2c8e6..f356a5c5be2f 100644 --- a/packages/plugins/Wallet/src/messages.ts +++ b/packages/plugins/Wallet/src/messages.ts @@ -18,7 +18,7 @@ export type TransactionDialogEvent = | { open: true state: TransactionState - shareLink?: string + shareText?: string summary?: string title?: string }