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