Skip to content

Commit c989da7

Browse files
authored
Merge pull request #36 from MXCzkEVM/wzb-a3
Wzb a3
2 parents 95aed00 + 1660498 commit c989da7

18 files changed

+838
-190
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
2+
3+
packages/bridge-ui/.vercel
4+
packages/bridge-ui/.vercel
5+
packages/bridge-ui/vercel.mainnet.json
6+
packages/bridge-ui/vercel.testnet.json
7+
8+
9+
110
# Logs
211
logs
312
*.log

.vscode/extensions.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

.vscode/settings.json

Lines changed: 0 additions & 10 deletions
This file was deleted.

packages/bridge-ui/.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ dist-ssr
2222
*.sln
2323
*.sw?
2424
.env
25+
.env.*
2526
.a1.env
2627
.s.env
2728

2829
# vite
2930
vite.config.ts.timestamp-*.mjs
30-
.vercel
31+
.vercel
32+
vercel.mainnet.json
33+
vercel.testnet.json

packages/bridge-ui/.vercel/README.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

packages/bridge-ui/.vercel/project.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/bridge-ui/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"type": "module",
66
"scripts": {
77
"start": "pnpm run dev",
8-
"dev": "vite",
8+
"dev": "cp .env.testnet .env && vite",
9+
"dev-mainnet": "cp .env.mainnet .env && vite",
910
"build": "vite build",
1011
"preview": "vite preview",
1112
"svelte:check": "svelte-check --tsconfig ./tsconfig.json --ignore ./wagmi.config.ts",
@@ -16,7 +17,9 @@
1617
"prettier:check": "pnpm run prettier '**/*.{js,ts,svelte}' --check",
1718
"lint": "pnpm exec eslint './**/*.{js,ts,svelte}' --ignore-path .eslintignore",
1819
"lint:fix": "pnpm exec eslint --fix './**/*.{js,ts,svelte}' --ignore-path .eslintignore",
19-
"generate-abi": "pnpm exec wagmi generate"
20+
"generate-abi": "pnpm exec wagmi generate",
21+
"vercel:mainnet": "cp src/pages/home/HomeMainnet.svelte src/pages/home/Home.svelte && cp vercel.mainnet.json .vercel/project.json && cp .env.mainnet .env && vercel --prod",
22+
"vercel:testnet": "cp src/pages/home/HomeTestnet.svelte src/pages/home/Home.svelte && cp vercel.testnet.json .vercel/project.json && cp .env.testnet .env && vercel --prod"
2023
},
2124
"devDependencies": {
2225
"@babel/preset-env": "^7.16.0",

packages/bridge-ui/src/components/AddressDropdown.svelte

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { errorToast, successToast } from './NotificationToast.svelte';
1818
import { L2_CHAIN_ID } from '../constants/envVars';
1919
20-
2120
let address: string = '';
2221
let addressAvatarImgData: string = '';
2322
let tokenBalance: string = '';
@@ -81,7 +80,9 @@
8180
<!-- Makes no sense to render anything here without signer -->
8281
{#if $signer}
8382
<div class="dropdown dropdown-bottom dropdown-end">
84-
<button class="btn justify-around">
83+
<!-- svelte-ignore a11y-label-has-associated-control -->
84+
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
85+
<label tabindex="0" class="btn justify-around">
8586
<span class="font-normal flex-1 text-left flex items-center">
8687
{#if pendingTx}
8788
<div class="inline-block ml-2">
@@ -101,7 +102,7 @@
101102
{/if}
102103
</span>
103104
<ChevronDown size="20" />
104-
</button>
105+
</label>
105106
<ul
106107
role="listbox"
107108
tabindex="0"
@@ -112,8 +113,8 @@
112113
<div class="text-lg mt-2">
113114
{tokenBalance.length > 10
114115
? `${truncateString(tokenBalance)}…`
115-
: tokenBalance}
116-
{$srcChain.id == L2_CHAIN_ID ? 'MXC' : 'ETH'}
116+
: tokenBalance}
117+
{$srcChain.id == L2_CHAIN_ID ? 'MXC' : 'ETH'}
117118
</div>
118119
{:else}
119120
<!-- <div class="text-lg mt-2">-- ETH</div> -->

packages/bridge-ui/src/components/BridgeForm/BridgeForm.svelte

Lines changed: 50 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
pendingTransactions,
2222
transactions as transactionsStore,
2323
} from '../../store/transaction';
24-
import {isETH, tokens} from '../../token/tokens';
24+
import { isETH, tokens } from '../../token/tokens';
2525
import { checkIfTokenIsDeployedCrossChain } from '../../utils/checkIfTokenIsDeployedCrossChain';
2626
import { getAddressForToken } from '../../utils/getAddressForToken';
2727
import { isOnCorrectChain } from '../../utils/isOnCorrectChain';
@@ -38,9 +38,8 @@
3838
import ProcessingFee from './ProcessingFee.svelte';
3939
import SelectToken from './SelectToken.svelte';
4040
import To from './To.svelte';
41-
import {L1_CHAIN_ID, L2_CHAIN_ID} from '../../constants/envVars';
42-
import {get} from "svelte/store";
43-
41+
import { L1_CHAIN_ID, L2_CHAIN_ID } from '../../constants/envVars';
42+
import { get } from 'svelte/store';
4443
4544
const log = getLogger('component:BridgeForm');
4645
@@ -127,7 +126,7 @@
127126
bridgeType: BridgeType,
128127
srcChain: Chain,
129128
signer: Signer,
130-
feeAmount: string
129+
feeAmount: string,
131130
) {
132131
if (!srcChain || !amount || !token || !bridgeType || !signer) return false;
133132
@@ -144,7 +143,7 @@
144143
145144
let amt = ethers.utils.parseUnits(amount, token.decimals);
146145
if (token.isChainToken && srcChain.id === L1_CHAIN_ID) {
147-
amt = amt.add(getProcessingFee());
146+
amt = amt.add(getProcessingFee());
148147
}
149148
150149
const isRequired = await $activeBridge.requiresAllowance({
@@ -166,7 +165,7 @@
166165
tokenBalance: string,
167166
memoError: string,
168167
srcChain: Chain,
169-
feeAmount: string
168+
feeAmount: string,
170169
) {
171170
if (
172171
!signer ||
@@ -192,13 +191,20 @@
192191
let amt = parsedAmount;
193192
if (token.symbol === 'MXC' && srcChain.id === L1_CHAIN_ID) {
194193
amt = amt.add(getProcessingFee());
195-
}else if(srcChain.id === L1_CHAIN_ID && token.symbol !== 'MXC') {
194+
} else if (srcChain.id === L1_CHAIN_ID && token.symbol !== 'MXC') {
196195
// allowance mxc as well
197-
const mxc = tokens.find((item) => item.symbol === 'MXC') as Token
198-
const requiredMxcAllowance = await checkAllowance(ethers.utils.formatUnits(getProcessingFee(), mxc.decimals), mxc, $bridgeType, srcChain, signer, feeAmount)
199-
if(requiredMxcAllowance) {
196+
const mxc = tokens.find((item) => item.symbol === 'MXC') as Token;
197+
const requiredMxcAllowance = await checkAllowance(
198+
ethers.utils.formatUnits(getProcessingFee(), mxc.decimals),
199+
mxc,
200+
$bridgeType,
201+
srcChain,
202+
signer,
203+
feeAmount,
204+
);
205+
if (requiredMxcAllowance) {
200206
requiresAllowanceMxc = true;
201-
}else {
207+
} else {
202208
requiresAllowanceMxc = false;
203209
}
204210
}
@@ -219,12 +225,12 @@
219225
throw Error('does not require additional allowance');
220226
221227
let amt = ethers.utils.parseUnits(amount, _token.decimals);
222-
if(_token.symbol === 'MXC' && $srcChain.id === L1_CHAIN_ID) {
223-
amt = amt.add(getProcessingFee())
228+
if (_token.symbol === 'MXC' && $srcChain.id === L1_CHAIN_ID) {
229+
amt = amt.add(getProcessingFee());
224230
}
225-
if(mxc) {
226-
_token = tokens.find(item => item.symbol === 'MXC')
227-
amt = getProcessingFee()
231+
if (mxc) {
232+
_token = tokens.find((item) => item.symbol === 'MXC');
233+
amt = getProcessingFee();
228234
}
229235
const contractAddress = await getAddressForToken(
230236
_token,
@@ -311,7 +317,6 @@
311317
312318
const hasEnoughBalance = balanceAvailableForTx.gte(requiredGas);
313319
314-
315320
log(
316321
`Is required gas ${requiredGas} less than available balance ${balanceAvailableForTx}? ${hasEnoughBalance}`,
317322
);
@@ -453,8 +458,7 @@
453458
successToast(
454459
`<strong>Transaction completed!</strong><br />Your funds are getting ready to be claimed on ${$destChain.name}.`,
455460
);
456-
}
457-
catch (error) {
461+
} catch (error) {
458462
console.error(error);
459463
const headerError = '<strong>Failed to bridge funds</strong><br />';
460464
const noteError =
@@ -480,7 +484,11 @@
480484
}
481485
482486
async function useFullAmount() {
483-
if (isETH($token) && ($token.symbol === 'MXC' && $srcChain.id === L2_CHAIN_ID)) {
487+
if (
488+
isETH($token) &&
489+
$token.symbol === 'MXC' &&
490+
$srcChain.id === L2_CHAIN_ID
491+
) {
484492
try {
485493
const feeData = await fetchFeeData();
486494
const gasEstimate = await $activeBridge.estimateGas({
@@ -500,7 +508,13 @@
500508
to: showTo && to ? to : await $signer.getAddress(),
501509
});
502510
503-
console.log("activeBridge",$activeBridge, isETH($token), "token",$token)
511+
console.log(
512+
'activeBridge',
513+
$activeBridge,
514+
isETH($token),
515+
'token',
516+
$token,
517+
);
504518
505519
const requiredGas = gasEstimate.mul(feeData.gasPrice);
506520
const userBalance = await $signer.getBalance('latest');
@@ -523,17 +537,21 @@
523537
amount = tokenBalance.toString();
524538
}
525539
} else {
526-
let amt = BigNumber.from(ethers.utils.parseUnits(tokenBalance.toString(), $token.decimals))
527-
console.log("amt",amt.toString(), getProcessingFee().toString())
528-
console.log($token, $srcChain.id)
540+
let amt = BigNumber.from(
541+
ethers.utils.parseUnits(tokenBalance.toString(), $token.decimals),
542+
);
543+
console.log('amt', amt.toString(), getProcessingFee().toString());
544+
console.log($token, $srcChain.id);
529545
530546
if ($token.symbol === 'MXC' && $srcChain.id === L1_CHAIN_ID) {
531547
amt = amt.sub(getProcessingFee());
532548
}
533549
if (amt.gt(0)) {
534-
amount = ethers.utils.formatUnits(amt.toString(), $token.decimals).toString();
535-
}else {
536-
amount = '0'
550+
amount = ethers.utils
551+
.formatUnits(amt.toString(), $token.decimals)
552+
.toString();
553+
} else {
554+
amount = '0';
537555
}
538556
}
539557
}
@@ -543,7 +561,7 @@
543561
return BigNumber.from(0);
544562
}
545563
546-
return BigNumber.from(ethers.utils.parseEther(feeAmount || "0"));
564+
return BigNumber.from(ethers.utils.parseEther(feeAmount || '0'));
547565
}
548566
549567
function updateAmount(event: Event) {
@@ -562,7 +580,7 @@
562580
tokenBalance,
563581
memoError,
564582
$srcChain,
565-
feeAmount
583+
feeAmount,
566584
)
567585
.then((disabled) => (actionDisabled = disabled))
568586
.catch((error) => console.error(error));
@@ -586,7 +604,7 @@
586604
<span class="label-text">{$_('bridgeForm.fieldLabel')}</span>
587605

588606
{#if $signer && tokenBalance}
589-
<div class="label-text ">
607+
<div class="label-text">
590608
<span>
591609
{$_('bridgeForm.balance')}:
592610
{tokenBalance.length > 10
@@ -624,7 +642,7 @@
624642
</div>
625643

626644
<div>
627-
<ProcessingFee bind:method={feeMethod} bind:amount={feeAmount}/>
645+
<ProcessingFee bind:method={feeMethod} bind:amount={feeAmount} />
628646
</div>
629647

630648
<div>

0 commit comments

Comments
 (0)