Skip to content

Commit 63ef0f4

Browse files
authored
Merge pull request #1327 from stakwork/fix/test-user-codespaces
chore: show test user for codespaces
2 parents ba9ba86 + cab3f89 commit 63ef0f4

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

src/config/host.ts

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
const internalDockerHosts = ['localhost:13007', 'localhost:13000'];
22
const externalDockerHosts = ['localhost:23007', 'localhost:23000'];
33

4+
export function getCodespacesBackendUrl() {
5+
if (window.location.host.endsWith('-13008.app.github.dev')) {
6+
const arr = window.location.host.split('-13008');
7+
const codespaceUrl = arr[0];
8+
return `${codespaceUrl}-5002.app.github.dev`;
9+
}
10+
return '';
11+
}
12+
413
export function getHost(): string {
514
if (process.env.REACT_APP_LOCAL_ENV) {
615
return 'people-test.sphinx.chat';
716
}
817

918
// codespace urls
10-
if (window.location.host.endsWith('-13008.app.github.dev')) {
11-
const arr = window.location.host.split('-13008');
12-
const codespaceUrl = arr[0];
13-
console.log(`${codespaceUrl}-5002.app.github.dev`);
14-
return `${codespaceUrl}-5002.app.github.dev`;
19+
const codespaceUrl = getCodespacesBackendUrl();
20+
21+
if (codespaceUrl) {
22+
return codespaceUrl;
1523
}
1624

1725
const host = window.location.host.includes('localhost')
@@ -41,8 +49,5 @@ export const TribesURL = getHost().startsWith('localhost')
4149
// https://obscure-zebra-94rwjg6r9v37pwg.github.dev/
4250

4351
export function isDevHost() {
44-
return (
45-
window.location.host.includes('localhost') ||
46-
window.location.host.endsWith('-13008.app.github.dev')
47-
);
52+
return window.location.host.includes('localhost') || !!getCodespacesBackendUrl();
4853
}

src/helpers/testUserLnUrl.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { bech32 } from 'bech32';
2+
import { getCodespacesBackendUrl } from 'config';
23
import { ec as EC } from 'elliptic';
34

45
function hexToBytes(hex: string): Uint8Array {
@@ -36,7 +37,15 @@ export async function testUserLnUrlLogin(encode: string) {
3637
const uint8Array = new Uint8Array(bech32.fromWords(bech32.decode(encode, 1500).words));
3738

3839
const textDecoder = new TextDecoder('utf-8');
39-
const url = new URL(textDecoder.decode(uint8Array));
40+
let rawUrl = textDecoder.decode(uint8Array);
41+
42+
const codespaceUrl = getCodespacesBackendUrl();
43+
44+
if (codespaceUrl) {
45+
rawUrl = rawUrl.replace('https://app.github.dev', `https://${codespaceUrl}`);
46+
}
47+
48+
const url = new URL(rawUrl);
4049

4150
const message = 'lnurl+cypress+auth';
4251
const hash = await sha256(message);
@@ -59,7 +68,7 @@ export async function testUserLnUrlLogin(encode: string) {
5968

6069
const response = await fetch(url.toString());
6170

62-
if (response.ok) {
63-
console.log(await response.json());
71+
if (!response.ok) {
72+
console.log('Response from API Call', response);
6473
}
6574
}

0 commit comments

Comments
 (0)