Skip to content

Commit

Permalink
chore(bridge-ui-v2): Update isBridgePaused method (#15339)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaodino committed Dec 6, 2023
1 parent b3b9474 commit 72eb781
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 31 deletions.
18 changes: 8 additions & 10 deletions packages/bridge-ui-v2/src/components/Bridge/Actions.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@
export let allTokensApproved = false;
function onApproveClick() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
});
let paused = false;
function onApproveClick() {
if (paused) throw new BridgePausedError('Bridge is paused');
approving = true;
approve().finally(() => {
approving = false;
});
}
function onBridgeClick() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
});
if (paused) throw new BridgePausedError('Bridge is paused');
bridging = true;
bridge();
}
//TODO: this should probably be checked somewhere else?
export async function checkTokensApproved() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((result) => {
paused = result;
if (paused) throw new BridgePausedError('Bridge is paused');
});
$validatingAmount = true;
if ($selectedToken?.type === TokenType.ERC721 || $selectedToken?.type === TokenType.ERC1155) {
Expand Down Expand Up @@ -178,7 +176,7 @@
$selectedToken &&
!$validatingAmount &&
!$insufficientBalance &&
!isBridgePaused();
!paused;
$: erc20ConditionsSatisfied =
!canDoNothing && !$insufficientAllowance && commonConditions && $tokenBalance && $enteredAmount;
Expand Down
8 changes: 4 additions & 4 deletions packages/bridge-ui-v2/src/components/Bridge/Bridge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@
}
async function approve() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});
try {
if (!$selectedToken || !$network || !$destinationChain) return;
Expand Down Expand Up @@ -147,8 +147,8 @@
}
async function bridge() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});
if (!$bridgeService || !$selectedToken || !$network || !$destinationChain || !$account?.address) return;
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/components/Bridge/NFTBridge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@
};
const manualImportAction = () => {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});
if (!$network?.id) throw new Error('network not found');
const srcChainId = $network?.id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
}
async function claim() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});
if (!$network || !$account?.address) return;
Expand Down Expand Up @@ -169,8 +169,8 @@
}
async function release() {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});
if (!$network || !$account?.address) return;
Expand Down
8 changes: 4 additions & 4 deletions packages/bridge-ui-v2/src/libs/bridge/ERC20Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ export class ERC20Bridge extends Bridge {
}

async estimateGas(args: ERC20BridgeArgs) {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});

const { tokenVaultContract, sendERC20Args } = await ERC20Bridge._prepareTransaction(args);
Expand All @@ -88,8 +88,8 @@ export class ERC20Bridge extends Bridge {
}

async requireAllowance({ amount, tokenAddress, ownerAddress, spenderAddress }: RequireAllowanceArgs) {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});

const tokenContract = getContract({
Expand Down
8 changes: 4 additions & 4 deletions packages/bridge-ui-v2/src/libs/bridge/ERC721Bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export class ERC721Bridge extends Bridge {
}

async requiresApproval({ tokenAddress, spenderAddress, tokenId }: RequireApprovalArgs) {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});

const tokenContract = getContract({
Expand All @@ -50,8 +50,8 @@ export class ERC721Bridge extends Bridge {
}

async estimateGas(args: ERC721BridgeArgs): Promise<bigint> {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});

const { tokenVaultContract, sendERC721Args } = await ERC721Bridge._prepareTransaction(args);
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge-ui-v2/src/libs/bridge/ETHBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export class ETHBridge extends Bridge {
}

async bridge(args: ETHBridgeArgs) {
isBridgePaused().then(() => {
throw new BridgePausedError('Bridge is paused');
isBridgePaused().then((paused) => {
if (paused) throw new BridgePausedError('Bridge is paused');
});

const { bridgeContract, message } = await ETHBridge._prepareTransaction(args);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getContract } from '@wagmi/core';
import { get } from 'svelte/store';

import { bridgeABI } from '$abi';
import { routingContractsMap } from '$bridgeConfig';
Expand All @@ -10,7 +11,7 @@ const log = getLogger('bridge:checkForPausedContracts');

export const isBridgePaused = async () => {
await checkForPausedContracts();
if (bridgePausedModal) {
if (get(bridgePausedModal)) {
return true;
}
return false;
Expand Down

0 comments on commit 72eb781

Please sign in to comment.