Merge branch 'v0l:main' into main

This commit is contained in:
gandlafbtc 2023-02-17 11:12:55 +01:00 committed by GitHub
commit 24c840f1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 119 additions and 29 deletions

View File

@ -1,7 +1,8 @@
node_modules/
**/node_modules/
.github/
.vscode/
build/
**/build/
yarn-error.log
.husky/
.git/
**/dist/

View File

@ -5,6 +5,9 @@ on:
jobs:
build:
runs-on: self-hosted
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v2
- uses: docker/login-action@v1
@ -12,7 +15,13 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Build the Docker image
run: docker buildx build -t ghcr.io/${{ github.repository_owner }}/snort:latest --platform linux/amd64,linux/arm64 --push .
run: |
docker buildx build \
-t ghcr.io/${{ github.repository_owner }}/snort:latest \
--platform linux/amd64,linux/arm64 \
--cache-from "type=local,src=/tmp/.buildx-cache" \
--cache-to "type=local,dest=/tmp/.buildx-cache" \
--push .

View File

@ -25,8 +25,8 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/setup-qemu-action@v2
- uses: docker/setup-buildx-action@v2
- name: Build the Docker image
run: |
docker buildx build \

View File

@ -1,7 +1,12 @@
FROM node:16 as build
WORKDIR /app
COPY . .
COPY package.json yarn.lock .
COPY packages/app/package.json packages/app/
COPY packages/nostr/package.json packages/nostr/
RUN yarn install --network-timeout 1000000
COPY . .
RUN yarn build
FROM nginx:mainline-alpine

View File

