Skip to content

Commit 0009177

Browse files
committed
store: update store to encode the session pairing data
1 parent 03deb1a commit 0009177

File tree

5 files changed

+43
-4
lines changed

5 files changed

+43
-4
lines changed

Diff for: app/src/config.ts

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ export const IS_TEST = process.env.NODE_ENV === 'test';
99

1010
export const PUBLIC_URL = process.env.PUBLIC_URL;
1111

12+
// the Terminal on the web url to link to with the session pairing phrase
13+
export const LNC_APP_BASE_URL = IS_DEV
14+
? 'http://localhost:4000'
15+
: 'https://terminal.lightning.engirneering';
16+
1217
// detect the host currently serving the app files
1318
const { protocol, hostname, port } = window.location;
1419
const host = `${protocol}//${hostname}:${port}`;

Diff for: app/src/store/models/session.ts

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { makeAutoObservable } from 'mobx';
22
import * as LIT from 'types/generated/lit-sessions_pb';
33
import { SortParams } from 'types/state';
4+
import { Buffer } from 'buffer';
5+
import { LNC_APP_BASE_URL } from 'config';
46
import formatDate from 'date-fns/format';
57
import { MAX_DATE } from 'util/constants';
68
import { hex } from 'util/strings';
@@ -92,6 +94,17 @@ export default class Session {
9294
return this.isPaired ? 'In Use' : 'Created';
9395
}
9496

97+
/** The HEX encoded pairing secret mnemonic and mailbox server address */
98+
get encodedPairingData() {
99+
const data = `${this.pairingSecretMnemonic}||${this.mailboxServerAddr}`;
100+
return Buffer.from(data, 'ascii').toString('base64');
101+
}
102+
103+
/** The URL to use to pre-fill the pairing phrase in Terminal on the web */
104+
get terminalConnectUrl() {
105+
return `${LNC_APP_BASE_URL}#/connect/pair/${this.encodedPairingData}`;
106+
}
107+
95108
/**
96109
* Updates this session model using data provided from the LIT GRPC api
97110
*/

Diff for: app/src/store/store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import AppStorage from 'util/appStorage';
55
import CsvExporter from 'util/csv';
66
import { actionLog, Logger } from 'util/log';
77
import { GrpcClient, LitApi, LndApi, LoopApi, PoolApi } from 'api';
8+
import { PUBLIC_URL } from '../config';
89
import {
910
AccountStore,
1011
AuthStore,
@@ -30,7 +31,6 @@ import {
3031
RegisterSidecarView,
3132
RenewAccountView,
3233
} from './views';
33-
import { PUBLIC_URL } from '../config';
3434

3535
/**
3636
* The store used to manage global app state
@@ -132,7 +132,7 @@ export class Store {
132132
// stay on the current page (ex: history, settings)
133133
if (document.location.pathname === `${PUBLIC_URL}/`) {
134134
runInAction(() => {
135-
this.appView.goToLoop();
135+
this.appView.goToHome();
136136
});
137137
}
138138
// also fetch all the data we need

Diff for: app/src/store/stores/sessionStore.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ export default class SessionStore {
3939
return descending ? sessions.reverse() : sessions;
4040
}
4141

42+
/** The list of sessions that have not been paired */
43+
get unpairedSessions() {
44+
return this.sortedSessions.filter(s => !s.isPaired);
45+
}
46+
4247
/** indicates if there are more than one sessions active */
4348
get hasMultiple() {
4449
return this.sortedSessions.length > 1;
4550
}
4651

52+
/** The URl to pair with Terminal Web for the first session */
53+
get firstSessionTerminalUrl() {
54+
return this.unpairedSessions.length > 0
55+
? this.unpairedSessions[0].terminalConnectUrl
56+
: '';
57+
}
58+
4759
/**
4860
* queries the LIT api to fetch the list of sessions and stores them
4961
* in the state
@@ -78,7 +90,7 @@ export default class SessionStore {
7890
});
7991

8092
// Ensures that there is at least one session created
81-
if (this.sortedSessions.length === 0) {
93+
if (this.unpairedSessions.length === 0) {
8294
const count = values(this.sessions).filter(s =>
8395
s.label.startsWith('Default Session'),
8496
).length;
@@ -99,11 +111,13 @@ export default class SessionStore {
99111
* @param label the user defined label for this session
100112
* @param type the type of session being created (admin, read-only, etc)
101113
* @param expiry how long the session should be valid for
114+
* @param copy copy the session's phrase to the clipboard
102115
*/
103116
async addSession(
104117
label: string,
105118
type: LIT.SessionTypeMap[keyof LIT.SessionTypeMap],
106119
expiry: Date,
120+
copy = false,
107121
) {
108122
try {
109123
this._store.log.info(`submitting session with label ${label}`, {
@@ -124,7 +138,7 @@ export default class SessionStore {
124138
// fetch all sessions to update the store's state
125139
await this.fetchSessions();
126140

127-
if (session) {
141+
if (session && copy) {
128142
this.copyPhrase(session.label, session.pairingSecretMnemonic);
129143
return this.sessions.get(hex(session.localPublicKey));
130144
}

Diff for: app/src/store/views/appView.ts

+7
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ export default class AppView {
4545
this._store.log.info('Go to the Auth page');
4646
}
4747

48+
/** Change to the Home page */
49+
goToHome() {
50+
this.goTo(`${PUBLIC_URL}/home`);
51+
this._store.settingsStore.autoCollapseSidebar();
52+
this._store.log.info('Go to the Home page');
53+
}
54+
4855
/** Change to the Loop page */
4956
goToLoop() {
5057
this.goTo(`${PUBLIC_URL}/loop`);

0 commit comments

Comments
 (0)