Skip to content

Commit 94d5dce

Browse files
committed
fix
1 parent 77a5893 commit 94d5dce

File tree

1 file changed

+84
-42
lines changed
  • packages/bridge-ui/src/components/Bridge/SharedBridgeComponents

1 file changed

+84
-42
lines changed

packages/bridge-ui/src/components/Bridge/SharedBridgeComponents/Actions.svelte

Lines changed: 84 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -71,35 +71,36 @@
7171
7272
$: canDoNothing = !hasAddress || !hasNetworks || !hasBalance || !$selectedToken || disabled;
7373
74-
const isERC20ApprovalDisabled = () => {
75-
return canDoNothing || $insufficientBalance || $validatingAmount || approving || $allApproved || !$enteredAmount;
76-
};
77-
78-
const isERC721ApprovalDisabled = () => {
79-
return $allApproved || approving;
80-
};
81-
82-
const isERC1155ApprovalDisabled = () => {
83-
return $allApproved || approving;
84-
};
85-
86-
const checkDisableApprove = () => {
87-
if (checking) return true;
88-
if (!$selectedTokenIsBridged) {
89-
switch (true) {
90-
case isERC20:
91-
return isERC20ApprovalDisabled();
92-
case isERC721:
93-
return isERC721ApprovalDisabled();
94-
case isERC1155:
95-
return isERC1155ApprovalDisabled();
74+
$: {
75+
const isERC20ApprovalDisabled = () => {
76+
return canDoNothing || $insufficientBalance || $validatingAmount || approving || $allApproved || !$enteredAmount;
77+
};
78+
79+
const isERC721ApprovalDisabled = () => {
80+
return $allApproved || approving;
81+
};
82+
83+
const isERC1155ApprovalDisabled = () => {
84+
return $allApproved || approving;
85+
};
86+
87+
const isDisableApprove = () => {
88+
if (checking) return true;
89+
if (!$selectedTokenIsBridged) {
90+
switch (true) {
91+
case isERC20:
92+
return isERC20ApprovalDisabled();
93+
case isERC721:
94+
return isERC721ApprovalDisabled();
95+
case isERC1155:
96+
return isERC1155ApprovalDisabled();
97+
}
9698
}
97-
}
98-
return approving;
99-
};
99+
return approving;
100+
};
100101
101-
// Conditions to disable/enable buttons
102-
$: disableApprove = checkDisableApprove();
102+
disableApprove = isDisableApprove();
103+
}
103104
104105
$: isERC20 = $selectedToken?.type === TokenType.ERC20;
105106
$: isERC721 = $selectedToken?.type === TokenType.ERC721;
@@ -120,20 +121,61 @@
120121
$allApproved &&
121122
!paused;
122123
123-
const isDisableBridge = () => {
124-
switch (true) {
125-
case isERC20:
126-
return !(commonConditions && !canDoNothing && !$insufficientAllowance && $tokenBalance && $enteredAmount);
127-
case isERC721:
128-
return !commonConditions;
129-
case isERC1155:
130-
return !(commonConditions && $enteredAmount && $enteredAmount > 0);
131-
case isETH:
132-
return !(commonConditions && $enteredAmount && $enteredAmount > 0);
133-
default:
134-
return !commonConditions;
135-
}
136-
};
124+
// Conditions to disable/enable buttons
125+
$: disableApprove = true;
126+
$: disableBridge = true;
127+
128+
// Conditions to disable/enable Approve button
129+
$: {
130+
const isERC20ApprovalDisabled = () => {
131+
return canDoNothing || $insufficientBalance || $validatingAmount || approving || $allApproved || !$enteredAmount;
132+
};
133+
134+
const isERC721ApprovalDisabled = () => {
135+
return $allApproved || approving;
136+
};
137+
138+
const isERC1155ApprovalDisabled = () => {
139+
return $allApproved || approving;
140+
};
141+
142+
const isDisableApprove = () => {
143+
if (checking) return true;
144+
if (!$selectedTokenIsBridged) {
145+
switch (true) {
146+
case isERC20:
147+
return isERC20ApprovalDisabled();
148+
case isERC721:
149+
return isERC721ApprovalDisabled();
150+
case isERC1155:
151+
return isERC1155ApprovalDisabled();
152+
}
153+
}
154+
return approving;
155+
};
156+
157+
disableApprove = isDisableApprove();
158+
}
159+
160+
// Conditions to disable/enable Bridge button
161+
$: {
162+
const isDisableBridge = () => {
163+
switch (true) {
164+
case isERC20:
165+
return !(commonConditions && !canDoNothing && !$insufficientAllowance && $tokenBalance && $enteredAmount);
166+
case isERC721:
167+
return !commonConditions;
168+
case isERC1155:
169+
return !(commonConditions && $enteredAmount && $enteredAmount > 0);
170+
case isETH:
171+
return !(commonConditions && $enteredAmount && $enteredAmount > 0);
172+
default:
173+
return !commonConditions;
174+
}
175+
};
176+
177+
disableBridge = isDisableBridge();
178+
}
137179
</script>
138180

139181
<div class="f-col w-full gap-4">
@@ -157,7 +199,7 @@
157199
{/if}
158200
</ActionButton>
159201
{/if}
160-
<ActionButton priority="primary" disabled={isDisableBridge()} loading={bridging} on:click={onBridgeClick}>
202+
<ActionButton priority="primary" disabled={disableBridge} loading={bridging} on:click={onBridgeClick}>
161203
{#if bridging}
162204
<span class="body-bold">{$t('bridge.button.bridging')}</span>
163205
{:else}

0 commit comments

Comments
 (0)