@ -154,6 +154,10 @@
font-feature-settings: "tnum";
}
.reaction-pill-icon {
margin: auto;
}
.reaction-pill .reaction-pill-number {
margin-left: 8px;
font-feature-settings: "tnum";
@ -216,3 +220,15 @@
.note .reactions-link:hover {
text-decoration: underline;
}
.close-menu {
position: absolute;
width: 100vw;
height: 100vh;
top: -400px;
left: -600px;
}
.close-menu-container {
position: absolute;
}

View File

@ -209,6 +209,13 @@ export default function NoteFooter(props: NoteFooterProps) {
function menuItems() {
return (
<>
<div className="close-menu-container">
{/* This menu item serves as a "close menu" button;
it allows the user to click anywhere nearby the menu to close it. */}
<MenuItem>
<div className="close-menu" />
</MenuItem>
</div>
{prefs.enableReactions && (
<MenuItem onClick={() => setShowReactions(true)}>
<Heart />

View File

@ -23,6 +23,10 @@ function findTag(e: TaggedRawEvent, tag: string) {
function getInvoice(zap: TaggedRawEvent) {
const bolt11 = findTag(zap, "bolt11");
if (!bolt11) {
console.debug("Invalid zap: ", zap);
return {};
}
const decoded = invoiceDecode(bolt11);
const amount = decoded.sections.find(section => section.name === "amount")?.value;
@ -66,6 +70,7 @@ export interface ParsedZap {
content: string;
zapper?: HexKey;
valid: boolean;
zapService: HexKey;
}
export function parseZap(zap: TaggedRawEvent): ParsedZap {
@ -81,6 +86,7 @@ export function parseZap(zap: TaggedRawEvent): ParsedZap {
zapper: zapper.pubkey,
content: zap.content,
valid: zapper.isValid,
zapService: zap.pubkey,
};
}

View File

@ -1,20 +1,42 @@
import { NostrPrefix } from "@snort/nostr";
import { decodeTLV, NostrPrefix, TLVEntryType } from "@snort/nostr";
import { useEffect } from "react";
import { useDispatch } from "react-redux";
import { useNavigate, useParams } from "react-router-dom";
import { setRelays } from "State/Login";
import { eventLink, profileLink } from "Util";
export default function NostrLinkHandler() {
const params = useParams();
const dispatch = useDispatch();
const navigate = useNavigate();
const link = decodeURIComponent(params["*"] ?? "");
const link = decodeURIComponent(params["*"] ?? "").toLowerCase();
useEffect(() => {
if (link.length > 0) {
const ls = link.split(":");
const entity = ls[1];
if (entity.startsWith(NostrPrefix.PublicKey) || entity.startsWith(NostrPrefix.Profile)) {
const entity = link.startsWith("web+nostr:") ? link.split(":")[1] : link;
if (entity.startsWith(NostrPrefix.PublicKey)) {
navigate(`/p/${entity}`);
} else if (entity.startsWith(NostrPrefix.Event) || entity.startsWith(NostrPrefix.Note)) {
} else if (entity.startsWith(NostrPrefix.Note)) {
navigate(`/e/${entity}`);
} else if (entity.startsWith(NostrPrefix.Profile) || entity.startsWith(NostrPrefix.Event)) {
const decoded = decodeTLV(entity);
console.debug(decoded);
const id = decoded.find(a => a.type === TLVEntryType.Special)?.value as string;
const relays = decoded.filter(a => a.type === TLVEntryType.Relay);
if (relays.length > 0) {
const relayObj = {
relays: Object.fromEntries(relays.map(a => [a.value, { read: true, write: false }])),
createdAt: new Date().getTime(),
};
dispatch(setRelays(relayObj));
}
if (entity.startsWith(NostrPrefix.Profile)) {
navigate(profileLink(id));
} else if (entity.startsWith(NostrPrefix.Event)) {
navigate(eventLink(id));
}
}
}
}, [link]);

View File

@ -75,6 +75,8 @@ export default function ProfilePage() {
users: new Map(),
creator: "",
});
const npub = !id.startsWith("npub") ? hexToBech32("npub", id || undefined) : id;
const lnurl = extractLnAddress(user?.lud16 || user?.lud06 || "");
const website_url =
user?.website && !user.website.startsWith("http") ? "https://" + user.website : user?.website || "";
@ -121,7 +123,7 @@ export default function ProfilePage() {
<FollowsYou followsMe={follows.includes(id)} />
</h2>
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
<Copy text={params.id || ""} />
<Copy text={npub} />
{links()}
</div>
);

View File

@ -86,16 +86,15 @@ export default function RootPage() {
return (
<>
<div className="main-content">{pubKey && <Tabs tabs={tabs} tab={tab} setTab={setTab} />}</div>
<div className="main-content">
{pubKey && <Tabs tabs={tabs} tab={tab} setTab={setTab} />}
{isGlobal && globalRelays.length > 0 && (
<div className="flex mb10">
<div className="f-grow">
<div className="flex mb10 f-end">
<FormattedMessage
defaultMessage="Read global from"
description="Label for reading global feed from specific relays"
/>
</div>
<div>
&nbsp;
<select onChange={e => setRelay(e.target.value)}>
{globalRelays.map(a => (
<option key={a} value={a}>
@ -104,8 +103,8 @@ export default function RootPage() {
))}
</select>
</div>
</div>
)}
</div>
{followHints()}
<Timeline
key={tab.value}

View File

@ -41,7 +41,7 @@ export function parseId(id: string) {
}
export function bech32ToHex(str: string) {
const nKey = bech32.decode(str);
const nKey = bech32.decode(str, 1_000);
const buff = bech32.fromWords(nKey.words);
return secp.utils.bytesToHex(Uint8Array.from(buff));
}

View File

@ -1,5 +1,6 @@
import * as secp from "@noble/secp256k1";
import { bech32 } from "bech32";
import { HexKey } from ".";
export enum NostrPrefix {
PublicKey = "npub",
@ -12,10 +13,17 @@ export enum NostrPrefix {
Relay = "nrelay",
}
export enum TLVEntryType {
Special = 0,
Relay = 1,
Author = 2,
Kind = 3,
}
export interface TLVEntry {
type: number;
type: TLVEntryType;
length: number;
value: string; // hex encoded data
value: string | HexKey | number;
}
export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
@ -39,7 +47,7 @@ export function encodeTLV(hex: string, prefix: NostrPrefix, relays?: string[]) {
}
export function decodeTLV(str: string) {
const decoded = bech32.decode(str);
const decoded = bech32.decode(str, 1_000);
const data = bech32.fromWords(decoded.words);
const entries: TLVEntry[] = [];
@ -51,9 +59,24 @@ export function decodeTLV(str: string) {
entries.push({
type: t,
length: l,
value: secp.utils.bytesToHex(new Uint8Array(v)),
value: decodeTLVEntry(t, new Uint8Array(v)),
});
x += 2 + l;
}
return entries;
}
function decodeTLVEntry(type: TLVEntryType, data: Uint8Array) {
switch (type) {
case TLVEntryType.Special:
case TLVEntryType.Author: {
return secp.utils.bytesToHex(data);
}
case TLVEntryType.Kind: {
return 0
}
case TLVEntryType.Relay: {
return new TextDecoder("ASCII").decode(data);
}
}
}