rebase and fix scna and url pairing
This commit is contained in:
parent
5aad3a4109
commit
dac9297ea7
@ -1,5 +1,6 @@
|
||||
import QrScanner from 'qr-scanner';
|
||||
import Services from '../../services/service';
|
||||
import { prepareAndSendPairingTx } from '~/utils/sp-address.utils';
|
||||
|
||||
export default class QrScannerComponent extends HTMLElement {
|
||||
videoElement: any;
|
||||
@ -53,20 +54,9 @@ import Services from '../../services/service';
|
||||
// Extract the 'sp_address' parameter
|
||||
const spAddress = scannedUrl.searchParams.get('sp_address');
|
||||
if(spAddress) {
|
||||
const service = await Services.getInstance();
|
||||
// Call the sendPairingTx function with the extracted sp_address
|
||||
try {
|
||||
const sharedSecret = await service.getSecretForAddress(spAddress);
|
||||
if (!sharedSecret) {
|
||||
const member = {
|
||||
sp_addresses: [spAddress],
|
||||
}
|
||||
await service.connectMember([member]);
|
||||
}
|
||||
const mySPAddress = await service.getDeviceAddress()
|
||||
await service.createPairingProcess([spAddress], mySPAddress, 1);
|
||||
|
||||
// await service.sendPairingTx(spAddress);
|
||||
await prepareAndSendPairingTx(spAddress)
|
||||
} catch (e) {
|
||||
console.error('Failed to pair:', e);
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import Database from './services/database.service';
|
||||
import Services from './services/service';
|
||||
import { cleanSubscriptions } from './utils/subscription.utils';
|
||||
import { LoginComponent } from './pages/home/home-component';
|
||||
import { prepareAndSendPairingTx } from './utils/sp-address.utils';
|
||||
export {Services};
|
||||
const routes: { [key: string]: string } = {
|
||||
home: '/src/pages/home/home.html',
|
||||
@ -123,10 +124,7 @@ export async function init(): Promise<void> {
|
||||
setTimeout(async () => {
|
||||
try {
|
||||
// check if we have a shared secret with that address
|
||||
const sharedSecret = await services.getSecretForAddress(pairingAddress);
|
||||
if (!sharedSecret) {
|
||||
await services.connectMember([{sp_addresses: [pairingAddress]}]);
|
||||
}
|
||||
await prepareAndSendPairingTx(pairingAddress)
|
||||
} catch (e) {
|
||||
console.error('Failed to pair:', e);
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import { IProcess } from '~/models/process.model';
|
||||
import { initWebsocket, sendMessage } from '../websockets';
|
||||
import { ApiReturn, Member, PcdUpdates, Process, RoleDefinition } from '../../pkg/sdk_client';
|
||||
import ModalService from './modal.service';
|
||||
import { navigate } from '../router';
|
||||
import Database from './database.service';
|
||||
|
||||
export const U32_MAX = 4294967295;
|
||||
|
@ -149,22 +149,30 @@ export function initAddressInput() {
|
||||
|
||||
async function onOkButtonClick() {
|
||||
const container = getCorrectDOM('login-4nk-component') as HTMLElement
|
||||
const service = await Services.getInstance();
|
||||
const addressInput = (container.querySelector('#addressInput') as HTMLInputElement).value;
|
||||
const secondDeviceAddress = (container.querySelector('#addressInput') as HTMLInputElement).value;
|
||||
try {
|
||||
// Connect to target, if necessary
|
||||
const sharedSecret = await service.getSecretForAddress(addressInput);
|
||||
await prepareAndSendPairingTx(secondDeviceAddress);
|
||||
} catch (e) {
|
||||
console.error(`onOkButtonClick error: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function prepareAndSendPairingTx(secondDeviceAddress: string) {
|
||||
const service = await Services.getInstance();
|
||||
|
||||
const sharedSecret = await service.getSecretForAddress(secondDeviceAddress);
|
||||
if (!sharedSecret) {
|
||||
const member = {
|
||||
sp_addresses: [addressInput],
|
||||
}
|
||||
sp_addresses: [secondDeviceAddress],
|
||||
};
|
||||
const connectMemberResult = await service.connectMember([member]);
|
||||
await service.handleApiReturn(connectMemberResult);
|
||||
}
|
||||
// Create the process
|
||||
setTimeout(async () => {
|
||||
const relayAddress = await service.getRelayAddresses(); // Get one (or more?) relay addresses
|
||||
const createPairingProcessReturn = await service.createPairingProcess([addressInput], relayAddress[0], 1);
|
||||
const createPairingProcessReturn = await service.createPairingProcess([secondDeviceAddress], relayAddress[0], 1);
|
||||
|
||||
if (!createPairingProcessReturn.updated_process) {
|
||||
throw new Error('createPairingProcess returned an empty new process'); // This should never happen
|
||||
@ -172,9 +180,6 @@ async function onOkButtonClick() {
|
||||
|
||||
await service.handleApiReturn(createPairingProcessReturn);
|
||||
}, 1000);
|
||||
} catch (e) {
|
||||
console.error(`onOkButtonClick error: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateQRCode(spAddress: string) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user