Skip to content

Commit ff9b42f

Browse files
authored
Merge pull request #2 from unyt-org/[email protected]
Prepare for [email protected]
2 parents e0503db + 39f5869 commit ff9b42f

File tree

12 files changed

+163
-153
lines changed

12 files changed

+163
-153
lines changed

.github/workflows/uix-deploy-prod.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ name: Deploy prod
44
on: push
55
env:
66
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7+
HOST_TOKEN: ${{secrets.HOST_TOKEN}}
78
jobs:
89
deploy:
910
runs-on: ubuntu-latest
@@ -15,4 +16,4 @@ jobs:
1516
- name: Setup Deno
1617
uses: "denoland/setup-deno@v1"
1718
- name: Deploy UIX App
18-
run: "deno run --importmap ./importmap.json -Aqr https://cdn.unyt.org/uix@0.2.x/run.ts --stage prod --detach"
19+
run: "deno run --importmap ./importmap.json -Aqr https://cdn.unyt.org/uix@0.3.x/run.ts --stage prod --detach"

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"deno.enable": true
3+
}

backend/.dx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ endpoint: stage {
55
},
66

77
location: stage {
8-
prod: @+unyt-host-4
8+
prod: @+unyt-private-1
99
},
1010

1111
domain: stage {

common/TOR-Worker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ const ed = await import("https://unpkg.com/@noble/[email protected]/index.js");
22
const base32 = await import("https://cdn.jsdelivr.net/npm/[email protected]/+esm");
33
await import("https://cdn.jsdelivr.net/npm/[email protected]/src/sha3.min.js");
44

5-
65
export type AddressData = {
76
address: string;
87
public: {
@@ -81,7 +80,7 @@ async function generateOnionV3(keys: KeyPair | Promise<KeyPair> = generateKeys()
8180
hash.update(version);
8281

8382
const checksum = hash.digest().slice(0, 2);
84-
83+
8584
const decoded = new Uint8Array([...publicKey, ...checksum, ...version]);
8685
const address = base32.encode(Array.from(decoded)).toLowerCase().concat(".onion");
8786
const _publicKey = getPublicKey(address);

common/components/MainPage.css

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
2+
:host {
3+
display: flex;
4+
flex-direction: column;
5+
font-size: x-large;
6+
padding: 10px;
7+
width: 70%;
8+
margin: auto;
9+
align-items: center;
10+
margin-top: 40px;
11+
text-align: center;
12+
&>div {
13+
margin-top: 30px;
14+
width: 100%;
15+
flex-wrap: wrap;
16+
justify-content: center;
17+
&>h2 {
18+
width: 100%;
19+
}
20+
grid-gap: 20px;
21+
gap: 20px;
22+
display: flex;
23+
border-bottom: 1px solid gray;
24+
padding-bottom: 30px;
25+
&>input {
26+
flex: 1;
27+
padding: 20px;
28+
border-radius: var(--standard-border-radius);
29+
max-width: 300px;
30+
background-color: transparent;
31+
color: var(--text_highlight);
32+
padding-left: 20px;
33+
font-size: x-large;
34+
border: 2px solid var(--accent);
35+
}
36+
37+
&.hidden {
38+
&>.button {
39+
opacity: 0.4;
40+
background-color: transparent;
41+
border-color: var(--red);
42+
color: var(--text_highlight);
43+
}
44+
}
45+
&>div {
46+
transition: opacity 0.2s;
47+
background-color: var(--text_highlight);
48+
border: 3px solid var(--text_highlight);
49+
border-radius: var(--standard-border-radius);
50+
padding: 10px;
51+
cursor: pointer;
52+
transition: background-color 0.2s;
53+
box-sizing: border-box;
54+
color: var(--accent);
55+
&:hover {
56+
color: var(--text_highlight);
57+
background-color: transparent;
58+
}
59+
}
60+
&>.results {
61+
text-align: left;
62+
word-break: break-word;
63+
width: 100%;
64+
gap: 6px;
65+
font-family: monospace;
66+
display: flex;
67+
flex-direction: column;
68+
}
69+
}
70+
&>#tor {
71+
span {
72+
max-width: 1000px;
73+
margin: auto;
74+
width: 100%;
75+
display: flex;
76+
flex-wrap: wrap;
77+
b {
78+
width: 50%;
79+
}
80+
a {
81+
margin: auto;
82+
margin-bottom: 10px;
83+
text-align: center;
84+
}
85+
}
86+
}
87+
}

common/components/MainPage.scss

Lines changed: 0 additions & 89 deletions
This file was deleted.

common/components/MainPage.tsx

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
import { template } from "uix/html/template.ts";
22
import { Component } from "uix/components/Component.ts";
3-
import { spawnThreads, spawnThread } from "unyt_core/threads/threads.ts";
4-
import { always, map } from "unyt_core/functions.ts";
3+
import { spawnThreads, spawnThread, run } from "datex-core-legacy/threads/threads.ts";
54
import type { AddressData } from "common/TOR-Worker.ts";
65

76
@template(function(this: MainPage) {
8-
return <div>
9-
<div id="tor" class={always(()=>this.calculatingAddress?'hidden':'')}>
7+
return <>
8+
<div id="run" class={this.calculatingPI ? 'hidden': ''}>
9+
<h2>Use Console</h2>
10+
<div onclick={() => this.runConsole()} class="button">
11+
Run in Thread
12+
</div>
13+
</div>
14+
<div id="pi" class={this.calculatingPI ? 'hidden': ''}>
15+
<h2>Calculate PI</h2>
16+
<input id="inputPiDigits"
17+
type="number"
18+
placeholder="Number of digits"
19+
value={this.piDigits}/>
20+
<div onclick={() => this.computePI()} class="button">{
21+
this.calculatingPI ? "Waiting" : "Calculate"
22+
}</div>
23+
<section class="results">
24+
{this.resultPIs.map(pi =>
25+
<span>{pi}</span>
26+
)}
27+
</section>
28+
</div>
29+
<div id="tor" class={this.calculatingAddress ? 'hidden': ''}>
1030
<h2>Create TOR Address</h2>
11-
<input id="torAddress" maxlength="3" type="text" placeholder="Prefix of vanity address" value={this.$.addressPrefix}/>
12-
<div onclick={() => this.createVanityAddress()} class="button">Compute</div>
31+
<input id="torAddress"
32+
maxlength="3"
33+
type="text"
34+
placeholder="Prefix of vanity address"
35+
value={this.addressPrefix}/>
36+
<div onclick={() => this.createVanityAddress()} class="button">{
37+
this.calculatingAddress ? "Waiting" : "Calculate"
38+
}</div>
1339
<section class="results">
14-
{map(this.resultAddresses, (address: AddressData) =>
40+
{this.resultAddresses.map(address =>
1541
<span>
1642
<a>{address.address}</a>
1743
<b>Pub: {address.public.b64}</b>
@@ -20,44 +46,26 @@ import type { AddressData } from "common/TOR-Worker.ts";
2046
)}
2147
</section>
2248
</div>
23-
<div id="pi" class={always(()=>this.calculatingPI?'hidden':'')}>
24-
<h2>Calculate PI</h2>
25-
<input id="inputPiDigits" type="number" placeholder="Number of digits" value={this.$.piDigits}/>
26-
<div onclick={() => this.computePI()} class="button">Compute</div>
27-
<section class="results">
28-
{map(this.resultPIs, (pi: string) =>
29-
<span>{pi}</span>
30-
)}
31-
</section>
32-
</div>
33-
</div>
49+
</>
3450
})
3551
export class MainPage extends Component {
36-
3752
// reference properties for input values
3853
@property piDigits = 5;
39-
@property addressPrefix = "";
54+
@property addressPrefix = '';
4055

4156
// reference properties for calculation state
4257
@property calculatingPI = false
4358
@property calculatingAddress = false
4459

4560
// arrays containing history of calculated results
46-
@property resultPIs:string[] = []
47-
@property resultAddresses:AddressData[] = []
48-
49-
async createVanityAddress() {
50-
this.calculatingAddress = true;
61+
@property resultPIs: string[] = []
62+
@property resultAddresses: AddressData[] = []
5163

52-
// spawn 10 new threads
53-
using threads = await spawnThreads<typeof import('../TOR-Worker.ts')>('../TOR-Worker.ts', 10);
54-
// try to find an address in parallel
55-
const address = await Promise.any(
56-
threads.map(thread => thread.generateVanityAddress(this.addressPrefix))
57-
);
58-
this.resultAddresses.unshift(address);
59-
60-
this.calculatingAddress = false;
64+
runConsole() {
65+
run(() => {
66+
console.log("Hello, main thread!");
67+
globalThis.console.log("Hello, worker!");
68+
});
6169
}
6270

6371
async computePI() {
@@ -71,4 +79,18 @@ export class MainPage extends Component {
7179

7280
this.calculatingPI = false;
7381
}
82+
83+
async createVanityAddress() {
84+
this.calculatingAddress = true;
85+
86+
// spawn 10 new threads
87+
using threads = await spawnThreads<typeof import('../TOR-Worker.ts')>('../TOR-Worker.ts', 10);
88+
// try to find an address in parallel
89+
const address = await Promise.any(
90+
threads.map(thread => thread.generateVanityAddress(this.addressPrefix))
91+
);
92+
this.resultAddresses.unshift(address);
93+
94+
this.calculatingAddress = false;
95+
}
7496
}

deno.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
{
2-
"_publicImportMap": "./importmap.json",
3-
"importMap": "./.datex-cache/importmap.lock.json",
2+
"importMap": "./importmap.json",
43
"compilerOptions": {
54
"jsx": "react-jsx",
6-
"jsxImportSource": "uix",
5+
"jsxImportSource": "jusix",
76
"lib": [
87
"dom",
98
"deno.window"

frontend/entrypoint.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
slot#main {
22
overflow-y: scroll;
33
}
4-
.button {
4+
div.button {
55
display: flex;
66
align-items: center;
77
}

frontend/entrypoint.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
import { MainPage } from "../common/components/MainPage.tsx";
2-
export default <MainPage/>
1+
import { type Entrypoint } from "uix/providers/entrypoints.ts";
2+
import { MainPage } from "common/components/MainPage.tsx";
3+
export default <MainPage/> satisfies Entrypoint;

0 commit comments

Comments
 (0)