Skip to content

Luizoamorim/from ilyas browser fixes 2 #670

New issue

Have a question about this project? Sign up for a free account to open an issue and contact its maintainers and the community.

By clicking “Sign up for ”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on ? Sign in to your account

Merged
merged 21 commits into from
May 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 91 additions & 98 deletions wallet/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on .

1 change: 1 addition & 0 deletions wallet/package.json
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,6 +103,7 @@
},
"scripts": {
"start": "LOCAL_PROPOSER=true PUBLIC_URL='/nightfall/' USE_STUBS=true REACT_APP_MODE=local node scripts/start.js",
"start:testnet": "LOCAL_PROPOSER=false PUBLIC_URL='/nightfall/' USE_STUBS=false REACT_APP_MODE=testnet node scripts/start.js",
"build": "LOCAL_PROPOSER=false USE_STUBS=false REACT_APP_MODE=production PUBLIC_URL='https://wallet-beta.polygon.technology/nightfall/' node scripts/build.js",
"deploy": "npm run build && aws s3 sync build s3://pnf-dev-browser --cache-control max-age=172800 --delete && aws configure set preview.cloudfront true && aws cloudfront create-invalidation --distribution-id ENV3X13MLR5YT --paths \"/*\"",
"test": "env TS_NODE_COMPILER_OPTIONS='{\"module\": \"commonjs\" }' mocha -r ts-node/register 'tests/**/*.ts'",
Expand Down
81 changes: 59 additions & 22 deletions wallet/src/components/BridgeComponent/index.jsx
Original file line numberDiff line numberDiff line change
Expand Up@@ -191,10 +191,17 @@ const BridgeComponent = () => {
console.log('readyTx', readyTx);
try {
switch (readyTx.type) {
case 'onchain':
await submitTransaction(readyTx.rawTransaction, shieldContractAddress, 150000, 0); // 150k is enough gasLimit for a deposit
case 'onchain': {
const txL1Hash = await submitTransaction(
readyTx.rawTransaction,
shieldContractAddress,
150000,
0,
); // 150k is enough gasLimit for a deposit
readyTx.transaction.l1Hash = txL1Hash;
break;
case 'offchain':
}
case 'offchain': {
await axios
.post(
`${proposerUrl}/proposer/offchain-transaction`,
Expand All@@ -205,8 +212,10 @@ const BridgeComponent = () => {
throw new Error(err);
});
break;
default:
}
default: {
console.log('Error when sending');
}
}
await saveTransaction(readyTx.transaction);
handleClose();
Expand DownExpand Up@@ -311,10 +320,35 @@ const BridgeComponent = () => {
(txType === 'deposit' &&
new BigFloat(transferValue, token.decimals).toBigInt() > l1Balance) ||
(txType === 'withdraw' && new BigFloat(transferValue, token.decimals).toBigInt() > l2Balance)
)
) {
toast.error("Input value can't be greater than balance!");
else if (!transferValue) toast.warn('Input a value for transfer, please.');
else if (transferValue === 0) toast.warn("Input a value can't be zero.");
return;
}

if (
txType === 'deposit' &&
new BigFloat(transferValue, token.decimals).toBigInt() >
parseInt(token.restrictions[txType], 10)
) {
toast.error(
`Input value can't be greater than ${
parseInt(token.restrictions[txType], 10) /
parseInt(new BigFloat('1', token.decimals).toBigInt().toString(), 10)
}`,
);
return;
}

if (!transferValue) {
toast.warn('Input a value for transfer, please.');
return;
}

if (transferValue === '0') {
toast.warn("Input a value can't be zero.");
return;
}

setShow(true);
};

Expand DownExpand Up@@ -344,13 +378,22 @@ const BridgeComponent = () => {
}, [token, txType, accountInstance]);

const updateInputValue = () => {
const inputElement = document
.querySelector('nightfall-app')
.shadowRoot.getElementById('inputValue');
if (txType === 'deposit') {
document.getElementById('inputValue').value = l1Balance;
setTransferValue(l1Balance);
inputElement.value = new BigFloat(l1Balance, token.decimals).toFixed(4);
setTransferValue(new BigFloat(l1Balance, token.decimals).toFixed(4).toString());
return;
}
document.getElementById('inputValue').value = l2Balance;
setTransferValue(l2Balance);
inputElement.value = new BigFloat(l2Balance, token.decimals).toFixed(4);
setTransferValue(new BigFloat(l2Balance, token.decimals).toFixed(4).toString());
};

const continueTransfer = async () => {
if (await submitTx()) {
history.push('/transactionPage');
}
};

return (
Expand DownExpand Up@@ -527,15 +570,9 @@ const BridgeComponent = () => {

{/* TRANSFER BUTTON */}
<div>
{Number(transferValue) > 0 ? (
<button type="button" className="transfer_button" onClick={handleShow}>
<p>Transfer</p>
</button>
) : (
<button type="button" className="transfer_button">
<p>Transfer</p>
</button>
)}
<button type="button" className="transfer_button" onClick={handleShow}>
<p>Transfer</p>
</button>
</div>
</div>
{show && (
Expand DownExpand Up@@ -625,9 +662,9 @@ const BridgeComponent = () => {
<ContinueTransferButton
type="button"
id="Bridge_modal_continueTransferButton"
onClick={() => {
onClick={async () => {
setSendingState(true);
submitTx();
continueTransfer();
}}
>
{sending ? (
Expand Down
Loading