Minor improvements and bug fixes
This commit is contained in:
parent
1eab5efab8
commit
1f4153619a
@ -69,7 +69,7 @@ export default class Routing {
|
||||
window.onclick = (event) => {
|
||||
const modal = document.getElementById('modal');
|
||||
if (event.target === modal) {
|
||||
this.confirm(this.currentPrd || pcd, outpointCommitment || this.currentOutpoint);
|
||||
this.confirm(pcd, outpointCommitment);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,12 +84,12 @@ export default class Routing {
|
||||
if (modal) modal.style.display = 'none';
|
||||
}
|
||||
|
||||
async confirm(prd?: any, outpointCommitment?: string) {
|
||||
async confirm(prd: any, outpointCommitment: string) {
|
||||
const service = await Services.getInstance()
|
||||
const modal = document.getElementById('modal')
|
||||
console.log("🚀 ~ Routing ~ confirm ~ prd:", this.currentPrd || prd, outpointCommitment)
|
||||
console.log("🚀 ~ Routing ~ confirm ~ prd:", prd, outpointCommitment)
|
||||
if (modal) modal.style.display = 'none';
|
||||
if(this.currentPrd || prd) service.pairDevice(this.currentPrd || prd, outpointCommitment || this.currentOutpoint as string)
|
||||
await service.pairDevice(prd, outpointCommitment);
|
||||
}
|
||||
async closeConfirmationModal() {
|
||||
const modal = document.getElementById('modal')
|
||||
|
@ -103,10 +103,10 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
async prepareProcessTx(myAddress: string, recipientAddress: string) {
|
||||
private prepareProcessTx(myAddress: string, recipientAddress: string) {
|
||||
const initial_session_privkey = new Uint8Array(32);
|
||||
const initial_session_pubkey = new Uint8Array(32);
|
||||
const paringTemplate = {
|
||||
const pairingTemplate = {
|
||||
"description": "AliceBob",
|
||||
"roles": {
|
||||
"owner": {
|
||||
@ -134,27 +134,33 @@ export default class Services {
|
||||
}
|
||||
|
||||
|
||||
const apiReturn = await this.sdkClient.create_update_transaction(undefined, JSON.stringify(paringTemplate), 1)
|
||||
const apiReturn = this.sdkClient.create_update_transaction(undefined, JSON.stringify(pairingTemplate), 1)
|
||||
return apiReturn
|
||||
}
|
||||
|
||||
public async sendPairingTx(spAddress: string): Promise<void> {
|
||||
// const services = await Services.getInstance();
|
||||
const amount = await this.getAmount() as any
|
||||
console.log("🚀 ~ Services ~ sendPairingTx ~ amount:", amount)
|
||||
const amount = this.sdkClient.get_available_amount();
|
||||
|
||||
const localAddress = await this.getDeviceAddress() as any
|
||||
if (amount === 0n) {
|
||||
const faucetMsg = this.sdkClient.create_faucet_msg();
|
||||
await this.sendFaucetMessage(faucetMsg);
|
||||
}
|
||||
|
||||
const localAddress = this.sdkClient.get_address();
|
||||
const emptyTxid = '0'.repeat(64)
|
||||
|
||||
try {
|
||||
let commitmentOutpoint = `${emptyTxid}:${U32_MAX}`;
|
||||
await this.sdkClient.pair_device(commitmentOutpoint, [spAddress])
|
||||
this.sdkClient.pair_device(commitmentOutpoint, [spAddress])
|
||||
} catch (e) {
|
||||
console.error("Services ~ Error:", e);
|
||||
return
|
||||
}
|
||||
const apiReturn = await this.prepareProcessTx(localAddress, spAddress)
|
||||
this.handleApiReturn(apiReturn);
|
||||
|
||||
setTimeout( async () => {
|
||||
const apiReturn = this.prepareProcessTx(localAddress, spAddress)
|
||||
await this.handleApiReturn(apiReturn);
|
||||
}, 100)
|
||||
|
||||
return
|
||||
}
|
||||
@ -211,7 +217,7 @@ export default class Services {
|
||||
async parseNewTx(tx: string) {
|
||||
try {
|
||||
// console.log('==============> sending txxxxxxx parser', tx)
|
||||
const parsedTx = await this.sdkClient.parse_new_tx(tx, 0, 0.01)
|
||||
const parsedTx = await this.sdkClient.parse_new_tx(tx, 0, 0.0001)
|
||||
if(parsedTx) {
|
||||
console.log("🚀 ~ Services ~ parseNewTx ~ parsedTx:", parsedTx)
|
||||
try {
|
||||
@ -223,26 +229,33 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
} catch(e) {
|
||||
console.trace('Not our transaction');
|
||||
console.trace(e);
|
||||
}
|
||||
}
|
||||
|
||||
private async handleApiReturn(apiReturn: ApiReturn) {
|
||||
if(apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length) {
|
||||
if (apiReturn.ciphers_to_send && apiReturn.ciphers_to_send.length) {
|
||||
await this.sendCipherMessages(apiReturn.ciphers_to_send)
|
||||
}
|
||||
|
||||
if(apiReturn.new_tx_to_send) {
|
||||
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send))
|
||||
}
|
||||
|
||||
if(apiReturn.updated_process && apiReturn.updated_process.length) {
|
||||
setTimeout(async () => {
|
||||
if (apiReturn.updated_process && apiReturn.updated_process.length) {
|
||||
const [processCommitment, process] = apiReturn.updated_process;
|
||||
console.debug('Updated Process Commitment:', processCommitment);
|
||||
console.debug('Process Details:', process);
|
||||
|
||||
// Save process to storage
|
||||
localStorage.setItem(processCommitment, JSON.stringify(process));
|
||||
// router.openConfirmationModal(impendingRequest, outpointCommitment)
|
||||
// Check if the newly updated process reveals some new information
|
||||
try {
|
||||
const proposals: string[] = this.sdkClient.get_update_proposals(processCommitment);
|
||||
const actual_proposal = JSON.parse(proposals[0]); // just hacky way to solve redundant info for now
|
||||
console.info(actual_proposal);
|
||||
let router = await Routing.getInstance();
|
||||
router.openConfirmationModal(actual_proposal, processCommitment);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
if(apiReturn.updated_cached_msg && apiReturn.updated_cached_msg.length) {
|
||||
@ -255,8 +268,13 @@ export default class Services {
|
||||
|
||||
if (apiReturn.commit_to_send) {
|
||||
const commit = apiReturn.commit_to_send;
|
||||
this.sendCommitMessage(JSON.stringify(commit));
|
||||
await this.sendCommitMessage(JSON.stringify(commit));
|
||||
}
|
||||
|
||||
if (apiReturn.new_tx_to_send) {
|
||||
await this.sendNewTxMessage(JSON.stringify(apiReturn.new_tx_to_send))
|
||||
}
|
||||
}, 0)
|
||||
}
|
||||
|
||||
async pairDevice(prd: any, outpointCommitment: string) {
|
||||
@ -327,9 +345,7 @@ export default class Services {
|
||||
}
|
||||
|
||||
async getDeviceAddress() {
|
||||
const address = await this.sdkClient.get_address()
|
||||
console.log("🚀 ~ Services ~ getDeviceAddress ~ address:", address)
|
||||
return address
|
||||
return await this.sdkClient.get_address();
|
||||
}
|
||||
|
||||
async dumpDevice() {
|
||||
@ -481,7 +497,7 @@ export default class Services {
|
||||
}
|
||||
}
|
||||
|
||||
private cleanSubsciptions(): void {
|
||||
private cleanSubscriptions(): void {
|
||||
for (const sub of this.subscriptions) {
|
||||
const el = sub.element;
|
||||
const eventHandler = sub.eventHandler;
|
||||
@ -498,7 +514,7 @@ export default class Services {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cleanSubsciptions()
|
||||
this.cleanSubscriptions()
|
||||
|
||||
// const user = services.sdkClient.create_user('Test', 'test', 10, 1, 'Messaging')
|
||||
// console.log("🚀 ~ Services ~ injectProcessListPage ~ user:", user)
|
||||
|
Loading…
x
Reference in New Issue
Block a user