From 9479b4fc55fd88f25ad7763ab15cfcc5fbd2a57b Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Sat, 23 Dec 2023 21:20:07 -0600 Subject: [PATCH] Remove redshift --- e2e/routes.spec.ts | 7 - src/components/Activity.tsx | 2 - src/components/NavBar.tsx | 8 - src/i18n/en/translations.ts | 24 -- src/i18n/ko/translations.ts | 19 - src/router.tsx | 2 - src/routes/Redshift.tsx | 652 ----------------------------------- src/routes/index.ts | 1 - src/routes/settings/Plus.tsx | 4 - src/utils/fakeLabels.ts | 20 -- src/utils/index.ts | 1 - 11 files changed, 740 deletions(-) delete mode 100644 src/routes/Redshift.tsx delete mode 100644 src/utils/fakeLabels.ts diff --git a/e2e/routes.spec.ts b/e2e/routes.spec.ts index e9a9bbe..b95e4fc 100644 --- a/e2e/routes.spec.ts +++ b/e2e/routes.spec.ts @@ -6,7 +6,6 @@ const routes = [ "/feedback", "/gift", "/receive", - "/redshift", "/scanner", "/send", "/swap", @@ -182,12 +181,6 @@ test("visit each route", async ({ page }) => { "Add Connection" ); - // Redshift - await page.goto("http://localhost:3420/redshift"); - await expect(page.locator("h1")).toHaveText("Redshift (coming soon)"); - checklist.set("/redshift", true); - await page.goBack(); - // Swap await page.goto("http://localhost:3420/swap"); await expect(page.locator("h1")).toHaveText("Swap to Lightning"); diff --git a/src/components/Activity.tsx b/src/components/Activity.tsx index 228e25b..cc6abfb 100644 --- a/src/components/Activity.tsx +++ b/src/components/Activity.tsx @@ -26,8 +26,6 @@ export const THREE_COLUMNS = export const CENTER_COLUMN = "min-w-0 overflow-hidden max-w-full"; export const MISSING_LABEL = "py-1 px-2 bg-white/10 rounded inline-block text-sm"; -export const REDSHIFT_LABEL = - "py-1 px-2 bg-white text-m-red rounded inline-block text-sm"; export const RIGHT_COLUMN = "flex flex-col items-right text-right max-w-[8rem]"; export interface IActivityItem { diff --git a/src/components/NavBar.tsx b/src/components/NavBar.tsx index dd47243..06afc88 100644 --- a/src/components/NavBar.tsx +++ b/src/components/NavBar.tsx @@ -3,7 +3,6 @@ import { A } from "@solidjs/router"; import airplane from "~/assets/icons/airplane.svg"; import receive from "~/assets/icons/big-receive.svg"; import mutiny_m from "~/assets/icons/m.svg"; -import redshift from "~/assets/icons/rs.svg"; import scan from "~/assets/icons/scan.svg"; import settings from "~/assets/icons/settings.svg"; import userClock from "~/assets/icons/user-clock.svg"; @@ -14,7 +13,6 @@ type ActiveTab = | "send" | "receive" | "settings" - | "redshift" | "activity" | "none"; @@ -74,12 +72,6 @@ export function NavBar(props: { activeTab: ActiveTab }) { active={false} alt="scan" /> - - diff --git a/src/routes/Redshift.tsx b/src/routes/Redshift.tsx deleted file mode 100644 index 90c42d9..0000000 --- a/src/routes/Redshift.tsx +++ /dev/null @@ -1,652 +0,0 @@ -import { MutinyChannel } from "@mutinywallet/mutiny-wasm"; -import { - createEffect, - createMemo, - createResource, - createSignal, - For, - Match, - onMount, - ParentComponent, - Show, - Suspense, - Switch -} from "solid-js"; - -import utxoIcon from "~/assets/icons/coin.svg"; -import wave from "~/assets/wave.gif"; -import { - AmountSats, - BackLink, - Button, - Card, - CENTER_COLUMN, - DefaultMain, - LargeHeader, - LoadingSpinner, - MISSING_LABEL, - MutinyWalletGuard, - NavBar, - NiceP, - ProgressBar, - REDSHIFT_LABEL, - RIGHT_COLUMN, - SafeArea, - SmallAmount, - SmallHeader, - StyledRadioGroup, - THREE_COLUMNS, - VStack -} from "~/components"; -import { useI18n } from "~/i18n/context"; -import { Network } from "~/logic/mutinyWalletSetup"; -import { useMegaStore } from "~/state/megaStore"; -import { getRedshifted, mempoolTxUrl, setRedshifted } from "~/utils"; - -type ShiftOption = "utxo" | "lightning"; - -type ShiftStage = "choose" | "observe" | "success" | "failure"; - -type OutPoint = string; // Replace with the actual TypeScript type for OutPoint -type RedshiftStatus = string; // Replace with the actual TypeScript type for RedshiftStatus -type RedshiftRecipient = unknown; // Replace with the actual TypeScript type for RedshiftRecipient -type PublicKey = unknown; // Replace with the actual TypeScript type for PublicKey - -interface RedshiftResult { - id: string; - input_utxo: OutPoint; - status: RedshiftStatus; - recipient: RedshiftRecipient; - output_utxo?: OutPoint; - introduction_channel?: OutPoint; - output_channel?: OutPoint; - introduction_node: PublicKey; - amount_sats: bigint; - change_amt?: bigint; - fees_paid: bigint; -} - -interface UtxoItem { - outpoint: string; - txout: { - value: number; - script_pubkey: string; - }; - keychain: string; - is_spent: boolean; - redshifted?: boolean; -} - -const dummyRedshift: RedshiftResult = { - id: "44036599c37d590899e8d5d920860286", - input_utxo: - "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1", - status: "Completed", // Replace with a dummy value for RedshiftStatus - recipient: {}, // Replace with a dummy value for RedshiftRecipient - output_utxo: - "44036599c37d590899e8d5d92086028695d2c2966fdc354ce1da9a9eac610a53:1", - introduction_channel: - "a7773e57f8595848a635e9af105927cac9ecaf292d71a76456ae0455bd3c9c64:0", - output_channel: - "a7773e57f8595848a635e9af105927cac9ecaf292d71a76456ae0455bd3c9c64:0", - introduction_node: {}, // Replace with a dummy value for PublicKey - amount_sats: BigInt(1000000), - change_amt: BigInt(12345), - fees_paid: BigInt(2500) -}; - -function RedshiftReport(props: { redshift: RedshiftResult; utxo: UtxoItem }) { - const i18n = useI18n(); - const [state, _actions] = useMegaStore(); - - const getUtXos = async () => { - console.log("Getting utxos"); - return (await state.mutiny_wallet?.list_utxos()) as UtxoItem[]; - }; - - // function findUtxoByOutpoint( - // outpoint?: string, - // utxos: UtxoItem[] = [] - // ): UtxoItem | undefined { - // if (!outpoint) return undefined - // return utxos.find((utxo) => utxo.outpoint === outpoint) - // } - - const [_utxos, { refetch: _refetchUtxos }] = createResource(getUtXos); - - // const inputUtxo = createMemo(() => { - // console.log(utxos()) - // const foundUtxo = findUtxoByOutpoint(props.redshift.input_utxo, utxos()) - // console.log("Found utxo:", foundUtxo) - // return foundUtxo - // }) - - const [redshiftResource, { refetch: _refetchRedshift }] = createResource( - async () => { - console.log("Checking redshift", props.redshift.id); - const redshift = await state.mutiny_wallet?.get_redshift( - props.redshift.id - ); - console.log(redshift); - return redshift; - } - ); - onMount(() => { - // const interval = setInterval(() => { - // if (redshiftResource()) refetch() - // // if (sentAmount() === 200000) { - // // clearInterval(interval) - // // props.setShiftStage("success"); - // // // setSentAmount((0)) - // // } else { - // // setSentAmount((sentAmount() + 50000)) - // // } - // }, 1000) - }); - - // const outputUtxo = createMemo(() => { - // return findUtxoByOutpoint(redshiftResource()?.output_utxo, utxos()) - // }) - - createEffect(() => { - setRedshifted(true, redshiftResource()?.output_utxo); - }); - - const network = state.mutiny_wallet?.get_network() as Network; - - return ( - - {/* - We did it. Here's your new UTXO: - - - - - - */} - - {i18n.t("redshift.what_happened")} - - - - {/* - - - - */} - - - - - - - - - - - -
-                                        {
-                                            redshiftResource()!
-                                                .introduction_channel
-                                        }
-                                    
- - {i18n.t("common.view_transaction")} - -
-
- - - -
-                                            {redshiftResource()!.output_channel}
-                                        
- - {i18n.t("common.view_transaction")} - -
-
-
-
-
-
-
-
- ); -} - -export function Utxo(props: { item: UtxoItem; onClick?: () => void }) { - const i18n = useI18n(); - const redshifted = createMemo(() => getRedshifted(props.item.outpoint)); - return ( - <> -
props.onClick && props.onClick()} - > -
- coin -
-
-
- - {i18n.t("redshift.unknown")} - - } - > -

