Skip to content

Commit

Permalink
fix some of ben's problems
Browse files Browse the repository at this point in the history
  • Loading branch information
futurepaul committed Feb 20, 2024
1 parent 041592a commit 40a3e79
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 111 deletions.
72 changes: 44 additions & 28 deletions src/components/Activity.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TagItem } from "@mutinywallet/mutiny-wasm";
import { cache, createAsync, revalidate, useNavigate } from "@solidjs/router";
import { Plus, Save, Search, Shuffle } from "lucide-solid";
import { Plus, Save, Search, Shuffle, Users } from "lucide-solid";
import { createEffect, createSignal, For, Match, Show, Switch } from "solid-js";

import { ActivityDetailsModal, ButtonCard, NiceP } from "~/components";
Expand Down Expand Up @@ -30,6 +30,8 @@ export function UnifiedActivityItem(props: {
item: IActivityItem;
onClick: (id: string, kind: HackActivityType) => void;
}) {
const navigate = useNavigate();

const click = () => {
props.onClick(
props.item.id,
Expand Down Expand Up @@ -115,33 +117,37 @@ export function UnifiedActivityItem(props: {
};

return (
<>
<button class="pt-3 first-of-type:pt-0" onClick={() => click()}>
<GenericItem
primaryAvatarUrl={primaryContact()?.image_url || ""}
icon={shouldShowShuffle() ? <Shuffle /> : undefined}
primaryName={
props.item.inbound
? primaryContact()?.name || "Unknown"
: "You"
}
genericAvatar={shouldShowGeneric()}
verb={verb()}
message={message()}
secondaryName={secondaryName()}
amount={
props.item.amount_sats
? BigInt(props.item.amount_sats || 0)
: undefined
}
date={timeAgo(props.item.last_updated)}
accent={props.item.inbound ? "green" : undefined}
visibility={
props.item.kind === "Lightning" ? "private" : undefined
}
/>
</button>
</>
<div class="pt-3 first-of-type:pt-0">
<GenericItem
primaryAvatarUrl={primaryContact()?.image_url || ""}
icon={shouldShowShuffle() ? <Shuffle /> : undefined}
primaryOnClick={() =>
primaryName() !== "You" && primaryContact()?.id
? navigate(`/chat/${primaryContact()?.id}`)
: undefined
}
amountOnClick={click}
primaryName={
props.item.inbound
? primaryContact()?.name || "Unknown"
: "You"
}
genericAvatar={shouldShowGeneric()}
verb={verb()}
message={message()}
secondaryName={secondaryName()}
amount={
props.item.amount_sats
? BigInt(props.item.amount_sats || 0)
: undefined
}
date={timeAgo(props.item.last_updated)}
accent={props.item.inbound ? "green" : undefined}
visibility={
props.item.kind === "Lightning" ? "private" : undefined
}
/>
</div>
);
}

Expand Down Expand Up @@ -199,6 +205,16 @@ export function CombinedActivity() {
</Show>
<Switch>
<Match when={activity().length === 0}>
<Show when={state.federations?.length === 0}>
<ButtonCard
onClick={() => navigate("/settings/federations")}
>
<div class="flex items-center gap-2">
<Users class="inline-block text-m-red" />
<NiceP>{i18n.t("home.federation")}</NiceP>
</div>
</ButtonCard>
</Show>
<ButtonCard onClick={() => navigate("/receive")}>
<div class="flex items-center gap-2">
<Plus class="inline-block text-m-red" />
Expand Down
8 changes: 6 additions & 2 deletions src/components/GenericItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function GenericItem(props: {
forceSecondary?: boolean;
link?: string;
primaryOnClick?: () => void;
amountOnClick?: () => void;
secondaryOnClick?: () => void;
approveAction?: () => void;
rejectAction?: () => void;
Expand Down Expand Up @@ -76,7 +77,10 @@ export function GenericItem(props: {
<div class="flex flex-wrap gap-1">
{/* AMOUNT */}
<Show when={props.amount}>
<div
<button
onClick={() =>
props.amountOnClick && props.amountOnClick()
}
class="flex items-center gap-1 rounded-full px-2 py-1 text-xs font-semibold text-white"
classList={{
"bg-m-grey-800": !props.accent,
Expand All @@ -86,7 +90,7 @@ export function GenericItem(props: {
{/* <img src={bolt} width={8} height={8} /> */}
<Zap class="w-3" fill="currentColor" />
{`${props.amount!.toLocaleString()} sats`}
</div>
</button>
</Show>
{/* FIAT AMOUNT */}
<Show when={props.showFiat}>
Expand Down
7 changes: 6 additions & 1 deletion src/i18n/en/translations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,18 @@ export default {
receive: "Receive your first sats",
find: "Find your friends on nostr",
backup: "Secure your funds!",
connection: "Create a wallet connection"
connection: "Create a wallet connection",
federation: "Join a federation"
},
profile: {
nostr_identity: "Nostr Identity",
add_lightning_address: "Add Lightning Address",
edit_profile: "Edit Profile"
},
chat: {
prompt: "This is a new conversation. Try asking for money!",
placeholder: "Message"
},
contacts: {
new: "new",
add_contact: "Add Contact",
Expand Down
107 changes: 77 additions & 30 deletions src/routes/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { TagItem } from "@mutinywallet/mutiny-wasm";
import { createAsync, useNavigate, useParams } from "@solidjs/router";
import { ArrowDownLeft, ArrowUpRight, Zap } from "lucide-solid";
import { ArrowDownLeft, ArrowUpRight, MessagesSquare, Zap } from "lucide-solid";
import {
createEffect,
createResource,
Expand All @@ -19,18 +19,21 @@ import {
AmountSats,
BackPop,
Button,
ButtonCard,
ContactButton,
ContactFormValues,
ContactViewer,
HackActivityType,
IActivityItem,
LoadingShimmer,
MutinyWalletGuard,
NiceP,
showToast,
SimpleInput,
UnifiedActivityItem
} from "~/components";
import { MiniFab } from "~/components/Fab";
import { useI18n } from "~/i18n/context";
import { ParsedParams, toParsedParams } from "~/logic/waila";
import { useMegaStore } from "~/state/megaStore";
import { eify, hexpubFromNpub, timeAgo } from "~/utils";
Expand Down Expand Up @@ -267,6 +270,8 @@ export function Chat() {
const [messageValue, setMessageValue] = createSignal("");
const [sending, setSending] = createSignal(false);

const i18n = useI18n();

const contact = createAsync(async () => {
try {
return state.mutiny_wallet?.get_tag_item(params.id);
Expand All @@ -283,20 +288,27 @@ export function Chat() {
if (!contact || !contact?.npub) return undefined;
if (!contact.npub) return [] as CombinedMessagesAndActivity[];
try {
const activity = await state.mutiny_wallet?.get_label_activity(
params.id
);
let acts = [] as IActivityItem[];
let dms = [] as FakeDirectMessage[];

console.log("activity", activity);
const convo = await state.mutiny_wallet?.get_dm_conversation(
contact.npub,
20n,
undefined,
undefined
);
try {
acts = (await state.mutiny_wallet?.get_label_activity(
params.id
)) as IActivityItem[];
} catch (e) {
console.error("error getting activity:", e);
}

const dms = convo as FakeDirectMessage[];
const acts = activity as IActivityItem[];
try {
dms = (await state.mutiny_wallet?.get_dm_conversation(
contact.npub,
20n,
undefined,
undefined
)) as FakeDirectMessage[];
} catch (e) {
console.error("error getting dms:", e);
}

// Combine both arrays into an array of CombinedMessagesAndActivity, then sort by date
const combined = [
Expand Down Expand Up @@ -339,13 +351,14 @@ export function Chat() {
const npub = contact()?.npub;
if (!npub) return;
setSending(true);
const rememberedValue = messageValue();
setMessageValue("");
try {
const dmResult = await state.mutiny_wallet?.send_dm(
npub,
messageValue()
rememberedValue
);
console.log("dmResult:", dmResult);
setMessageValue("");
refetch();
} catch (e) {
console.error("error sending dm:", e);
Expand Down Expand Up @@ -495,15 +508,40 @@ export function Chat() {
<Suspense>
<Show when={contact()}>
<Suspense fallback={<LoadingShimmer />}>
<Show when={convo.latest}>
{/* TODO: figure out how not to do typecasting here */}
<MessageList
convo={
convo.latest as CombinedMessagesAndActivity[]
<Switch>
<Match
when={
convo.latest &&
convo.latest.length > 0
}
contact={contact()!}
/>
</Show>
>
{/* TODO: figure out how not to do typecasting here */}
<MessageList
convo={
convo.latest as CombinedMessagesAndActivity[]
}
contact={contact()!}
/>
</Match>
<Match when={true}>
<ButtonCard
onClick={() =>
requestFromContact(
contact()
)
}
>
<div class="flex items-center gap-4 text-left">
<div class="flex-0">
<MessagesSquare class="inline-block text-m-red" />
</div>
<NiceP>
{i18n.t("chat.prompt")}
</NiceP>
</div>
</ButtonCard>
</Match>
</Switch>
</Suspense>
</Show>
</Suspense>
Expand All @@ -521,14 +559,23 @@ export function Chat() {
}
onRequest={() => requestFromContact(contact())}
/>
<SimpleInput
disabled={sending()}
value={messageValue()}
onInput={(e) => setMessageValue(e.currentTarget.value)}
placeholder="Message"
/>
<form
onSubmit={async (e) => {
e.preventDefault();
await sendMessage();
}}
>
<SimpleInput
disabled={sending()}
value={messageValue()}
onInput={(e) =>
setMessageValue(e.currentTarget.value)
}
placeholder={i18n.t("chat.placeholder")}
/>
</form>
<div>
<Show when={messageValue()}>
<Show when={messageValue() || sending()}>
<Button
layout="xs"
intent="blue"
Expand Down
2 changes: 1 addition & 1 deletion src/routes/settings/Backup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export function Backup() {
function wroteDownTheWords() {
setLoading(true);
actions.setHasBackedUp();
navigate("/settings/encrypt");
navigate("/");
setLoading(false);
}

Expand Down
Loading

0 comments on commit 40a3e79

Please sign in to comment.