Fix confirmation modal
This commit is contained in:
parent
da32410c71
commit
d923a188e6
@ -4,11 +4,12 @@ import Services from './service';
|
|||||||
import { U32_MAX } from './service';
|
import { U32_MAX } from './service';
|
||||||
import { navigate } from '../router';
|
import { navigate } from '../router';
|
||||||
import { addressToEmoji } from '../utils/sp-address.utils';
|
import { addressToEmoji } from '../utils/sp-address.utils';
|
||||||
|
import { RoleDefinition } from 'dist/pkg/sdk_client';
|
||||||
|
|
||||||
export default class ModalService {
|
export default class ModalService {
|
||||||
private static instance: ModalService;
|
private static instance: ModalService;
|
||||||
private currentPrd: any;
|
private currentPrd: any;
|
||||||
private currentOutpoint?: string;
|
private currentOutpoint: string | null = null;
|
||||||
private constructor() {}
|
private constructor() {}
|
||||||
private paired_addresses: string[] = [];
|
private paired_addresses: string[] = [];
|
||||||
|
|
||||||
@ -51,11 +52,31 @@ export default class ModalService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async openConfirmationModal(pcd: any, outpointCommitment: string) {
|
public async openConfirmationModal(pcd: any, commitmentTx: string) {
|
||||||
let roles = JSON.parse(pcd['roles']); // ['members'][0];
|
let map: Record<string, RoleDefinition>;
|
||||||
console.log(roles);
|
if (pcd['roles']) {
|
||||||
let members = roles['owner']['members'];
|
const roles = pcd['roles'];
|
||||||
console.log(members);
|
try {
|
||||||
|
map = JSON.parse(roles);
|
||||||
|
} catch (e) {
|
||||||
|
throw new Error(`Failed to parse roles: ${e}`);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new Error('Pcd doesn\'t have a \"roles\" field');
|
||||||
|
}
|
||||||
|
|
||||||
|
let members;
|
||||||
|
if (map['owner']) {
|
||||||
|
const owner = map['owner'];
|
||||||
|
members = owner.members;
|
||||||
|
} else {
|
||||||
|
throw new Error('No \"owner\" role');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (members.length != 1) {
|
||||||
|
throw new Error('Must have exactly 1 member');
|
||||||
|
}
|
||||||
|
|
||||||
// We take all the addresses except our own
|
// We take all the addresses except our own
|
||||||
const service = await Services.getInstance();
|
const service = await Services.getInstance();
|
||||||
const localAddress = await service.getDeviceAddress();
|
const localAddress = await service.getDeviceAddress();
|
||||||
@ -65,6 +86,7 @@ export default class ModalService {
|
|||||||
this.paired_addresses.push(address);
|
this.paired_addresses.push(address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.currentOutpoint = commitmentTx;
|
||||||
await this.injectModal(members);
|
await this.injectModal(members);
|
||||||
const modal = document.getElementById('modal');
|
const modal = document.getElementById('modal');
|
||||||
if (modal) modal.style.display = 'flex';
|
if (modal) modal.style.display = 'flex';
|
||||||
@ -96,13 +118,15 @@ export default class ModalService {
|
|||||||
const modal = document.getElementById('modal');
|
const modal = document.getElementById('modal');
|
||||||
// console.log("🚀 ~ Routing ~ confirm ~ prd:", prd)
|
// console.log("🚀 ~ Routing ~ confirm ~ prd:", prd)
|
||||||
if (modal) modal.style.display = 'none';
|
if (modal) modal.style.display = 'none';
|
||||||
// Just make an empty commitment for now
|
|
||||||
const emptyTxid = '0'.repeat(64);
|
if (this.currentOutpoint === null || this.paired_addresses.length === 0) {
|
||||||
const commitmentOutpoint = `${emptyTxid}:${U32_MAX}`;
|
throw new Error('Missing outpoint and/or paired addresses');
|
||||||
|
}
|
||||||
|
|
||||||
// We take the paired device(s) from the contract
|
// We take the paired device(s) from the contract
|
||||||
await service.pairDevice(commitmentOutpoint, this.paired_addresses);
|
await service.pairDevice(this.currentOutpoint, this.paired_addresses);
|
||||||
this.paired_addresses = [];
|
this.paired_addresses = [];
|
||||||
|
this.currentOutpoint = null;
|
||||||
const newDevice = await service.dumpDevice();
|
const newDevice = await service.dumpDevice();
|
||||||
await service.saveDevice(newDevice);
|
await service.saveDevice(newDevice);
|
||||||
navigate('process');
|
navigate('process');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user