- {i18n.t("redshift.title")} -

-
-
- -
-
- - {/* {props.item?.is_spent ? "SPENT" : "UNSPENT"} */} - -
-
- - ); -} - -const FAKE_STATES = [ - "Creating a new node", - "Opening a channel", - "Sending funds through", - "Closing the channel", - "Redshift complete" -]; - -function ShiftObserver(props: { - setShiftStage: (stage: ShiftStage) => void; - redshiftId: string; -}) { - const i18n = useI18n(); - const [_state, _actions] = useMegaStore(); - - const [fakeStage, _setFakeStage] = createSignal(2); - - const [sentAmount, setSentAmount] = createSignal(0); - - onMount(() => { - const interval = setInterval(() => { - if (sentAmount() === 200000) { - clearInterval(interval); - props.setShiftStage("success"); - // setSentAmount((0)) - } else { - setSentAmount(sentAmount() + 50000); - } - }, 1000); - }); - - // async function checkRedshift(id: string) { - // console.log("Checking redshift", id) - // const redshift = await state.mutiny_wallet?.get_redshift(id) - // console.log(redshift) - // return redshift - // } - - // const [redshiftResource, { refetch }] = createResource( - // props.redshiftId, - // checkRedshift - // ) - - // onMount(() => { - // const interval = setInterval(() => { - // if (redshiftResource()) refetch(); - // // if (sentAmount() === 200000) { - // // clearInterval(interval) - // // props.setShiftStage("success"); - // // // setSentAmount((0)) - - // // } else { - // // setSentAmount((sentAmount() + 50000)) - // // } - // }, 1000) - // }) - - // createEffect(() => { - // const interval = setInterval(() => { - // if (chosenUtxo()) refetch(); - // }, 1000); // Poll every second - // onCleanup(() => { - // clearInterval(interval); - // }); - // }); - - return ( - <> - {i18n.t("redshift.watch_it_go")} - - -
{FAKE_STATES[fakeStage()]}
- - sine wave -
-
- - ); -} - -const KV: ParentComponent<{ key: string }> = (props) => { - return ( -
-

{props.key}

- {props.children} -
- ); -}; - -export function Redshift() { - const i18n = useI18n(); - const [state, _actions] = useMegaStore(); - - const [shiftStage, setShiftStage] = createSignal("choose"); - const [shiftType, setShiftType] = createSignal("utxo"); - - const [chosenUtxo, setChosenUtxo] = createSignal(); - - const SHIFT_OPTIONS = [ - { - value: "utxo", - label: i18n.t("redshift.utxo_label"), - caption: i18n.t("redshift.utxo_caption") - }, - { - value: "lightning", - label: i18n.t("redshift.lightning_label"), - caption: i18n.t("redshift.lightning_caption") - } - ]; - - const getUtXos = async () => { - console.log("Getting utxos"); - return (await state.mutiny_wallet?.list_utxos()) as UtxoItem[]; - }; - - // TODO: FIXME: this is old code needs to be revisited! - const getChannels = async () => { - console.log("Getting channels"); - // await state.mutiny_wallet?.sync(); - const channels = - (await state.mutiny_wallet?.list_channels()) as Promise< - MutinyChannel[] - >; - console.log(channels); - return channels; - }; - - const [utxos, { refetch: _refetchUtxos }] = createResource(getUtXos); - const [_channels, { refetch: _refetchChannels }] = - createResource(getChannels); - - const redshiftedUtxos = createMemo(() => { - return utxos()?.filter((utxo) => getRedshifted(utxo.outpoint)); - }); - - const unredshiftedUtxos = createMemo(() => { - return utxos()?.filter((utxo) => !getRedshifted(utxo.outpoint)); - }); - - function resetState() { - setShiftStage("choose"); - setShiftType("utxo"); - setChosenUtxo(undefined); - } - - async function redshiftUtxo(utxo: UtxoItem) { - console.log("Redshifting utxo", utxo.outpoint); - const redshift = await state.mutiny_wallet?.init_redshift( - utxo.outpoint - ); - console.log("Redshift initialized:"); - console.log(redshift); - return redshift; - } - - const [initializedRedshift, { refetch: _refetchRedshift }] = createResource( - chosenUtxo, - redshiftUtxo - ); - - createEffect(() => { - if (chosenUtxo() && initializedRedshift()) { - // window.location.href = "/" - setShiftStage("observe"); - } - }); - - return ( - - - - - - {i18n.t("redshift.title")}{" "} - {i18n.t("common.coming_soon")} - -
- - {/*
{JSON.stringify(redshiftResource(), null, 2)}
*/} - - - - - {i18n.t("redshift.where_this_goes")} - - - setShiftType( - newValue as ShiftOption - ) - } - choices={SHIFT_OPTIONS} - /> - - - - {i18n.t("redshift.choose_your")}{" "} - - sine wave - {" "} - {i18n.t("redshift.utxo_to_begin")} - - - - - - - - - - {i18n.t( - "redshift.no_utxos_empty_state" - )} - - - = 0 - } - > - - {(utxo) => ( - - setChosenUtxo( - utxo - ) - } - /> - )} - - - - - - - - - {i18n.t( - "redshift.redshifted" - )}{" "} - - {i18n.t( - "redshift.utxos" - )} - - } - > - - - - - - - {i18n.t( - "redshift.no_utxos_empty_state" - )} - - - = 0 - } - > - - {(utxo) => ( - - )} - - - - - - - - - - - - - - - - - - {i18n.t("redshift.oh_dear")} - - {i18n.t("redshift.here_is_error")} - - - - -
-
-
- -
-
- ); -} diff --git a/src/routes/index.ts b/src/routes/index.ts index 504b03c..0e520cc 100644 --- a/src/routes/index.ts +++ b/src/routes/index.ts @@ -4,7 +4,6 @@ export * from "./Feedback"; export * from "./Gift"; export * from "./Main"; export * from "./Receive"; -export * from "./Redshift"; export * from "./Scanner"; export * from "./Send"; export * from "./Swap"; diff --git a/src/routes/settings/Plus.tsx b/src/routes/settings/Plus.tsx index 654e37a..c806d98 100644 --- a/src/routes/settings/Plus.tsx +++ b/src/routes/settings/Plus.tsx @@ -48,10 +48,6 @@ function Perks(props: { alreadySubbed?: boolean }) { -
  • - {i18n.t("redshift.title")}{" "} - {i18n.t("common.coming_soon")} -
  • {i18n.t("settings.plus.multi_device")}{" "} {i18n.t("common.coming_soon")} diff --git a/src/utils/fakeLabels.ts b/src/utils/fakeLabels.ts deleted file mode 100644 index e225abe..0000000 --- a/src/utils/fakeLabels.ts +++ /dev/null @@ -1,20 +0,0 @@ -// Simple storage for fake labels -// For each outpoint string, we can store a boolean whether it's redshifted or not - -function setRedshifted(redshifted: boolean, outpoint?: string) { - if (outpoint === undefined) return; - localStorage.setItem(outpoint, redshifted.toString()); -} - -function getRedshifted(outpoint: string): boolean { - const redshifted = localStorage.getItem(outpoint); - if (redshifted === null) { - return false; - } - return redshifted === "true"; -} - -const TEST_UTXO = - "47651763fbd74488a478aad80e4205c3e34bbadcfc42b5cd9557ef12a15ab00c:1"; - -export { setRedshifted, getRedshifted, TEST_UTXO }; diff --git a/src/utils/index.ts b/src/utils/index.ts index 5c2c39b..e372fad 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -2,7 +2,6 @@ export * from "./conversions"; export * from "./deepSignal"; export * from "./download"; export * from "./eify"; -export * from "./fakeLabels"; export * from "./getHostname"; export * from "./gradientHash"; export * from "./mempoolTxUrl";