Skip to content

Commit

Permalink
Fix/401 double claiming (#402)
Browse files Browse the repository at this point in the history
* Disable Claim CSOV option when none available. Closes #392 (#393)

* Fixes #401 - prevents multiple txs being sent when claiming tokens

Co-authored-by: soulBit <[email protected]>
  • Loading branch information
creed-victor and soulBit authored Feb 18, 2021
1 parent 0c621e9 commit 4efc123
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/app/containers/WalletPage/components/CSovActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function CSovActions(props: Props) {

return (
<>
{processed ? (
{!processed ? (
<p className="text-gold my-0" style={{ opacity: 0.3 }}>
Already Claimed.
</p>
Expand All @@ -41,7 +41,7 @@ export function CSovActions(props: Props) {
text={t(translations.userAssets.actions.claimSov)}
className="text-gold button-round"
onClick={() => setDialog(DialogType.CLAIM)}
disabled={processed}
disabled={processed || parseInt(props.amount) === 0}
loading={loading}
/>
{/*<Button*/}
Expand Down
23 changes: 17 additions & 6 deletions src/app/containers/WalletPage/components/ClaimDialiog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback } from 'react';
import { Classes, Overlay } from '@blueprintjs/core';
import classNames from 'classnames';
import styles from './dialog.module.css';
Expand All @@ -10,7 +10,10 @@ import { Button } from '../../../components/Button';
import { useAccount } from '../../../hooks/useAccount';
import { useCacheCallWithValue } from '../../../hooks/useCacheCallWithValue';
import { useSendContractTx } from '../../../hooks/useSendContractTx';
import { TxType } from '../../../../store/global/transactions-store/types';
import {
TxStatus,
TxType,
} from '../../../../store/global/transactions-store/types';
import { SendTxProgress } from '../../../components/SendTxProgress';
import { gasLimit } from '../../../../utils/classifiers';

Expand All @@ -32,12 +35,13 @@ export function ClaimDialog(props: Props) {
'vestingRegistry',
'exchangeAllCSOV',
);
const handleSubmit = () =>
const handleSubmit = useCallback(() => {
send(
[],
{ from: account, gas: gasLimit[TxType.SOV_CONVERT] },
{ type: TxType.SOV_CONVERT },
);
}, [account, send]);
return (
<>
<Overlay
Expand Down Expand Up @@ -95,7 +99,7 @@ export function ClaimDialog(props: Props) {
</DummyField>
</FieldGroup>

<div className={styles.txFee}>Tx Fee: 0.000004 (r)BTC</div>
<div className={styles.txFee}>Tx Fee: 0.00016 (r)BTC</div>
{processed && (
<p className={styles.txFee}>Already processed!</p>
)}
Expand All @@ -110,10 +114,17 @@ export function ClaimDialog(props: Props) {
<div className="d-flex flex-row justify-content-between align-items-center">
<Button
text="Confirm"
onClick={handleSubmit}
onClick={() => handleSubmit()}
className="mr-3 w-100"
loading={tx.loading || loading}
// disabled={tx.loading || loading || processed}
disabled={
tx.loading ||
[TxStatus.PENDING_FOR_USER, TxStatus.PENDING].includes(
tx.status,
) ||
loading ||
processed
}
/>
<Button
text="Cancel"
Expand Down
22 changes: 16 additions & 6 deletions src/app/containers/WalletPage/components/RedeemDialiog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useCallback } from 'react';
import { Classes, Overlay } from '@blueprintjs/core';
import classNames from 'classnames';
import { bignumber } from 'mathjs';
Expand All @@ -9,7 +9,10 @@ import { DummyField } from '../../../components/DummyField';
import { weiToNumberFormat } from '../../../../utils/display-text/format';
import { Button } from '../../../components/Button';
import { useSendContractTx } from '../../../hooks/useSendContractTx';
import { TxType } from '../../../../store/global/transactions-store/types';
import {
TxStatus,
TxType,
} from '../../../../store/global/transactions-store/types';
import { SendTxProgress } from '../../../components/SendTxProgress';
import { useAccount } from '../../../hooks/useAccount';
import { useCacheCallWithValue } from '../../../hooks/useCacheCallWithValue';
Expand All @@ -33,13 +36,13 @@ export function RedeemDialog(props: Props) {
account,
);
const { send, ...tx } = useSendContractTx('vestingRegistry', 'reImburse');
const handleSubmit = () =>
const handleSubmit = useCallback(() => {
send(
[],
{ from: account, gas: gasLimit[TxType.SOV_REIMBURSE] },
{ type: TxType.SOV_REIMBURSE },
);

}, [account, send]);
return (
<>
<Overlay
Expand Down Expand Up @@ -112,10 +115,17 @@ export function RedeemDialog(props: Props) {
<div className="d-flex flex-row justify-content-between align-items-center">
<Button
text="Confirm"
onClick={handleSubmit}
onClick={() => handleSubmit()}
className="mr-3 w-100"
loading={tx.loading || loading}
disabled={tx.loading || loading || processed}
disabled={
tx.loading ||
[TxStatus.PENDING_FOR_USER, TxStatus.PENDING].includes(
tx.status,
) ||
loading ||
processed
}
/>
<Button
text="Cancel"
Expand Down

1 comment on commit 4efc123

@vercel
Copy link

@vercel vercel bot commented on 4efc123 Feb 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.