From 7040253f3296d15cb98533bc4e8be9ec23ca80e8 Mon Sep 17 00:00:00 2001
From: Kieran
Date: Mon, 18 Dec 2023 16:58:30 +0000
Subject: [PATCH] feat: apply for leader
---
packages/app/src/Const.ts | 5 -
packages/app/src/External/SnortApi.ts | 6 +
packages/app/src/Login/MultiAccountStore.ts | 8 +-
packages/app/src/Pages/settings/Referrals.tsx | 109 +++++++++++++++---
packages/app/src/lang.json | 18 +++
packages/app/src/translations/en.json | 6 +
6 files changed, 125 insertions(+), 27 deletions(-)
diff --git a/packages/app/src/Const.ts b/packages/app/src/Const.ts
index 07efd323..29e7192e 100644
--- a/packages/app/src/Const.ts
+++ b/packages/app/src/Const.ts
@@ -28,11 +28,6 @@ export const KieranPubKey = "npub1v0lxxxxutpvrelsksy8cdhgfux9l6a42hsj2qzquu2zk7v
*/
export const SnortPubKey = "npub1sn0rtcjcf543gj4wsg7fa59s700d5ztys5ctj0g69g2x6802npjqhjjtws";
-/**
- * Default bootstrap relays
- */
-export const DefaultRelays = new Map(Object.entries(CONFIG.defaultRelays));
-
/**
* Default search relays
*/
diff --git a/packages/app/src/External/SnortApi.ts b/packages/app/src/External/SnortApi.ts
index 3159d1c0..1b49b12e 100644
--- a/packages/app/src/External/SnortApi.ts
+++ b/packages/app/src/External/SnortApi.ts
@@ -81,6 +81,8 @@ export interface RelayDistance {
export interface RefCodeResponse {
code: string;
pubkey: string;
+ revShare?: number;
+ leaderState?: "pending" | "approved";
}
export default class SnortApi {
@@ -148,6 +150,10 @@ export default class SnortApi {
return this.#getJson(`api/v1/referral/${code}`, "GET");
}
+ applyForLeader() {
+ return this.#getJsonAuthd("api/v1/referral/leader-apply", "POST");
+ }
+
async #getJsonAuthd(
path: string,
method?: "GET" | string,
diff --git a/packages/app/src/Login/MultiAccountStore.ts b/packages/app/src/Login/MultiAccountStore.ts
index 362e6ad2..8f24ba83 100644
--- a/packages/app/src/Login/MultiAccountStore.ts
+++ b/packages/app/src/Login/MultiAccountStore.ts
@@ -3,9 +3,8 @@ import * as utils from "@noble/curves/abstract/utils";
import { v4 as uuid } from "uuid";
import { HexKey, RelaySettings, EventPublisher, KeyStorage, NotEncrypted, socialGraphInstance } from "@snort/system";
-import { deepClone, sanitizeRelayUrl, unwrap, ExternalStore } from "@snort/shared";
+import { deepClone, unwrap, ExternalStore } from "@snort/shared";
-import { DefaultRelays } from "@/Const";
import { LoginSession, LoginSessionType, createPublisher } from "@/Login";
import { DefaultPreferences, UserPreferences } from "./Preferences";
@@ -39,7 +38,7 @@ const LoggedOut = {
timestamp: 0,
},
relays: {
- item: Object.fromEntries([...DefaultRelays.entries()].map(a => [unwrap(sanitizeRelayUrl(a[0])), a[1]])),
+ item: CONFIG.defaultRelays,
timestamp: 0,
},
latestNotification: 0,
@@ -49,6 +48,7 @@ const LoggedOut = {
item: {
mutedWords: [],
preferences: DefaultPreferences,
+ showContentWarningPosts: false,
},
timestamp: 0,
},
@@ -179,7 +179,7 @@ export class MultiAccountStore extends ExternalStore {
if (relays && Object.keys(relays).length > 0) {
return relays;
}
- return Object.fromEntries(DefaultRelays.entries());
+ return CONFIG.defaultRelays;
}
loginWithPrivateKey(key: KeyStorage, entropy?: string, relays?: Record) {
diff --git a/packages/app/src/Pages/settings/Referrals.tsx b/packages/app/src/Pages/settings/Referrals.tsx
index b103ba22..fc7ef2bd 100644
--- a/packages/app/src/Pages/settings/Referrals.tsx
+++ b/packages/app/src/Pages/settings/Referrals.tsx
@@ -1,20 +1,100 @@
+import AsyncButton from "@/Element/Button/AsyncButton";
import { LeaderBadge } from "@/Element/CommunityLeaders/LeaderBadge";
import Copy from "@/Element/Copy";
-import SnortApi from "@/External/SnortApi";
+import SnortApi, { RefCodeResponse } from "@/External/SnortApi";
import useEventPublisher from "@/Hooks/useEventPublisher";
import { useEffect, useState } from "react";
-import { FormattedMessage } from "react-intl";
+import { FormattedMessage, FormattedNumber } from "react-intl";
+import { Link } from "react-router-dom";
export function ReferralsPage() {
- const [refCode, setRefCode] = useState("");
+ const [refCode, setRefCode] = useState();
const { publisher } = useEventPublisher();
+ const api = new SnortApi(undefined, publisher);
+
+ async function loadRefCode() {
+ const c = await api.getRefCode();
+ setRefCode(c);
+ }
useEffect(() => {
- const api = new SnortApi(undefined, publisher);
-
- api.getRefCode().then(v => setRefCode(v.code));
+ loadRefCode();
}, [publisher]);
+ async function applyNow() {
+ await api.applyForLeader();
+ await loadRefCode();
+ }
+
+ function becomeLeader() {
+ return (
+ <>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ >
+ );
+ }
+
+ function leaderPending() {
+ return (
+ <>
+
+
+
+
+
+
+
+
+
+
+
+
+
+ >
+ );
+ }
+
+ function leaderInfo() {
+ return (
+ <>
+
+
+
+
+ {c},
+ percent: ,
+ }}
+ />
+
+
+
+
+ >
+ );
+ }
+
return (
<>
@@ -25,7 +105,7 @@ export function ReferralsPage() {
defaultMessage="Your referral code is {code}"
id="UxgyeY"
values={{
- code: {refCode},
+ code: {refCode?.code},
}}
/>
@@ -36,18 +116,11 @@ export function ReferralsPage() {
/>
-
+
-
-
-
-
-
-
-
-
-
-
+ {refCode?.leaderState === undefined && becomeLeader()}
+ {refCode?.leaderState === "pending" && leaderPending()}
+ {refCode?.leaderState === "approved" && leaderInfo()}
>
);
}
diff --git a/packages/app/src/lang.json b/packages/app/src/lang.json
index d4eb21cc..836640cc 100644
--- a/packages/app/src/lang.json
+++ b/packages/app/src/lang.json
@@ -543,6 +543,9 @@
"H0JBH6": {
"defaultMessage": "Log Out"
},
+ "H0OG3T": {
+ "defaultMessage": "Leader Info"
+ },
"H6/kLh": {
"defaultMessage": "Order Paid!"
},
@@ -737,6 +740,9 @@
"NndBJE": {
"defaultMessage": "New users page"
},
+ "O3Jz4E": {
+ "defaultMessage": "Use your invite code to earn sats!"
+ },
"O8Z8t9": {
"defaultMessage": "Show More"
},
@@ -872,6 +878,9 @@
"TaeBqw": {
"defaultMessage": "Sign in with Nostr Extension"
},
+ "TdTXXf": {
+ "defaultMessage": "Learn more"
+ },
"TdtZQ5": {
"defaultMessage": "Crypto"
},
@@ -909,6 +918,9 @@
"Up5U7K": {
"defaultMessage": "Block"
},
+ "Ups2/p": {
+ "defaultMessage": "Your application is pending"
+ },
"UrKTqQ": {
"defaultMessage": "You have an active iris.to account"
},
@@ -1030,6 +1042,9 @@
"b5vAk0": {
"defaultMessage": "Your handle will act like a lightning address and will redirect to your chosen LNURL or Lightning address"
},
+ "bF1MYT": {
+ "defaultMessage": "You are a community leader and are earning {percent} of referred users subscriptions!"
+ },
"bG00/W": {
"defaultMessage": "Service Worker Running"
},
@@ -1293,6 +1308,9 @@
"jzgQ2z": {
"defaultMessage": "{n} Reactions"
},
+ "k0kCJp": {
+ "defaultMessage": "Apply Now"
+ },
"k2veDA": {
"defaultMessage": "Write"
},
diff --git a/packages/app/src/translations/en.json b/packages/app/src/translations/en.json
index 93f847a8..1ee05b3b 100644
--- a/packages/app/src/translations/en.json
+++ b/packages/app/src/translations/en.json
@@ -179,6 +179,7 @@
"Gxcr08": "Broadcast Event",
"H+vHiz": "Hex Key..",
"H0JBH6": "Log Out",
+ "H0OG3T": "Leader Info",
"H6/kLh": "Order Paid!",
"HAlOn1": "Name",
"HFls6j": "name will be available later",
@@ -243,6 +244,7 @@
"NdOYJJ": "Hmm nothing here.. Checkout {newUsersPage} to follow some recommended nostrich's!",
"NepkXH": "Can't vote with {amount} sats, please set a different default zap amount",
"NndBJE": "New users page",
+ "O3Jz4E": "Use your invite code to earn sats!",
"O8Z8t9": "Show More",
"OEW7yJ": "Zaps",
"OKhRC6": "Share",
@@ -287,6 +289,7 @@
"TJo5E6": "Preview",
"TP/cMX": "Ended",
"TaeBqw": "Sign in with Nostr Extension",
+ "TdTXXf": "Learn more",
"TdtZQ5": "Crypto",
"TpgeGw": "Hex Salt..",
"Tpy00S": "People",
@@ -299,6 +302,7 @@
"UUPFlt": "Users must accept the content warning to show the content of your note.",
"Ub+AGc": "Sign In",
"Up5U7K": "Block",
+ "Ups2/p": "Your application is pending",
"UrKTqQ": "You have an active iris.to account",
"UxgyeY": "Your referral code is {code}",
"VL900k": "Recommended Relays",
@@ -339,6 +343,7 @@
"aWpBzj": "Show more",
"b12Goz": "Mnemonic",
"b5vAk0": "Your handle will act like a lightning address and will redirect to your chosen LNURL or Lightning address",
+ "bF1MYT": "You are a community leader and are earning {percent} of referred users subscriptions!",
"bG00/W": "Service Worker Running",
"bLZL5a": "Get Address",
"bMphls": "Logged in with read-only access",
@@ -426,6 +431,7 @@
"jTrbGf": "{n} km - {location}",
"jvo0vs": "Save",
"jzgQ2z": "{n} Reactions",
+ "k0kCJp": "Apply Now",
"k2veDA": "Write",
"k7sKNy": "Our very own NIP-05 verification service, help support the development of this site and get a shiny special badge on our site!",
"kEZUR8": "Register an Iris username",