add dump device after pairing confirmation and unpair revoke button

This commit is contained in:
AnisHADJARAB 2024-10-17 14:00:02 +00:00
parent 65bfe1cd21
commit eedfac704d
4 changed files with 22 additions and 3 deletions

View File

@ -17,7 +17,7 @@
</svg>
<div class="menu-content" id="menu">
<a href="#">Revoke</a>
<a href="#" onclick="unpair()">Revoke</a>
<a href="#">Export</a>
<a href="#">Import</a>
<a href="#">Disconnect</a>

View File

@ -1,3 +1,5 @@
import Services from "/src/services/service.ts";
function toggleMenu() {
const menu = document.getElementById("menu");
if (menu.style.display === "block") {
@ -370,3 +372,11 @@ document.addEventListener("click", () => {
}
}
});
export async function unpair() {
const service = await Services.getInstance()
await service.unpairDevice()
}
window.unpair = unpair;

View File

@ -100,9 +100,10 @@ export default class Routing {
const commitmentOutpoint = `${emptyTxid}:${U32_MAX}`;
// We take the paired device(s) from the contract
this.sdkClient.pair_device(commitmentOutpoint, this.paired_addresses)
await this.sdkClient.pair_device(commitmentOutpoint, this.paired_addresses)
this.paired_addresses = []
const newDevice = await service.dumpDevice();
await service.saveDevice(newDevice);
service.injectProcessListPage();
}

View File

@ -106,6 +106,13 @@ export default class Services {
}
}
public async unpairDevice(): Promise<void> {
const service = await Services.getInstance()
await service.sdkClient.unpair_device()
const newDevice = await this.dumpDevice();
await this.saveDevice(newDevice);
}
private prepareProcessTx(myAddress: string, recipientAddress: string) {
const initial_session_privkey = new Uint8Array(32);
const initial_session_pubkey = new Uint8Array(32);
@ -527,6 +534,7 @@ export default class Services {
// await database.writeObject(indexedDb, database.getStoreList().AnkUser, user.user, null);
container.innerHTML = processPage;
const newScript = document.createElement('script');
newScript.setAttribute('type', 'module')
newScript.textContent = processScript;
document.head.appendChild(newScript).parentNode?.removeChild(newScript);