Skip to content

Commit

Permalink
fix approval label and disabling transfer button
Browse files Browse the repository at this point in the history
  • Loading branch information
gmxer committed May 13, 2024
1 parent eb591f4 commit 153d89d
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/components/ApproveTokenButton/ApproveTokenButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {
tokenSymbol: string;
isApproved?: boolean;
approveAmount?: BigNumber;
customLabel?: string;
};

export function ApproveTokenButton(p: Props) {
Expand Down Expand Up @@ -46,9 +47,7 @@ export function ApproveTokenButton(p: Props) {

return (
<div className="ApproveTokenButton Checkbox fullRow" onClick={onApprove}>
<span className="text-warning">
<Trans>Allow {p.tokenSymbol} to be spent</Trans>
</span>
<span className="text-warning">{p.customLabel ?? <Trans>Allow {p.tokenSymbol} to be spent</Trans>}</span>

<div className="ApproveTokenButton-checkbox">
{isLoading ? (
Expand Down
8 changes: 8 additions & 0 deletions src/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "Alle"
msgid "All time"
msgstr "Gesamtzeit"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "Bezahlen"
msgid "Pay Amount"
msgstr "Betrag bezahlen"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "All"
msgid "All time"
msgstr "All time"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr "Allow all my tokens to be transferred to a new account"

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr "Allow {0} to be spent"
Expand Down Expand Up @@ -4136,6 +4140,10 @@ msgstr "Pay"
msgid "Pay Amount"
msgstr "Pay Amount"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr "Pending Transfer Approval"

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr "Pending Wallet message sign"
Expand Down
8 changes: 8 additions & 0 deletions src/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "Todo"
msgid "All time"
msgstr "Todo el tiempo"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "Pagar"
msgid "Pay Amount"
msgstr "Importe a pagar"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "Tout"
msgid "All time"
msgstr "Tout le temps"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "Payer"
msgid "Pay Amount"
msgstr "Somme à payer"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "すべて"
msgid "All time"
msgstr "すべての時間"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "支払い"
msgid "Pay Amount"
msgstr "支払い額"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "모두"
msgid "All time"
msgstr "모든 시간"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "지불"
msgid "Pay Amount"
msgstr "지불액"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/pseudo/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr ""
msgid "All time"
msgstr ""

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr ""
msgid "Pay Amount"
msgstr ""

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/ru/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "Все"
msgid "All time"
msgstr "Всё время"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "Оплатить"
msgid "Pay Amount"
msgstr "Оплата Суммы"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
8 changes: 8 additions & 0 deletions src/locales/zh/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,10 @@ msgstr "全部"
msgid "All time"
msgstr "所有时间"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Allow all my tokens to be transferred to a new account"
msgstr ""

#: src/components/ApproveTokenButton/ApproveTokenButton.tsx
msgid "Allow {0} to be spent"
msgstr ""
Expand Down Expand Up @@ -4133,6 +4137,10 @@ msgstr "支付"
msgid "Pay Amount"
msgstr "支付金额"

#: src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
msgid "Pending Transfer Approval"
msgstr ""

#: src/components/Synthetics/StatusNotification/SubaccountNotification.tsx
msgid "Pending Wallet message sign"
msgstr ""
Expand Down
49 changes: 29 additions & 20 deletions src/pages/BeginAccountTransfer/BeginAccountTransfer.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import React, { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import useSWR from "swr";
import { ethers } from "ethers";
import { ApproveTokenButton } from "components/ApproveTokenButton/ApproveTokenButton";
import { getContract } from "config/contracts";
import { ethers } from "ethers";
import { useMemo, useState } from "react";
import { Link } from "react-router-dom";
import useSWR from "swr";

import Modal from "components/Modal/Modal";
import Footer from "components/Footer/Footer";
import Modal from "components/Modal/Modal";

import RewardRouter from "abis/RewardRouter.json";
import RewardTracker from "abis/RewardTracker.json";
import Token from "abis/Token.json";
import Vester from "abis/Vester.json";
import RewardTracker from "abis/RewardTracker.json";
import RewardRouter from "abis/RewardRouter.json";

import { FaCheck, FaTimes } from "react-icons/fa";

import { Trans, t } from "@lingui/macro";

import "./BeginAccountTransfer.css";
import { callContract, contractFetcher } from "lib/contracts";
import { approveTokens } from "domain/tokens";
import { useChainId } from "lib/chains";
import Button from "components/Button/Button";
import useWallet from "lib/wallets/useWallet";
import Checkbox from "components/Checkbox/Checkbox";
import { usePendingTxns } from "lib/usePendingTxns";
import { getNeedTokenApprove, useTokenBalances, useTokensAllowanceData } from "domain/synthetics/tokens";
import { approveTokens } from "domain/tokens";
import { useChainId } from "lib/chains";
import { callContract, contractFetcher } from "lib/contracts";
import { usePendingTxns } from "lib/usePendingTxns";
import useWallet from "lib/wallets/useWallet";
import { zeroAddress } from "viem";
import "./BeginAccountTransfer.css";

function ValidationRow({ isValid, children }) {
return (
Expand Down Expand Up @@ -188,6 +188,10 @@ export default function BeginAccountTransfer() {
if (isTransferring) {
return false;
}

if (needFeeGmxTrackerApproval) {
return false;
}
return true;
};

Expand All @@ -206,6 +210,10 @@ export default function BeginAccountTransfer() {
return t`Transferring`;
}

if (needFeeGmxTrackerApproval) {
return t`Pending Transfer Approval`;
}

return t`Begin Transfer`;
};

Expand Down Expand Up @@ -240,23 +248,23 @@ export default function BeginAccountTransfer() {
const completeTransferLink = `/complete_account_transfer/${account}/${parsedReceiver}`;
const pendingTransferLink = `/complete_account_transfer/${account}/${pendingReceiver}`;

const feeGmxTracker = getContract(chainId, "FeeGmxTracker");
const feeGmxTrackerAddress = getContract(chainId, "FeeGmxTracker");

const { tokensAllowanceData } = useTokensAllowanceData(chainId, {
spenderAddress: parsedReceiver,
tokenAddresses: [feeGmxTracker],
tokenAddresses: [feeGmxTrackerAddress],
});
const { balancesData } = useTokenBalances(chainId, undefined, [{ address: feeGmxTracker }], 1000);
const { balancesData } = useTokenBalances(chainId, undefined, [{ address: feeGmxTrackerAddress }], 1000);

const feeGmxTrackerBalance = balancesData?.[feeGmxTracker];
const feeGmxTrackerBalance = balancesData?.[feeGmxTrackerAddress];
const needFeeGmxTrackerApproval = useMemo(
() =>
parsedReceiver &&
feeGmxTrackerBalance &&
parsedReceiver !== zeroAddress &&
tokensAllowanceData &&
getNeedTokenApprove(tokensAllowanceData, feeGmxTracker, feeGmxTrackerBalance),
[feeGmxTracker, feeGmxTrackerBalance, parsedReceiver, tokensAllowanceData]
getNeedTokenApprove(tokensAllowanceData, feeGmxTrackerAddress, feeGmxTrackerBalance),
[feeGmxTrackerAddress, feeGmxTrackerBalance, parsedReceiver, tokensAllowanceData]
);

return (
Expand Down Expand Up @@ -352,8 +360,9 @@ export default function BeginAccountTransfer() {
{needFeeGmxTrackerApproval && (
<>
<ApproveTokenButton
tokenAddress={feeGmxTracker}
tokenAddress={feeGmxTrackerAddress}
tokenSymbol={"sbfGMX"}
customLabel={t`Allow all my tokens to be transferred to a new account`}
spenderAddress={parsedReceiver}
approveAmount={feeGmxTrackerBalance}
/>
Expand Down

0 comments on commit 153d89d

Please sign in to comment.