|
71 | 71 |
|
72 | 72 | $: canDoNothing = !hasAddress || !hasNetworks || !hasBalance || !$selectedToken || disabled; |
73 | 73 |
|
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 | + } |
96 | 98 | } |
97 | | - } |
98 | | - return approving; |
99 | | - }; |
| 99 | + return approving; |
| 100 | + }; |
100 | 101 |
|
101 | | - // Conditions to disable/enable buttons |
102 | | - $: disableApprove = checkDisableApprove(); |
| 102 | + disableApprove = isDisableApprove(); |
| 103 | + } |
103 | 104 |
|
104 | 105 | $: isERC20 = $selectedToken?.type === TokenType.ERC20; |
105 | 106 | $: isERC721 = $selectedToken?.type === TokenType.ERC721; |
|
120 | 121 | $allApproved && |
121 | 122 | !paused; |
122 | 123 |
|
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 | + } |
137 | 179 | </script> |
138 | 180 |
|
139 | 181 | <div class="f-col w-full gap-4"> |
|
157 | 199 | {/if} |
158 | 200 | </ActionButton> |
159 | 201 | {/if} |
160 | | - <ActionButton priority="primary" disabled={isDisableBridge()} loading={bridging} on:click={onBridgeClick}> |
| 202 | + <ActionButton priority="primary" disabled={disableBridge} loading={bridging} on:click={onBridgeClick}> |
161 | 203 | {#if bridging} |
162 | 204 | <span class="body-bold">{$t('bridge.button.bridging')}</span> |
163 | 205 | {:else} |
|
0 commit comments