Skip to content

Commit

Permalink
Add cancel option for URL admin=1
Browse files Browse the repository at this point in the history
  • Loading branch information
wilwade committed May 30, 2024
1 parent 2c51527 commit 46629cc
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
11 changes: 11 additions & 0 deletions multisig-ui/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
display: none;
}

/* Hide unless admin */
.countersignCancel {
display: none;
}

.isAdmin .countersignCancel {
display: inline-block;
}

@keyframes flash {
0% {
background-color: var(--color-link);
Expand Down Expand Up @@ -122,6 +131,8 @@
</label>
<div class="walletAddressNotFound">
Notice: The connected wallet extension does not have any addresses that match the multisig participants.
<br />
<button class="countersign countersignCancel">Cancel Transaction</button>
</div>
<div class="signingSection">
<button class="countersign countersignExe">Authorize and Execute</button>
Expand Down
33 changes: 28 additions & 5 deletions multisig-ui/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ async function pendingTransactionUpdate(tx, el) {
walletAddressNotFound.style.display = "none";
} else {
signingSection.style.display = "none";

// Get the account that deposited
const depositor = (await getAccounts(getPrefix(), true)).find((x) => x.address === tx.depositor);

const buttonCancel = walletAddressNotFound.querySelector(".countersignCancel");
buttonCancel.dataset.txHash = tx.hash;
buttonCancel.dataset.isCancel = true;
buttonCancel.dataset.when = JSON.stringify(tx.when);
// Only the depsitor can cancel
if (!depositor) {
buttonCancel.disabled = true;
buttonCancel.setAttribute("title", `ONLY ${tx.depositor.toString()} can cancel this transaction.`);
} else {
buttonCancel.dataset.sender = depositor.address;
buttonCancel.setAttribute("title", `With Account: ${depositor.address}`);
}
walletAddressNotFound.style.display = "block";
}
}
Expand Down Expand Up @@ -212,7 +228,7 @@ const postTransaction = (section) => (status) => {
section.append(p);
};

async function signTransaction(section, sender, txHash, timepoint, callData) {
async function signTransaction(section, sender, txHash, timepoint, callData, isCancel = false) {
const api = await loadApi();
const multisigResult = multisigProcess(false);
if (!multisigResult) {
Expand All @@ -231,7 +247,9 @@ async function signTransaction(section, sender, txHash, timepoint, callData) {
const injector = await web3FromAddress(sender);

let tx;
if (callData) {
if (isCancel) {
tx = api.tx.multisig.cancelAsMulti(multisigThreshold, sortedOthers, timepoint, txHash);
} else if (callData) {
tx = api.tx.multisig.asMulti(multisigThreshold, sortedOthers, timepoint, callData, maxWeight);
} else {
tx = api.tx.multisig.approveAsMulti(multisigThreshold, sortedOthers, timepoint, txHash, maxWeight);
Expand Down Expand Up @@ -369,6 +387,11 @@ function setFromUrl() {
if (multisigSignatories) {
document.getElementById("multisigSignatories").value = multisigSignatories.join("\n");
}

const isAdmin = getParameterByName("admin") !== null;
if (isAdmin) {
document.getElementById("pendingTransactions").classList.add("isAdmin");
}
}

// Start this up with event listeners
Expand All @@ -386,10 +409,10 @@ function init() {
e.preventDefault();
if (!e.target.dataset.sender) return;

const { sender, txHash, callData, when } = e.target.dataset;
const { sender, txHash, callData, when, isCancel } = e.target.dataset;

const section = e.target.closest(".signingSection");
await signTransaction(section, sender, txHash, JSON.parse(when), callData);
const section = e.target.closest(".pending-multisig");
await signTransaction(section, sender, txHash, JSON.parse(when), callData, isCancel || false);
});

initConnection(postConnect);
Expand Down

0 comments on commit 46629cc

Please sign in to comment.