Skip to content

Commit

Permalink
feat: adds link to sign in chainweaver v3
Browse files Browse the repository at this point in the history
  • Loading branch information
alber70g committed Dec 3, 2024
1 parent 7ed927f commit 4f36511
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
12 changes: 10 additions & 2 deletions docs/xchain.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

<body>
<div class="ui main container">
<a href="/"><img src="./kadena-logo.png" class="center" style="height:70px"></a>

<a href="/">
<img src="./kadena-logo.png" class="center" style="height: 70px" />
</a>

<h1>Finish Cross Chain Transfer</h1>
<form id="kadena-form" class="ui form">
Expand Down Expand Up @@ -93,6 +94,13 @@ <h3 class="header">SigData</h3>
<button id="click-to-copy" class="ui secondary basic button">
Click To Copy
</button>
<a
id="open-in-chainweaver"
target="_blank"
href="https://wallet.kadena.io/sig-builder?transaction="
>
Open in Chainweaver v3 Beta
</a>
</div>

<div id="signed-transaction-wrapper" class="ui field hidden">
Expand Down
27 changes: 23 additions & 4 deletions docs/xchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,9 @@ async function finishXChain() {
(testLocal.result.status === 'failure' &&
testLocal.result.error.errorMsg?.includes('pact completed'))
) {
setError(testLocal.result.error.message || testLocal.result.error.errorMsg);
setError(
testLocal.result.error.message || testLocal.result.error.errorMsg,
);
return;
}

Expand Down Expand Up @@ -585,12 +587,18 @@ function setError(msg) {
document.getElementById('acct-err').classList.remove('hidden');
document.getElementById('kadena-form').setAttribute('class', 'ui form error');
}

function setSigData(msg) {
const sigDataTextarea = document.getElementById('sig-data');
sigDataTextarea.value = msg;
}

function setOpenInChainweaver(msg){
//base64 encode and set link of id `open-in-chainweaver` to `https://wallet.kadena.io/sig-builder?transaction=${msg}`
const encoded = btoa(msg);
const openInChainweaver = document.getElementById('open-in-chainweaver');
openInChainweaver.href = `https://wallet.kadena.io/sig-builder?transaction=${encoded}`;
}

function sigData() {
return document.getElementById('sig-data').value;
}
Expand Down Expand Up @@ -736,7 +744,11 @@ function isAccountEligibleForGasPayment() {
// error state
if (!isBalanceSufficient) {
setError(
`Balance of ${State.sender} is not sufficient ${State.gasPayerAccountDetails.result.data.balance}`,
`Balance of ${
State.sender
} is not sufficient ${getBalanceOrBalanceDecimal(
State.gasPayerAccountDetails.result.data.balance,
)}`,
);
} else if (!isSingleSig) {
setError(
Expand Down Expand Up @@ -932,6 +944,7 @@ async function fillSigData() {

c.sigs = keys.getSigsObject();
setTimeout(() => setSigData(JSON.stringify(c, null, 2)));
setTimeout(() => setOpenInChainweaver(JSON.stringify(c, null, 2)));
}

function isGasStation(res) {
Expand All @@ -940,7 +953,9 @@ function isGasStation(res) {

function isBalanceSufficient(gasPrice, gasLimit, res) {
try {
return gasPrice * gasLimit <= res.result.data.balance;
return (
gasPrice * gasLimit <= getBalanceOrBalanceDecimal(res.result.data.balance)
);
} catch (error) {
return false;
}
Expand Down Expand Up @@ -1084,3 +1099,7 @@ function setUrlParam(key, value) {
`${window.location.pathname}?${urlParams}`,
);
}

function getBalanceOrBalanceDecimal(res) {
return typeof res === 'object' ? res.decimal : res;
}

0 comments on commit 4f36511

Please sign in to comment.