From bcd131f0d92b0ac0877dfab0a7010b8b3dfccd54 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Sun, 3 Mar 2024 10:58:37 +0800 Subject: [PATCH 1/2] fix(donation): prompt to reapprove if exceeded allowance --- lang/default.json | 21 ++++++++ lang/en.json | 21 ++++++++ lang/zh-Hans.json | 21 ++++++++ lang/zh-Hant.json | 21 ++++++++ src/common/enums/text.ts | 6 --- src/components/Dialogs/ENSDialog/LinkENS.tsx | 5 +- .../PayTo/SetAmount/SubmitButton.tsx | 41 ++++++++------ .../PaymentForm/PayTo/SetAmount/index.tsx | 54 +++++++++++-------- .../Forms/PaymentForm/Processing/index.tsx | 7 +-- 9 files changed, 148 insertions(+), 49 deletions(-) diff --git a/lang/default.json b/lang/default.json index 4fbf47b7e2..625947b28e 100644 --- a/lang/default.json +++ b/lang/default.json @@ -23,6 +23,9 @@ "+aMAeT": { "defaultMessage": "Address copied" }, + "+bwe8v": { + "defaultMessage": "Stripe will process your payment, so you can support the author wherever you are." + }, "+cS08C": { "defaultMessage": "Are you sure you want to remove ‘{article}’ from this collection?", "description": "src/components/Dialogs/RemoveArticleCollectionDialog/index.tsx" @@ -229,6 +232,9 @@ "3kbIhS": { "defaultMessage": "Untitled" }, + "3lMsOU": { + "defaultMessage": "Reapprove to continue" + }, "3phEFL": { "defaultMessage": "Continued use indicates your agreement to", "description": "src/components/Forms/SelectAuthMethodForm/NormalFeed.tsx" @@ -319,6 +325,9 @@ "defaultMessage": "Set threshold for circle (per month)", "description": "src/components/Forms/CreateCircleForm/Init.tsx" }, + "6ErzDk": { + "defaultMessage": "Reconnect Wallet" + }, "6N2LKY": { "defaultMessage": "Please log in again.", "description": "OAUTH_TOKEN_INVALID" @@ -828,6 +837,9 @@ "defaultMessage": "New followers", "description": "src/views/Me/Settings/Notifications/GeneralSettings/index.tsx" }, + "JmzmVH": { + "defaultMessage": "Switch to" + }, "JpS59y": { "defaultMessage": "Accepted", "description": "src/views/Circle/Settings/ManageInvitation/Invites/index.tsx" @@ -1160,6 +1172,9 @@ "defaultMessage": "Subscribers", "description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx" }, + "Tgd5id": { + "defaultMessage": "Transfer amount exceeds allowance" + }, "TjWWxF": { "defaultMessage": "Broadcast sent", "description": "src/views/Circle/Broadcast/Broadcast.tsx" @@ -1426,6 +1441,9 @@ "ai7kS4": { "defaultMessage": "My Works" }, + "aoDcrD": { + "defaultMessage": "Approve to continue" + }, "aqX2Bt": { "defaultMessage": "go to the homepage", "description": "src/views/Callback/UI.tsx" @@ -1883,6 +1901,9 @@ "defaultMessage": "Set password succeed", "description": "src/components/Dialogs/SetPasswordDialog/Content.tsx" }, + "pKkpI9": { + "defaultMessage": "The wallet address is not the one you bound to account. Please switch it in the wallet or reconnect as:" + }, "pRV+UD": { "defaultMessage": "Collapse", "description": "src/components/Comment/DropdownActions/CollapseComment/Button.tsx" diff --git a/lang/en.json b/lang/en.json index a12aa816fb..32ab5339e7 100644 --- a/lang/en.json +++ b/lang/en.json @@ -23,6 +23,9 @@ "+aMAeT": { "defaultMessage": "Address copied" }, + "+bwe8v": { + "defaultMessage": "Stripe will process your payment, so you can support the author wherever you are." + }, "+cS08C": { "defaultMessage": "Are you sure you want to remove ‘{article}’ from this collection?", "description": "src/components/Dialogs/RemoveArticleCollectionDialog/index.tsx" @@ -229,6 +232,9 @@ "3kbIhS": { "defaultMessage": "Untitled" }, + "3lMsOU": { + "defaultMessage": "Reapprove to continue" + }, "3phEFL": { "defaultMessage": "Continued use indicates your agreement to ", "description": "src/components/Forms/SelectAuthMethodForm/NormalFeed.tsx" @@ -319,6 +325,9 @@ "defaultMessage": "Set threshold for circle (per month)", "description": "src/components/Forms/CreateCircleForm/Init.tsx" }, + "6ErzDk": { + "defaultMessage": "Reconnect Wallet" + }, "6N2LKY": { "defaultMessage": "Please log in again.", "description": "OAUTH_TOKEN_INVALID" @@ -828,6 +837,9 @@ "defaultMessage": "New followers", "description": "src/views/Me/Settings/Notifications/GeneralSettings/index.tsx" }, + "JmzmVH": { + "defaultMessage": "Switch to " + }, "JpS59y": { "defaultMessage": "Accepted", "description": "src/views/Circle/Settings/ManageInvitation/Invites/index.tsx" @@ -1160,6 +1172,9 @@ "defaultMessage": "Subscribers", "description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx" }, + "Tgd5id": { + "defaultMessage": "Transfer amount exceeds allowance" + }, "TjWWxF": { "defaultMessage": "Broadcast sent", "description": "src/views/Circle/Broadcast/Broadcast.tsx" @@ -1426,6 +1441,9 @@ "ai7kS4": { "defaultMessage": "My Works" }, + "aoDcrD": { + "defaultMessage": "Approve to continue" + }, "aqX2Bt": { "defaultMessage": "go to the homepage", "description": "src/views/Callback/UI.tsx" @@ -1883,6 +1901,9 @@ "defaultMessage": "Set password succeed", "description": "src/components/Dialogs/SetPasswordDialog/Content.tsx" }, + "pKkpI9": { + "defaultMessage": "The wallet address is not the one you bound to account. Please switch it in the wallet or reconnect as:" + }, "pRV+UD": { "defaultMessage": "Collapse", "description": "src/components/Comment/DropdownActions/CollapseComment/Button.tsx" diff --git a/lang/zh-Hans.json b/lang/zh-Hans.json index a5e43400b0..faddd50b83 100644 --- a/lang/zh-Hans.json +++ b/lang/zh-Hans.json @@ -23,6 +23,9 @@ "+aMAeT": { "defaultMessage": "地址已复制" }, + "+bwe8v": { + "defaultMessage": "Stripe will process your payment, so you can support the author wherever you are." + }, "+cS08C": { "defaultMessage": "确认要将“{article}”从选集中移出吗?", "description": "src/components/Dialogs/RemoveArticleCollectionDialog/index.tsx" @@ -229,6 +232,9 @@ "3kbIhS": { "defaultMessage": "未命名" }, + "3lMsOU": { + "defaultMessage": "重新授权后继续" + }, "3phEFL": { "defaultMessage": "继续使用表示您同意", "description": "src/components/Forms/SelectAuthMethodForm/NormalFeed.tsx" @@ -319,6 +325,9 @@ "defaultMessage": "设定围炉门槛(每月)", "description": "src/components/Forms/CreateCircleForm/Init.tsx" }, + "6ErzDk": { + "defaultMessage": "重新连接钱包" + }, "6N2LKY": { "defaultMessage": "授权信息已失效,请重新登入", "description": "OAUTH_TOKEN_INVALID" @@ -828,6 +837,9 @@ "defaultMessage": "被追踪", "description": "src/views/Me/Settings/Notifications/GeneralSettings/index.tsx" }, + "JmzmVH": { + "defaultMessage": "切换到 " + }, "JpS59y": { "defaultMessage": "已接受", "description": "src/views/Circle/Settings/ManageInvitation/Invites/index.tsx" @@ -1160,6 +1172,9 @@ "defaultMessage": "付费人数", "description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx" }, + "Tgd5id": { + "defaultMessage": "支持金额超出授权额度" + }, "TjWWxF": { "defaultMessage": "广播已送出", "description": "src/views/Circle/Broadcast/Broadcast.tsx" @@ -1426,6 +1441,9 @@ "ai7kS4": { "defaultMessage": "我的创作" }, + "aoDcrD": { + "defaultMessage": "首次需确认授权后继续" + }, "aqX2Bt": { "defaultMessage": "前往首页", "description": "src/views/Callback/UI.tsx" @@ -1883,6 +1901,9 @@ "defaultMessage": "登录密码已设置", "description": "src/components/Dialogs/SetPasswordDialog/Content.tsx" }, + "pKkpI9": { + "defaultMessage": "The wallet address is not the one you bound to account. Please switch it in the wallet or reconnect as:" + }, "pRV+UD": { "defaultMessage": "折叠", "description": "src/components/Comment/DropdownActions/CollapseComment/Button.tsx" diff --git a/lang/zh-Hant.json b/lang/zh-Hant.json index e49c2dac2a..35f39ef308 100644 --- a/lang/zh-Hant.json +++ b/lang/zh-Hant.json @@ -23,6 +23,9 @@ "+aMAeT": { "defaultMessage": "地址已複製" }, + "+bwe8v": { + "defaultMessage": "Stripe will process your payment, so you can support the author wherever you are." + }, "+cS08C": { "defaultMessage": "確認要將「{article}」從選集中移出嗎?", "description": "src/components/Dialogs/RemoveArticleCollectionDialog/index.tsx" @@ -229,6 +232,9 @@ "3kbIhS": { "defaultMessage": "未命名" }, + "3lMsOU": { + "defaultMessage": "重新授權後繼續" + }, "3phEFL": { "defaultMessage": "繼續使用表示您同意", "description": "src/components/Forms/SelectAuthMethodForm/NormalFeed.tsx" @@ -319,6 +325,9 @@ "defaultMessage": "設定圍爐門檻(每月)", "description": "src/components/Forms/CreateCircleForm/Init.tsx" }, + "6ErzDk": { + "defaultMessage": "重新連接錢包" + }, "6N2LKY": { "defaultMessage": "授權信息已失效,請重新登入", "description": "OAUTH_TOKEN_INVALID" @@ -828,6 +837,9 @@ "defaultMessage": "被追蹤", "description": "src/views/Me/Settings/Notifications/GeneralSettings/index.tsx" }, + "JmzmVH": { + "defaultMessage": "切換到 " + }, "JpS59y": { "defaultMessage": "已接受", "description": "src/views/Circle/Settings/ManageInvitation/Invites/index.tsx" @@ -1160,6 +1172,9 @@ "defaultMessage": "付費人數", "description": "src/views/Circle/Analytics/SubscriberAnalytics/index.tsx" }, + "Tgd5id": { + "defaultMessage": "支持金額超出授權額度" + }, "TjWWxF": { "defaultMessage": "廣播已送出", "description": "src/views/Circle/Broadcast/Broadcast.tsx" @@ -1426,6 +1441,9 @@ "ai7kS4": { "defaultMessage": "我的創作" }, + "aoDcrD": { + "defaultMessage": "首次需確認授權後繼續" + }, "aqX2Bt": { "defaultMessage": "前往首頁", "description": "src/views/Callback/UI.tsx" @@ -1883,6 +1901,9 @@ "defaultMessage": "登入密碼已設定", "description": "src/components/Dialogs/SetPasswordDialog/Content.tsx" }, + "pKkpI9": { + "defaultMessage": "The wallet address is not the one you bound to account. Please switch it in the wallet or reconnect as:" + }, "pRV+UD": { "defaultMessage": "闔上", "description": "src/components/Comment/DropdownActions/CollapseComment/Button.tsx" diff --git a/src/common/enums/text.ts b/src/common/enums/text.ts index f976ae5bd9..62d59131f8 100644 --- a/src/common/enums/text.ts +++ b/src/common/enums/text.ts @@ -120,8 +120,6 @@ export const TEXT = { readCount: '閱讀次數', readHistory: '瀏覽記錄', readTime: '累計閱讀時數', - reconnectHint: - '當前錢包地址與帳戶綁定不同,若要變更請直接操作錢包或重新連接為:', refund: '退款', refuse: '拒絕', register: '註冊', @@ -339,8 +337,6 @@ export const TEXT = { readCount: '阅读次数', readHistory: '浏览记录', readTime: '累计阅读时数', - reconnectHint: - '当前钱包地址与帐户绑定不同,若要变更请直接操作钱包或重新连接为:', refund: '退款', refuse: '拒绝', register: '注册', @@ -572,8 +568,6 @@ export const TEXT = { readCount: 'Read Counts', readHistory: 'Read History', readTime: 'Accumulated Read Time', - reconnectHint: - 'The wallet address is not the one you bound to account. Please switch it in the wallet or reconnect as: ', refund: 'Refund', refuse: 'Decline', register: 'Register', diff --git a/src/components/Dialogs/ENSDialog/LinkENS.tsx b/src/components/Dialogs/ENSDialog/LinkENS.tsx index 9a22dea506..8f4d2d3c0c 100644 --- a/src/components/Dialogs/ENSDialog/LinkENS.tsx +++ b/src/components/Dialogs/ENSDialog/LinkENS.tsx @@ -198,7 +198,10 @@ const LinkENS = ({

- + = ({ formId, isValid, isSubmitting, + isExceededAllowance, isBalanceInsufficient, isConnectedAddress, isUnsupportedNetwork, @@ -142,11 +139,7 @@ const USDTSubmitButton: React.FC = ({ + } onClick={() => { disconnect() @@ -161,7 +154,7 @@ const USDTSubmitButton: React.FC = ({ mode={mode} text={ <> - + {targetChainName} } @@ -176,10 +169,26 @@ const USDTSubmitButton: React.FC = ({ + } + loading={approving || approveConfirming || allowanceLoading} + onClick={() => { + if (approveWrite) { + approveWrite() + } + }} + /> + ) + } + + if (!isUnsupportedNetwork && isExceededAllowance) { + return ( + } loading={approving || approveConfirming || allowanceLoading} diff --git a/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx b/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx index b9e728199a..a5451ef854 100644 --- a/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx +++ b/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx @@ -4,10 +4,12 @@ import _get from 'lodash/get' import _pickBy from 'lodash/pickBy' import { useContext, useEffect, useRef, useState } from 'react' import { FormattedMessage, useIntl } from 'react-intl' +import { parseUnits } from 'viem' import { useAccount } from 'wagmi' import { waitForTransaction } from 'wagmi/actions' import { + contract, PAYMENT_CURRENCY as CURRENCY, PAYMENT_MAXIMUM_PAYTO_AMOUNT, WALLET_ERROR_MESSAGES, @@ -30,7 +32,6 @@ import { Spacer, Spinner, TextIcon, - Translate, useAllowanceUSDT, useApproveUSDT, useBalanceUSDT, @@ -129,18 +130,13 @@ const SetAmount: React.FC = ({ const { data: exchangeRateDate, loading: exchangeRateLoading } = useQuery(EXCHANGE_RATES, { - variables: { - from: currency, - to: quoteCurrency, - }, + variables: { from: currency, to: quoteCurrency }, }) // HKD balance const { data, loading, error } = useQuery( WALLET_BALANCE, - { - fetchPolicy: 'network-only', - } + { fetchPolicy: 'network-only' } ) // USDT balance & allowance @@ -165,13 +161,6 @@ const SetAmount: React.FC = ({ const balanceLike = data?.viewer?.liker.total || 0 const balance = isUSDT ? balanceUSDT : isHKD ? balanceHKD : balanceLike const maxAmount = isHKD ? PAYMENT_MAXIMUM_PAYTO_AMOUNT.HKD : Infinity - const networkError = - error || - (isUSDT && !isUnsupportedNetwork - ? allowanceError || balanceUSDTError || approveError - : undefined) - ? WALLET_ERROR_MESSAGES[lang].unknown - : '' // forms const { @@ -230,22 +219,37 @@ const SetAmount: React.FC = ({ }, }) - const isBalanceInsufficient = balance < (values.customAmount || values.amount) + const value = values.customAmount || values.amount + const isBalanceInsufficient = balance < value + const isExceededAllowance = + parseUnits(value + '', contract.Optimism.tokenDecimals) > allowanceUSDT + const hasUSDTNetworkError = // TODO: better error handling + isUSDT && + !isUnsupportedNetwork && + (allowanceError || balanceUSDTError || approveError) + const networkError = + error || hasUSDTNetworkError ? ( + WALLET_ERROR_MESSAGES[lang].unknown + ) : isExceededAllowance ? ( + + ) : ( + '' + ) const ComposedAmountInputHint = () => { const hkdHint = isHKD ? (

-
) : null - const value = values.customAmount || values.amount - const rate = _get(exchangeRateDate, 'exchangeRates.0.rate', 0) const convertedTotal = formatAmount(value * rate, 2) @@ -374,6 +378,7 @@ const SetAmount: React.FC = ({ recipient, isValid, isSubmitting, + isExceededAllowance, isBalanceInsufficient, isConnectedAddress, isUnsupportedNetwork, @@ -402,7 +407,10 @@ const SetAmount: React.FC = ({ {isUSDT && !isConnectedAddress && ( <>

- + = ({ const [payTo] = useMutation(PAY_TO) const viewer = useContext(ViewerContext) const { address } = useAccount() - const { data: balanceUSDTData } = useBalanceUSDT({}) const { chain } = useNetwork() const isUnsupportedNetwork = !!chain?.unsupported const isConnectedAddress = @@ -218,7 +216,10 @@ const USDTProcessingForm: React.FC = ({ args: [ recipient.info.ethAddress as `0x${string}`, contract.Optimism.tokenAddress, - parseUnits(amount.toString() as `${number}`, balanceUSDTData?.decimals!), + parseUnits( + amount.toString() as `${number}`, + contract.Optimism.tokenDecimals + ), `ipfs://${article?.dataHash}`, ], }) From 24508636a906af55f508d7026ae53b2aef0a71e6 Mon Sep 17 00:00:00 2001 From: robertu <4065233+robertu7@users.noreply.github.com> Date: Sun, 3 Mar 2024 11:18:51 +0800 Subject: [PATCH 2/2] fix(donation): skip polling tx state if tx id is not provided refs: - 2024-02-product-01#PN-0002 --- src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx | 1 + src/components/Forms/PaymentForm/Processing/index.tsx | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx b/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx index a5451ef854..76be42a3d8 100644 --- a/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx +++ b/src/components/Forms/PaymentForm/PayTo/SetAmount/index.tsx @@ -222,6 +222,7 @@ const SetAmount: React.FC = ({ const value = values.customAmount || values.amount const isBalanceInsufficient = balance < value const isExceededAllowance = + allowanceUSDT > 0n && parseUnits(value + '', contract.Optimism.tokenDecimals) > allowanceUSDT const hasUSDTNetworkError = // TODO: better error handling isUSDT && diff --git a/src/components/Forms/PaymentForm/Processing/index.tsx b/src/components/Forms/PaymentForm/Processing/index.tsx index c168564f30..f9ba31f394 100644 --- a/src/components/Forms/PaymentForm/Processing/index.tsx +++ b/src/components/Forms/PaymentForm/Processing/index.tsx @@ -83,7 +83,7 @@ const OthersProcessingForm: React.FC = ({ variables: { id: txId }, errorPolicy: 'none', fetchPolicy: 'network-only', - skip: typeof window === 'undefined', + skip: typeof window === 'undefined' || !txId, }) const txState = _get(data, 'viewer.wallet.transactions.edges.0.node.state') @@ -105,7 +105,7 @@ const OthersProcessingForm: React.FC = ({ useEffect(() => { if (error) { stopPolling() - } else { + } else if (txId) { startPolling(1000) }