Nip5 shop #50

Merged
v0l merged 9 commits from nip5-shop into main 2023-01-13 09:48:07 +00:00
7 changed files with 245 additions and 6 deletions
Showing only changes of commit bcdf035063 - Show all commits

View File

@ -0,0 +1,98 @@
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
import { useEffect, useMemo, useState } from "react";
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
import { useSelector } from "react-redux";
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
import { ServiceProvider, ServiceConfig, ServiceError, HandleAvailability, ServiceErrorCode } from "../nip05/ServiceProvider";
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
type Nip05ServiceProps = {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
name: string,
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
service: URL | string,
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
about: JSX.Element,
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
link: string
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
};
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
type ReduxStore = any;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
export default function Nip5Service(props: Nip05ServiceProps) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:56:30 +00:00 (Migrated from github.com)
Review

We can revisit this once our components are in TS.

We can revisit this once our components are in TS.
const pubkey = useSelector<ReduxStore, string>(s => s.login.publicKey);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const svc = new ServiceProvider(props.service);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const [serviceConfig, setServiceConfig] = useState<ServiceConfig>();
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const [error, setError] = useState<ServiceError>();
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const [handle, setHandle] = useState<string>("");
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const [domain, setDomain] = useState<string>("");
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const [availabilityResponse, setAvailabilityResponse] = useState<HandleAvailability>();
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
const domainConfig = useMemo(() => serviceConfig?.domains.find(a => a.name === domain), [domain]);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
useEffect(() => {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
svc.GetConfig()
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
.then(a => {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
if ('error' in a) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setError(a as ServiceError)
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
} else {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
let svc = a as ServiceConfig;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setServiceConfig(svc);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
let defaultDomain = svc.domains.find(a => a.default)?.name || svc.domains[0].name;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setDomain(defaultDomain);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
})
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
.catch(console.error)
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}, [props]);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
useEffect(() => {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
if(handle.length === 0) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setAvailabilityResponse(undefined);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
if (handle && domain) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
if (!domainConfig?.regex[0].match(handle)) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setAvailabilityResponse({ available: false, why: "REGEX" });
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
return;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
svc.CheckAvailable(handle, domain)
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
.then(a => {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
if ('error' in a) {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setError(a as ServiceError);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
} else {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
setAvailabilityResponse(a as HandleAvailability);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
})
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
.catch(console.error);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}, [handle, domain]);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
function mapError(e: ServiceErrorCode, t: string | null): string | undefined {
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
let whyMap = new Map([
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["TOO_SHORT", "name too short"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["TOO_LONG", "name too long"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["REGEX", "name has disallowed characters"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["REGISTERED", "name is registered"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["DISALLOWED_null", "name is blocked"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
["DISALLOWED_later", "name will be available later"],
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
]);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
return whyMap.get(e === "DISALLOWED" ? `${e}_${t}` : e);
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
return (
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<h3>{props.name}</h3>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{props.about}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<p>Find out more info about {props.name} at <a href={props.link} target="_blank" rel="noreferrer">{props.link}</a></p>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{error && <b className="error">{error.error}</b>}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<div className="flex mb10">
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<input type="text" placeholder="Handle" value={handle} onChange={(e) => setHandle(e.target.value)} />
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
&nbsp;@&nbsp;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<select value={domain} onChange={(e) => setDomain(e.target.value)}>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{serviceConfig?.domains.map(a => <option selected={a.default}>{a.name}</option>)}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</select>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</div>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{availabilityResponse?.available && <div className="flex">
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<div>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{availabilityResponse.quote?.price.toLocaleString()} sats
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
&nbsp;
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</div>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<input type="text" className="f-grow mr10" placeholder="pubkey" value={pubkey} disabled={pubkey ? true : false} />
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<div className="btn">Buy Now</div>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</div>}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
{availabilityResponse?.available === false && <div className="flex">
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
<b className="error">Not available: {mapError(availabilityResponse.why!, availabilityResponse.reasonTag || null)}</b>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</div>}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
</>
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
)
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥
}
verbiricha commented 2023-01-13 07:52:28 +00:00 (Migrated from github.com)
Review

🔥

🔥

View File

@ -107,7 +107,7 @@ textarea {
font: inherit;
}
input[type="text"], input[type="password"], input[type="number"], textarea {
input[type="text"], input[type="password"], input[type="number"], textarea, select {
padding: 10px;
border-radius: 5px;
border: 0;
@ -115,6 +115,11 @@ input[type="text"], input[type="password"], input[type="number"], textarea {
color: var(--font-color);
}
input:disabled {
color: var(--gray-medium);
cursor:not-allowed;
}
textarea:placeholder {
color: var(--gray-superlight);
}

View File

@ -18,7 +18,8 @@ import Store from "./state/Store";
import NotificationsPage from './pages/Notifications';
import NewUserPage from './pages/NewUserPage';
import SettingsPage from './pages/SettingsPage';
import ErrorPage from './pages/ErrorPage.tsx';
import ErrorPage from './pages/ErrorPage';
import VerificationPage from './pages/Verification';
/**
* Nostr websocket managment system
@ -57,6 +58,10 @@ const router = createBrowserRouter([
{
path: "/settings",
element: <SettingsPage />
},
{
path: "/verification",
element: <VerificationPage />
}
]
}

View File

@ -0,0 +1,86 @@
export type ServiceErrorCode = "UNKNOWN_ERROR" | "INVALID_BODY" | "NO_SUCH_DOMAIN" | "TOO_SHORT" | "TOO_LONG" | "REGEX" | "DISALLOWED" | "REGISTERED" | "NOT_AVAILABLE" | "RATE_LIMITED" | "NO_TOKEN" | "INVALID_TOKEN" | "NO_SUCH_PAYMENT";
export interface ServiceError {
error: ServiceErrorCode
};
export interface ServiceConfig {
domains: DomainConfig[]
}
export type DomainConfig = {
name: string,
default: boolean,
length: [number, number],
regex: [string, string],
regexChars: [string, string]
}
export type HandleAvailability = {
available: boolean,
why?: ServiceErrorCode,
reasonTag?: string | null,
quote?: HandleQuote
}
export type HandleQuote = {
price: number,
data: any
}
export type HandleRegisterResponse = {
quote: HandleQuote,
paymentHash: string,
invoice: string,
token: string
}
export class ServiceProvider {
readonly url: URL | string
constructor(url: URL | string) {
this.url = url;
}
async GetConfig(): Promise<ServiceConfig | ServiceError> {
return await this._GetJson("/config.json");
}
async CheckAvailable(handle: string, domain: string): Promise<HandleAvailability | ServiceError> {
return await this._GetJson("/registration/availability", "POST", { name: handle, domain });
}
async RegisterHandle(handle: string, domain: string, pubkey: string): Promise<HandleRegisterResponse | ServiceError> {
return await this._GetJson("/registration/register", "PUT", { name: handle, domain, pk: pubkey });
}
async CheckRegistration(token: string): Promise<any> {
return await this._GetJson("/registration/register/check", "POST", undefined, {
authorization: token
});
}
async _GetJson<T>(path: string, method?: "GET" | string, body?: any, headers?: any): Promise<T | ServiceError> {
try {
let rsp = await fetch(`${this.url}${path}`, {
method: method,
body: body ? JSON.stringify(body) : undefined,
headers: {
accept: "application/json",
...(body ? { "content-type": "application/json" } : {}),
...headers
}
});
if (rsp.ok) {
let obj = await rsp.json();
if ('error' in obj) {
return <ServiceError>obj;
}
return obj;
}
} catch (e) {
console.warn(e);
}
return { error: "UNKNOWN_ERROR" };
}
}

View File

@ -1,15 +1,14 @@
import React, { FC } from "react";
import { useRouteError } from "react-router-dom";
const ErrorPage: FC = () => {
const ErrorPage = () => {
const error = useRouteError();
console.error(error);
return (
<>
<h4>{error?.message ?? "Uknown error"}</h4>
<h4>An error has occured!</h4>
<pre>
{JSON.stringify(error)}
{JSON.stringify(error, undefined, ' ')}
</pre>
</>
);

View File

@ -0,0 +1,37 @@
import Nip5Service from "../element/Nip5Service";
export default function VerificationPage() {
const services = [
/*{
name: "Snort",
service: "https://api.snort.social/api/v1/n5sp",
link: "https://snort.social/",
about: <>Our very own NIP-05 verification service, help support the development of this site and get a shiny special badge on our site!</>
},*/
{
name: "Nostr Plebs",
service: "https://nostrplebs.com/api/v1",
link: "https://nostrplebs.com/",
about: <>
<p>Nostr Plebs is one of the first NIP-05 providers in the space and offers a good collection of domains at reasonable prices</p>
</>
}
];
return (
<>
<h2>Get Verified</h2>
<p>
NIP-05 is a DNS based verification spec which helps to validate you as a real user.
</p>
<p>Getting NIP-05 verified can help:</p>
<ul>
<li>Prevent fake accounts from immitating you</li>
<li>Make your profile easier to find and share</li>
<li>Fund developers and platforms providing NIP-05 verification services</li>
</ul>
{services.map(a => <Nip5Service key={a.name} {...a} />)}
</>
)
}

9
tsconfig.json Normal file
View File

@ -0,0 +1,9 @@
{
"compilerOptions": {
"jsx": "react-jsx",
"moduleResolution": "node",
"forceConsistentCasingInFileNames": true,
"strict": true,
"skipLibCheck": true
}
}