Skip to content

Commit

Permalink
Merge pull request #3752 from balancer/hf/ensure-no-withdraw-access-w…
Browse files Browse the repository at this point in the history
…o-bpt

Hotfix: Block all access to withdraw page if BPT 0
  • Loading branch information
timjrobinson authored Jul 20, 2023
2 parents cefee87 + ebef421 commit c932585
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/components/contextual/pages/claim/LegacyClaims.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ async function claimAvailableRewards() {
});
txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
isClaiming.value = false;
userClaimsQuery.refetch();
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ async function handleTransaction(
});
txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
setSyncTxHashes(network, tx.hash);
},
onTxFailed: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from '@/composables/usePoolHelpers';
import { useI18n } from 'vue-i18n';
import { Pool } from '@/services/pool/types';
import useNetwork from '@/composables/useNetwork';
type Props = {
pool: Pool;
Expand All @@ -37,7 +38,8 @@ const showPreview = ref(false);
const { t } = useI18n();
const { veBalTokenInfo } = useVeBal();
const { wrappedNativeAsset, nativeAsset } = useTokens();
const router = useRouter();
const { networkSlug } = useNetwork();
const { isWalletReady, startConnectWithInjectedProvider, isMismatchedNetwork } =
useWeb3();
const {
Expand All @@ -52,6 +54,7 @@ const {
hasAcceptedHighPriceImpact,
hasAmountsOut,
validAmounts,
hasBpt,
} = useExitPool();
const { isWrappedNativeAssetPool } = usePoolHelpers(pool);
Expand Down Expand Up @@ -90,6 +93,10 @@ const excludedTokens = computed((): string[] => {
* CALLBACKS
*/
onBeforeMount(() => {
// If user has no BPT when mounting this component, redirect back to pool page
if (!hasBpt.value)
router.push({ name: 'pool', params: { networkSlug, id: props.pool.id } });
singleAmountOut.address = isPreMintedBptType(pool.value.poolType)
? wrappedNativeAsset.value.address
: pool.value.tokensList[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const withdrawalConfirmed = ref(false);
const { t } = useI18n();
const { getToken } = useTokens();
const { networkSlug } = useNetwork();
const router = useRouter();
const {
bptIn,
Expand All @@ -52,6 +53,7 @@ const {
fiatAmountsOut,
isSingleAssetExit,
shouldExitViaInternalBalance,
hasBpt,
} = useExitPool();
/**
Expand Down Expand Up @@ -106,7 +108,13 @@ const amountsOutMap = computed((): AmountMap => {
* METHODS
*/
function handleClose(): void {
emit('close');
// If user has withdrawn everything, send back to pool page. Else, close
// modal.
if (!hasBpt.value) {
router.push({ name: 'pool', params: { networkSlug, id: props.pool.id } });
} else {
emit('close');
}
}
</script>

Expand Down
2 changes: 1 addition & 1 deletion src/composables/approvals/useRelayerApprovalTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export default function useRelayerApprovalTx(
});

approved.value = await txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
approving.value = false;
relayerApproval.refetch();
},
Expand Down
2 changes: 1 addition & 1 deletion src/composables/approvals/useTokenApproval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default function useTokenApproval(
});

txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
approving.value = false;
approved.value = true;
},
Expand Down
2 changes: 1 addition & 1 deletion src/composables/swap/useJoinExit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ export default function useJoinExit({
}

await txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
confirming.value = false;
relayerApprovalQuery.refetch();
},
Expand Down
2 changes: 1 addition & 1 deletion src/composables/swap/useSor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ export default function useSor({
toFiat(tokenInAmountInput.value, tokenInAddressInput.value) || '0';

txListener(tx, {
onTxConfirmed: () => {
onTxConfirmed: async () => {
trackGoal(Goals.Swapped, bnum(swapUSDValue).times(100).toNumber() || 0);
swapping.value = false;
latestTxHash.value = tx.hash;
Expand Down
12 changes: 5 additions & 7 deletions src/composables/useEthers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ import {
} from '@/lib/utils/promise';
import { rpcProviderService } from '@/services/rpc-provider/rpc-provider.service';

import useBlocknative from './useBlocknative';
import { toJsTimestamp } from './useTime';
import { useTokens } from '@/providers/tokens.provider';
import useTransactions from './useTransactions';
import { captureBalancerException } from '@/lib/utils/errors';

type ConfirmedTxCallback = (receipt: TransactionReceipt) => void;
type ConfirmedTxCallback = (receipt: TransactionReceipt) => Promise<void>;
type FailedTxCallback = (txData: TransactionResponse) => void;

// keep a record of processed txs
export const processedTxs = ref<Set<string>>(new Set(''));

export default function useEthers() {
const { finalizeTransaction, updateTransaction } = useTransactions();
const { supportsBlocknative } = useBlocknative();
const { refetchBalances } = useTokens();

async function getTxConfirmedAt(receipt: TransactionReceipt): Promise<Date> {
Expand All @@ -50,7 +48,7 @@ export default function useEthers() {
txListener(
tx,
{
onTxConfirmed: () => {
onTxConfirmed: async () => {
resolve(true);
},
onTxFailed: () => {
Expand Down Expand Up @@ -106,9 +104,9 @@ export default function useEthers() {
if (receipt != null) {
finalizeTransaction(txHash, 'tx', receipt);
}
callbacks.onTxConfirmed(receipt);
if (shouldRefetchBalances && !supportsBlocknative.value) {
refetchBalances();
await callbacks.onTxConfirmed(receipt);
if (shouldRefetchBalances) {
await refetchBalances();
}
confirmed = true;
} catch (error) {
Expand Down
1 change: 0 additions & 1 deletion src/pages/pool/withdraw.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { usePoolHelpers } from '@/composables/usePoolHelpers';
import { oneSecondInMs } from '@/composables/useTime';
import { useIntervalFn } from '@vueuse/core';
import { computed } from 'vue';
import { hasFetchedPoolsForSor } from '@/lib/balancer.sdk';
import WithdrawPage from '@/components/contextual/pages/pool/withdraw/WithdrawPage.vue';
import { useTokens } from '@/providers/tokens.provider';
Expand Down

0 comments on commit c932585

Please sign in to comment.