Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Apr 23, 2024
1 parent 189d550 commit 75fa2b9
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 55 deletions.
28 changes: 18 additions & 10 deletions src/components/ActivityDetailsModal.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Dialog } from "@kobalte/core";
import {
MutinyChannel,
ActivityItem,
MutinyInvoice,
TagItem
} from "@mutinywallet/mutiny-wasm";
import { createAsync } from "@solidjs/router";
import { Copy, Link, Shuffle, Zap } from "lucide-solid";
import {
createEffect,
createMemo,
createResource,
Match,
ParentComponent,
Expand All @@ -30,7 +30,6 @@ import {
VStack
} from "~/components";
import { useI18n } from "~/i18n/context";
import { Network } from "~/logic/mutinyWalletSetup";
import { BalanceBar } from "~/routes/settings/Channels";
import { useMegaStore } from "~/state/megaStore";
import { mempoolTxUrl, prettyPrintTime, useCopy } from "~/utils";
Expand Down Expand Up @@ -497,7 +496,7 @@ export function ActivityDetailsModal(props: {
id: string;
setOpen: (open: boolean) => void;
}) {
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const id = () => props.id;
const kind = () => props.kind;

Expand All @@ -523,15 +522,18 @@ export function ActivityDetailsModal(props: {
return undefined;
}
});
const tags = createMemo(() => {
const tags = createAsync(async () => {
if (
!!data() &&
// @ts-expect-error we're narrowing the type here
data()?.labels !== undefined &&
// @ts-expect-error we're narrowing the type here
typeof data()?.labels[0] === "string"
) {
const typedData = data() as MutinyInvoice | ActivityItem;
try {
// find if there's just one for now
const tags = sw.get_tag_item(data().labels[0]);
const tags = await sw.get_tag_item(typedData.labels[0]);
if (tags) {
return tags;
} else {
Expand Down Expand Up @@ -591,7 +593,7 @@ export function ActivityDetailsModal(props: {
>
<OnchainHeader
info={
data() as OnChainTx
data() as unknown as OnChainTx
}
kind={kind()}
/>
Expand All @@ -605,7 +607,9 @@ export function ActivityDetailsModal(props: {
<Switch>
<Match when={kind() === "Lightning"}>
<LightningDetails
info={data() as MutinyInvoice}
info={
data() as unknown as MutinyInvoice
}
tags={tags()}
/>
</Match>
Expand All @@ -616,14 +620,18 @@ export function ActivityDetailsModal(props: {
}
>
<OnchainDetails
info={data() as OnChainTx}
info={
data() as unknown as OnChainTx
}
kind={kind()}
tags={tags()}
/>
</Match>
<Match when={kind() === "ChannelClose"}>
<ChannelCloseDetails
info={data() as ChannelClosure}
info={
data() as unknown as ChannelClosure
}
/>
</Match>
</Switch>
Expand Down
2 changes: 1 addition & 1 deletion src/components/DeleteEverything.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { eify } from "~/utils";

export function DeleteEverything(props: { emergency?: boolean }) {
const i18n = useI18n();
const [state, actions, sw] = useMegaStore();
const [state, actions] = useMegaStore();

async function confirmReset() {
setConfirmOpen(true);
Expand Down
2 changes: 1 addition & 1 deletion src/components/EditProfileForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export function EditProfileForm(props: {
saving: boolean;
cta: string;
}) {
const [state, actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const [uploading, setUploading] = createSignal(false);
const [uploadError, setUploadError] = createSignal<Error>();

Expand Down
2 changes: 1 addition & 1 deletion src/components/KitchenSink.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ function ListNodes() {

function LSPS(props: { initialSettings: MutinyWalletSettingStrings }) {
const i18n = useI18n();
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const [lspSettingsForm, { Form, Field }] =
createForm<MutinyWalletSettingStrings>({
validate: (values) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NWCEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export function NWCEditor(props: {
initialNWA?: string;
onSave: (indexToOpen?: number, nwcUriForCallback?: string) => Promise<void>;
}) {
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const i18n = useI18n();

const nwa = createMemo(() => parseNWA(props.initialNWA));
Expand Down
2 changes: 0 additions & 2 deletions src/logic/mutinyWalletSetup.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Remote } from "comlink";

export type Network = "bitcoin" | "testnet" | "regtest" | "signet";

export type MutinyWalletSettingStrings = {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ function FixedChatHeader(props: {
sendToContact: (contact: TagItem) => void;
requestFromContact: (contact: TagItem) => void;
}) {
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const navigate = useNavigate();

async function saveContact(id: string, contact: ContactFormValues) {
Expand Down
2 changes: 1 addition & 1 deletion src/routes/EditProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createAsync, useNavigate } from "@solidjs/router";
import { createMemo, createSignal, Show } from "solid-js";
import { createSignal, Show } from "solid-js";

import {
BackLink,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function Profile() {
</ButtonCard>
</Show>
</Show>
<Show when={profile() && profile().deleted}>
<Show when={profile() && profile()?.deleted}>
<ButtonCard
onClick={() => navigate("/settings/importprofile")}
>
Expand Down
4 changes: 2 additions & 2 deletions src/routes/Request.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { eify } from "~/utils";
import { DestinationItem } from "./Send";

export function RequestRoute() {
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const navigate = useNavigate();
const i18n = useI18n();

Expand Down Expand Up @@ -103,7 +103,7 @@ export function RequestRoute() {
setAmountSats={setAmount}
onSubmit={handleSubmit}
/>
<ReceiveWarnings amountSats={amount() || "0"} />
<ReceiveWarnings amountSats={amount() || 0n} />
</VStack>
<div class="flex-1" />
<VStack>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/Connections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ function NwcDetails(props: {

function Nwc() {
const i18n = useI18n();
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();

async function fetchNwcProfiles() {
try {
Expand Down
4 changes: 2 additions & 2 deletions src/routes/settings/Encrypt.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type EncryptPasswordForm = {

export function Encrypt() {
const i18n = useI18n();
const [store, _actions] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const [error, setError] = createSignal<Error>();
const [loading, setLoading] = createSignal(false);

Expand Down Expand Up @@ -56,7 +56,7 @@ export function Encrypt() {
const handleFormSubmit = async (f: EncryptPasswordForm) => {
setLoading(true);
try {
await store.mutiny_wallet?.change_password(
await sw.change_password(
f.existingPassword === "" ? undefined : f.existingPassword,
f.password === "" ? undefined : f.password
);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/setup/NewProfile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { useMegaStore } from "~/state/megaStore";
import { DEFAULT_NOSTR_NAME } from "~/utils";

export function NewProfile() {
const [state, _actions, sw] = useMegaStore();
const [_state, _actions, sw] = useMegaStore();
const i18n = useI18n();

const [creating, setCreating] = createSignal(false);
Expand Down
50 changes: 20 additions & 30 deletions src/workers/sharedWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ export async function list_federations(): Promise<MutinyFederationIdentity[]> {

export async function check_subscribed(): Promise<bigint | undefined> {
const subscribed = await wallet!.check_subscribed();
console.log("check_subscribed", subscribed);
return subscribed;
}

Expand All @@ -244,14 +243,12 @@ export async function delete_all(): Promise<void> {
await wallet!.delete_all();
}

export async function get_bitcoin_price(
fiat: string
): Promise<number | undefined> {
export async function get_bitcoin_price(fiat: string): Promise<number> {
const price = await wallet!.get_bitcoin_price(fiat);
return price;
}

export async function get_tag_items(): Promise<TagItem[] | undefined> {
export async function get_tag_items(): Promise<TagItem[]> {
const tagItems = await wallet!.get_tag_items();
return tagItems;
}
Expand All @@ -269,7 +266,7 @@ export async function get_nostr_profile(): Promise<NostrMetadata> {
export async function get_activity(
limit: number,
offset?: number
): Promise<unknown[] | undefined> {
): Promise<unknown[]> {
const activity = await wallet!.get_activity(limit, offset);
return activity;
}
Expand All @@ -287,7 +284,7 @@ export async function create_new_contact(
ln_address?: string,
lnurl?: string,
image_url?: string
): Promise<string | undefined> {
): Promise<string> {
const contactId = await wallet!.create_new_contact(
name,
npub,
Expand All @@ -299,14 +296,11 @@ export async function create_new_contact(
}

export async function get_tag_item(id: string): Promise<TagItem | undefined> {
console.log("get_tag_item", id);
const tagItem = await wallet!.get_tag_item(id);
return { ...tagItem?.value };
}

export async function get_label_activity(
id: string
): Promise<IActivityItem[] | undefined> {
export async function get_label_activity(id: string): Promise<IActivityItem[]> {
const activity = await wallet!.get_label_activity(id);
return activity;
}
Expand Down Expand Up @@ -500,17 +494,15 @@ export async function keysend(

export async function get_invoice_by_hash(
hash: string
): Promise<MutinyInvoice | undefined> {
): Promise<MutinyInvoice> {
const invoice = await wallet!.get_invoice_by_hash(hash);
if (!invoice) return undefined;
return destructureInvoice(invoice);
}

export async function get_channel_closure(
user_channel_id: string
): Promise<ChannelClosure | undefined> {
): Promise<ChannelClosure> {
const channel_closure = await wallet!.get_channel_closure(user_channel_id);
if (!channel_closure) return undefined;
return {
channel_id: channel_closure.channel_id,
node_id: channel_closure.node_id,
Expand All @@ -520,29 +512,22 @@ export async function get_channel_closure(
}

// TODO: this is an ActivityItem right?
export async function get_transaction(
txid: string
): Promise<ActivityItem | undefined> {
export async function get_transaction(txid: string): Promise<ActivityItem> {
const transaction = await wallet!.get_transaction(txid);
if (!transaction) return undefined;
return transaction as ActivityItem;
}

export async function get_new_address(
labels: string[]
): Promise<MutinyBip21RawMaterials | undefined> {
): Promise<MutinyBip21RawMaterials> {
const mbrw = await wallet!.get_new_address(labels);
if (!mbrw) return undefined;
return {
...mbrw?.value
} as MutinyBip21RawMaterials;
}

export async function check_address(
address: string
): Promise<OnChainTx | undefined> {
export async function check_address(address: string): Promise<OnChainTx> {
const tx = await wallet!.check_address(address);
if (!tx) return undefined;
return tx as OnChainTx;
}

Expand Down Expand Up @@ -575,7 +560,7 @@ export async function discover_federations(): Promise<

export async function has_recommended_federation(
federation_id: string
): Promise<boolean | undefined> {
): Promise<boolean> {
const hasRecommended =
await wallet!.has_recommended_federation(federation_id);
return hasRecommended;
Expand All @@ -600,7 +585,7 @@ export async function edit_nostr_profile(
img_url?: string,
lnurl?: string,
nip05?: string
): Promise<NostrMetadata | undefined> {
): Promise<NostrMetadata> {
const profile = await wallet!.edit_nostr_profile(
name,
img_url,
Expand All @@ -612,9 +597,7 @@ export async function edit_nostr_profile(
};
}

export async function upload_profile_pic(
data: string
): Promise<string | undefined> {
export async function upload_profile_pic(data: string): Promise<string> {
const url = await wallet!.upload_profile_pic(data);
return url;
}
Expand Down Expand Up @@ -899,3 +882,10 @@ export async function get_federation_balances(): Promise<FederationBalances> {
balances: newBalances
} as FederationBalances;
}

export async function change_password(
old_password?: string,
new_password?: string
): Promise<void> {
await wallet!.change_password(old_password, new_password);
}

0 comments on commit 75fa2b9

Please sign in to comment.