Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Commit

Permalink
feat: add tx signing instructions modal
Browse files Browse the repository at this point in the history
  • Loading branch information
paouvrard committed May 6, 2021
1 parent b13b908 commit 6b015f4
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/html/erc20-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ <h2 class="modal-section__label">Enter a token address</h2>

disableForm();

window.dom.show("ethTxModal")
try {
await window.nep141Xerc20.naturalErc20.sendToNear({
amount: amount.value,
Expand All @@ -205,6 +206,7 @@ <h2 class="modal-section__label">Enter a token address</h2>
alert("Something went wrong!\n" + e.message);
throw e;
} finally {
window.dom.hide("ethTxModal")
// re-enable the form, whether the call succeeded or failed
enableForm();
}
Expand Down
6 changes: 6 additions & 0 deletions src/html/erc20n-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ <h2 class="modal-section__label">Enter a token address</h2>

disableForm();

window.dom.show("nearTxModal")
// give the user some time to read the redirect information
await new Promise(r => setTimeout(r, 3000));

try {
await window.nep141Xerc20.bridgedNep141.sendToEthereum({
amount: amount.value,
Expand All @@ -187,6 +191,8 @@ <h2 class="modal-section__label">Enter a token address</h2>
recipient: window.ethUserAddress,
});
} catch (e) {
// only hide if error, show until redirect happens
window.dom.hide("nearTxModal")
alert(
"Something went wrong! " +
"Maybe you need to sign out and back in? " +
Expand Down
11 changes: 11 additions & 0 deletions src/html/eth-tx-modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div data-behavior="ethTxModal" class="modal" style="display: none">
<div class="modal__container">
<div class="modal-image__container">
<img src="img/eth-wallet-sig.svg" alt="" class="modal__image" />
</div>
<h1 class="modal__heading">Confirm Ethereum Transaction</h1>
<p class="modal__message">
Please sign and confirm the transaction in your Ethereum wallet to proceed.
</p>
</div>
</div>
14 changes: 14 additions & 0 deletions src/html/near-tx-modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div data-behavior="nearTxModal" class="modal" style="display: none">
<div class="modal__container">
<div class="modal-image__container">
<img src="img/near.svg" alt="" class="modal__image" />
</div>
<h1 class="modal__heading">Confirm NEAR Transaction</h1>
<p class="modal__message">
You are being redirected to NEAR Wallet to confirm the transaction...
</p>
<p class="modal__message">
Please do not go back or close the window until the process is complete.
</p>
</div>
</div>
19 changes: 18 additions & 1 deletion src/html/transfers.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ <h1 class="modal__heading">Remove transfer from list?</h1>
</div>
</div>
</div>
</div>
<style>
.transfers {
padding: 5rem 0;
Expand Down Expand Up @@ -447,13 +448,30 @@ <h1 class="modal__heading">Remove transfer from list?</h1>
if (!callToAction) return;

const transferId = callToAction.closest("[data-behavior=transfer]").id;
const [transfer] = await window.transfers.get({
filter: (t) => t.id === transferId
});
if (
(transfer.type.includes('sendToNear') && transfer.completedStep !== 'sync-natural-erc20-to-nep141') || // approve or lock (including retry)
(transfer.type.includes('sendToEthereum') && transfer.completedStep === 'sync-bridged-nep141-to-erc20') // unlock (including retry)
// TODO eNEAR case
) {
window.dom.show("ethTxModal")
} else {
window.dom.show("nearTxModal")
// give the user some time to read the redirect information
await new Promise(r => setTimeout(r, 3000));
}
callToAction.disabled = true
try {
await window.transfers.act(transferId)
} catch(error) {
console.error(error)
// only hide if error, show until redirect happens
window.dom.hide("nearTxModal")
} finally {
callToAction.disabled = false
window.dom.hide("ethTxModal")
}
});
document.querySelector("body").addEventListener("click", (event) => {
Expand Down Expand Up @@ -628,4 +646,3 @@ <h3 class="transfer__amount">${window.utils.formatLargeNum(
window.renderers.push(updateTransfers);
window.renderers.push(hideShowTransfers);
</script>
</div>
11 changes: 11 additions & 0 deletions src/img/eth-wallet-sig.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@
<include src="erc20n-form.html"></include>
<include src="bridge-erc20-form.html"></include>
<include src="restore-transfer.html"></include>
<include src="eth-tx-modal.html"></include>
<include src="near-tx-modal.html"></include>
</div>

<script src="./js/index.js"></script>
Expand Down

0 comments on commit 6b015f4

Please # to comment.