Skip to content

Commit

Permalink
Fix approve buttons, update swap token details section
Browse files Browse the repository at this point in the history
  • Loading branch information
totop716 committed Jan 6, 2022
1 parent 8b8f52c commit f643e94
Show file tree
Hide file tree
Showing 18 changed files with 563 additions and 422 deletions.
26 changes: 22 additions & 4 deletions src/components/AddLiquidity/AddLiquidity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ const AddLiquidity: React.FC<{
const isnotMatic =
ethereum && ethereum.isMetaMask && Number(ethereum.chainId) !== 137;
const toggleWalletModal = useWalletModalToggle();
const [approvingA, setApprovingA] = useState(false);
const [approvingB, setApprovingB] = useState(false);
const [approvalA, approveACallback] = useApproveCallback(
parsedAmounts[Field.CURRENCY_A],
ROUTER_ADDRESS,
Expand Down Expand Up @@ -546,8 +548,16 @@ const AddLiquidity: React.FC<{
width={approvalB !== ApprovalState.APPROVED ? '48%' : '100%'}
>
<Button
onClick={approveACallback}
disabled={approvalA === ApprovalState.PENDING}
onClick={async () => {
setApprovingA(true);
try {
await approveACallback();
setApprovingA(false);
} catch (e) {
setApprovingA(false);
}
}}
disabled={approvingA || approvalA === ApprovalState.PENDING}
>
{approvalA === ApprovalState.PENDING
? `Approving ${currencies[Field.CURRENCY_A]?.symbol}`
Expand All @@ -560,8 +570,16 @@ const AddLiquidity: React.FC<{
width={approvalA !== ApprovalState.APPROVED ? '48%' : '100%'}
>
<Button
onClick={approveBCallback}
disabled={approvalB === ApprovalState.PENDING}
onClick={async () => {
setApprovingB(true);
try {
await approveBCallback();
setApprovingB(false);
} catch (e) {
setApprovingB(false);
}
}}
disabled={approvingB || approvalB === ApprovalState.PENDING}
>
{approvalB === ApprovalState.PENDING
? `Approving ${currencies[Field.CURRENCY_B]?.symbol}`
Expand Down
37 changes: 36 additions & 1 deletion src/components/CurrencyLogo/CurrencyLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ export const getTokenLogoURL = (address: string) => {
}
if (
address?.toLowerCase() ===
'0x348e62131fce2F4e0d5ead3Fe1719Bc039B380A9'.toLowerCase()
'0x430EF9263E76DAE63c84292C3409D61c598E9682'.toLowerCase()
) {
uri =
'https://assets.coingecko.com/coins/images/14770/small/1617088937196.png?1619414736';
Expand Down Expand Up @@ -1502,6 +1502,41 @@ export const getTokenLogoURL = (address: string) => {
'https://assets.coingecko.com/coins/images/20403/small/ep7GqM19_400x400.jpg?1636979120';
}

if (
address?.toLowerCase() ===
'0xc10358f062663448a3489fC258139944534592ac'.toLowerCase()
) {
uri = 'https://bcmhunt.com/bcmc-coin-512x512.png';
}
if (
address?.toLowerCase() ===
'0xcD86152047e800d67BDf00A4c635A8B6C0e5C4c2'.toLowerCase()
) {
uri =
'https://assets.coingecko.com/coins/images/21635/small/NF_nacho_2_200x200.png?1639627573';
}
if (
address?.toLowerCase() ===
'0x948D0a28b600BDBd77AF4ea30E6F338167034181'.toLowerCase()
) {
uri =
'https://assets.coingecko.com/coins/images/21692/small/NF_nshare_2_200x200.png?1639721239';
}
if (
address?.toLowerCase() ===
'0xf244E91A46A9cdd48da295cA5d0B27894f8032B1'.toLowerCase()
) {
uri =
'https://assets.coingecko.com/coins/images/22092/small/3Rx82r_w_400x400.png?1640823145';
}
if (
address?.toLowerCase() ===
'0xdf9B4b57865B403e08c85568442f95c26b7896b0'.toLowerCase()
) {
uri =
'https://assets.coingecko.com/coins/images/22198/small/download.png?1641192480';
}

if (
address?.toLowerCase() ===
'0xB35fcBCF1fD489fCe02Ee146599e893FDCdC60e6'.toLowerCase()
Expand Down
15 changes: 13 additions & 2 deletions src/components/FarmDualCard/FarmDualCardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const FarmDualCardDetails: React.FC<{
const [attemptStaking, setAttemptStaking] = useState(false);
const [attemptUnstaking, setAttemptUnstaking] = useState(false);
const [attemptClaimReward, setAttemptClaimReward] = useState(false);
const [approving, setApproving] = useState(false);
// const [hash, setHash] = useState<string | undefined>();
const [unstakeAmount, setUnStakeAmount] = useState('');
const stakingInfos = useDualStakingInfo(pair);
Expand Down Expand Up @@ -473,6 +474,7 @@ const FarmDualCardDetails: React.FC<{
</Box>
<Box
className={
!approving &&
Number(!attemptStaking && stakeAmount) > 0 &&
Number(stakeAmount) <=
Number(userLiquidityUnstaked?.toSignificant())
Expand All @@ -482,8 +484,9 @@ const FarmDualCardDetails: React.FC<{
mb={2}
mt={2}
p={2}
onClick={() => {
onClick={async () => {
if (
!approving &&
!attemptStaking &&
Number(stakeAmount) > 0 &&
Number(stakeAmount) <=
Expand All @@ -495,7 +498,13 @@ const FarmDualCardDetails: React.FC<{
) {
onStake();
} else {
onAttemptToApprove();
setApproving(true);
try {
await onAttemptToApprove();
setApproving(false);
} catch (e) {
setApproving(false);
}
}
}
}}
Expand All @@ -506,6 +515,8 @@ const FarmDualCardDetails: React.FC<{
: approval === ApprovalState.APPROVED ||
signatureData !== null
? 'Stake LP Tokens'
: approving
? 'Approving...'
: 'Approve'}
</Typography>
</Box>
Expand Down
17 changes: 14 additions & 3 deletions src/components/FarmLPCard/FarmLPCardDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ const FarmLPCardDetails: React.FC<{
const [attemptStaking, setAttemptStaking] = useState(false);
const [attemptUnstaking, setAttemptUnstaking] = useState(false);
const [attemptClaiming, setAttemptClaiming] = useState(false);
const [approving, setApproving] = useState(false);
const [unstakeAmount, setUnStakeAmount] = useState('');
const stakingInfos = useStakingInfo(pair);
const oldStakingInfos = useOldStakingInfo(pair);
Expand Down Expand Up @@ -405,7 +406,7 @@ const FarmLPCardDetails: React.FC<{
message,
});

library
return library
.send('eth_signTypedData_v4', [account, data])
.then(splitSignature)
.then((signature) => {
Expand Down Expand Up @@ -540,6 +541,7 @@ const FarmLPCardDetails: React.FC<{
</Box>
<Box
className={
!approving &&
Number(!attemptStaking && stakeAmount) > 0 &&
Number(stakeAmount) <=
Number(userLiquidityUnstaked?.toSignificant())
Expand All @@ -549,8 +551,9 @@ const FarmLPCardDetails: React.FC<{
mb={2}
mt={2}
p={2}
onClick={() => {
onClick={async () => {
if (
!approving &&
!attemptStaking &&
Number(stakeAmount) > 0 &&
Number(stakeAmount) <=
Expand All @@ -562,7 +565,13 @@ const FarmLPCardDetails: React.FC<{
) {
onStake();
} else {
onAttemptToApprove();
setApproving(true);
try {
await onAttemptToApprove();
setApproving(false);
} catch (e) {
setApproving(false);
}
}
}
}}
Expand All @@ -573,6 +582,8 @@ const FarmLPCardDetails: React.FC<{
: approval === ApprovalState.APPROVED ||
signatureData !== null
? 'Stake LP Tokens'
: approving
? 'Approving...'
: 'Approve'}
</Typography>
</Box>
Expand Down
15 changes: 12 additions & 3 deletions src/components/StakeQuickModal/StakeQuickModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const StakeQuickModal: React.FC<StakeQuickModalProps> = ({ open, onClose }) => {
const userLiquidityUnstaked = useTokenBalance(account ?? undefined, QUICK);
const [typedValue, setTypedValue] = useState('');
const [stakePercent, setStakePercent] = useState(0);
const [approving, setApproving] = useState(false);
const { parsedAmount, error } = useDerivedLairInfo(
typedValue,
QUICK,
Expand Down Expand Up @@ -205,10 +206,18 @@ const StakeQuickModal: React.FC<StakeQuickModalProps> = ({ open, onClose }) => {
>
<Button
className={classes.stakeButton}
disabled={approval !== ApprovalState.NOT_APPROVED}
onClick={onAttemptToApprove}
disabled={approving || approval !== ApprovalState.NOT_APPROVED}
onClick={async () => {
setApproving(true);
try {
await onAttemptToApprove();
setApproving(false);
} catch (e) {
setApproving(false);
}
}}
>
Approve
{approving ? 'Approving...' : 'Approve'}
</Button>
<Button
className={classes.stakeButton}
Expand Down
15 changes: 12 additions & 3 deletions src/components/StakeSyrupModal/StakeSyrupModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const StakeSyrupModal: React.FC<StakeSyrupModalProps> = ({
);
const [typedValue, setTypedValue] = useState('');
const [stakePercent, setStakePercent] = useState(0);
const [approving, setApproving] = useState(false);
const maxAmountInput = maxAmountSpend(userLiquidityUnstaked);
const { parsedAmount, error } = useDerivedSyrupInfo(
typedValue,
Expand Down Expand Up @@ -278,10 +279,18 @@ const StakeSyrupModal: React.FC<StakeSyrupModalProps> = ({
>
<Button
className={classes.stakeButton}
disabled={approval !== ApprovalState.NOT_APPROVED}
onClick={onAttemptToApprove}
disabled={approving || approval !== ApprovalState.NOT_APPROVED}
onClick={async () => {
setApproving(true);
try {
await onAttemptToApprove();
setApproving(false);
} catch (e) {
setApproving(false);
}
}}
>
Approve
{approving ? 'Approving...' : 'Approve'}
</Button>
<Button
className={classes.stakeButton}
Expand Down
15 changes: 13 additions & 2 deletions src/components/Swap/Swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const Swap: React.FC<{
} = useSwapActionHandlers();
const { address: recipientAddress } = useENSAddress(recipient);
const [allowedSlippage] = useUserSlippageTolerance();
const [approving, setApproving] = useState(false);
const [approval, approveCallback] = useApproveCallbackFromTrade(
trade,
allowedSlippage,
Expand Down Expand Up @@ -670,9 +671,19 @@ const Swap: React.FC<{
<Button
color='primary'
disabled={
approval !== ApprovalState.NOT_APPROVED || approvalSubmitted
approving ||
approval !== ApprovalState.NOT_APPROVED ||
approvalSubmitted
}
onClick={approveCallback}
onClick={async () => {
setApproving(true);
try {
await approveCallback();
setApproving(false);
} catch (err) {
setApproving(false);
}
}}
>
{approval === ApprovalState.PENDING ? (
<Box className='content'>
Expand Down
Loading

0 comments on commit f643e94

Please sign in to comment.