Skip to content

Commit

Permalink
Merged Release 3.0.0
Browse files Browse the repository at this point in the history
Updated Mutation Config
  • Loading branch information
alexrisch committed Dec 4, 2024
2 parents 71fc31d + 80637a7 commit b84d2c3
Show file tree
Hide file tree
Showing 31 changed files with 1,018 additions and 707 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { createStore, useStore } from "zustand";
type IConnectViaWalletStoreProps = {
address: string;
alreadyV3Db: boolean;
onXmtp: boolean;
signer: Signer;
};

Expand Down Expand Up @@ -43,7 +42,6 @@ const createConnectViaWalletStore = (props: IConnectViaWalletStoreProps) =>
createStore<IConnectViaWalletStoreState>()((set) => ({
address: props.address,
signer: props.signer,
onXmtp: props.onXmtp,
alreadyV3Db: props.alreadyV3Db,
loading: false,
numberOfSignaturesDone: 0,
Expand Down
22 changes: 4 additions & 18 deletions components/Onboarding/ConnectViaWallet/ConnectViaWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export const ConnectViaWallet = memo(function ConnectViaWallet(
// Wrapper to init the wallet state and then provide the data to the UI
const ConnectViaWalletStateWrapper = memo(
function ConnectViaWalletStateWrapper({ address }: { address: string }) {
const { isInitializing, alreadyV3Db, onXmtp, signer } =
const { isInitializing, alreadyV3Db, signer } =
useInitConnectViaWalletState({ address });

if (isInitializing) {
Expand All @@ -95,7 +95,6 @@ const ConnectViaWalletStateWrapper = memo(
<ConnectViaWalletStoreProvider
address={address}
alreadyV3Db={alreadyV3Db}
onXmtp={onXmtp}
signer={signer}
>
<ConnectViaWalletUI />
Expand All @@ -112,15 +111,13 @@ const ConnectViaWalletUI = memo(function ConnectViaWalletUI(props: object) {
loading,
waitingForNextSignature,
signer,
onXmtp,
alreadyV3Db,
signaturesDone,
} = useConnectViaWalletStoreContext((state) => ({
address: state.address,
loading: state.loading,
waitingForNextSignature: state.waitingForNextSignature,
signer: state.signer,
onXmtp: state.onXmtp,
alreadyV3Db: state.alreadyV3Db,
signaturesDone: state.numberOfSignaturesDone,
}));
Expand Down Expand Up @@ -156,23 +153,12 @@ const ConnectViaWalletUI = memo(function ConnectViaWalletUI(props: object) {
let showValueProps = true;

// On XMTP, needs V3 DB signature
if (onXmtp && !alreadyV3Db) {
title = `${translate("connectViaWallet.sign")} (${signaturesDone + 1}/2)`;
if (!alreadyV3Db) {
title = translate("connectViaWallet.sign");
subtitle = translate("connectViaWallet.firstSignature.explanation");
}
// On XMTP, has V3 DB signature
else if (onXmtp && alreadyV3Db) {
title = translate("connectViaWallet.firstSignature.title");
subtitle = translate("connectViaWallet.secondSignature.explanation");
}
// Waiting for second signature
else if (waitingForNextSignature && !loading) {
title = translate("connectViaWallet.secondSignature.title");
subtitle = translate("connectViaWallet.secondSignature.explanation");
showValueProps = false;
}
// Not on XMTP, needs first signature
else {
else if (alreadyV3Db) {
title = translate("connectViaWallet.firstSignature.title");
subtitle = translate("connectViaWallet.firstSignature.explanation");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ export function useInitXmptClient() {
try {
const signer = connectViewWalletStore.getState().signer!; // We can assume that signer is set at this point
const address = connectViewWalletStore.getState().address!; // We can assume that address is set at this point
const onXmtp = connectViewWalletStore.getState().onXmtp;
const alreadyV3Db = connectViewWalletStore.getState().alreadyV3Db;

const waitForClickSignature = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ import {
} from "thirdweb/react";

import { useConnectViaWalletContext } from "./ConnectViaWallet.context";
import { ensureError } from "../../../utils/error";
import { thirdwebClient } from "../../../utils/thirdweb";
import { getInboxId } from "../../../utils/xmtpRN/signIn";
import { canMessageByAccount } from "@utils/xmtpRN/contacts";
import { ensureError } from "@utils/error";
import { thirdwebClient } from "@utils/thirdweb";
import { getInboxId } from "@utils/xmtpRN/signIn";

/**
* For now let's keep Thirdweb and the hooks because I haven't found a better way to do it.
Expand All @@ -26,7 +25,6 @@ export function useInitConnectViaWalletState(args: { address: string }) {
const { onErrorConnecting } = useConnectViaWalletContext();

const [isInitializing, setIsInitializing] = useState(true);
const [onXmtp, setOnXmtp] = useState(false);
const [alreadyV3Db, setAlreadyV3Db] = useState(false);
const [signer, setSigner] = useState<Signer | undefined>();

Expand Down Expand Up @@ -84,22 +82,16 @@ export function useInitConnectViaWalletState(args: { address: string }) {

setIsInitializing(true);

const [isOnNetwork, inboxId] = await Promise.all([
canMessageByAccount({ account: address, peer: address }),
getInboxId(address),
]);
const inboxId = await getInboxId(address);

const v3Dbs = await getDatabaseFilesForInboxId(inboxId);
const hasV3 = v3Dbs.filter((n) => n.name.endsWith(".db3")).length > 0;

setOnXmtp(isOnNetwork);
setAlreadyV3Db(hasV3);
setSigner(thirdwebSigner);

logger.debug(
`[Connect Wallet] User connected wallet ${thirdwebWallet?.id} (${address}). ${
isOnNetwork ? "Already" : "Not yet"
} on XMTP. V3 database ${hasV3 ? "already" : "not"} present`
`[Connect Wallet] User connected wallet ${thirdwebWallet?.id} (${address}). V3 database ${hasV3 ? "already" : "not"} present`
);
} catch (error) {
logger.error("[Connect Wallet] Error initializing wallet:", error);
Expand All @@ -120,5 +112,5 @@ export function useInitConnectViaWalletState(args: { address: string }) {
onErrorConnecting,
]);

return { isInitializing, onXmtp, alreadyV3Db, signer };
return { isInitializing, alreadyV3Db, signer };
}
20 changes: 17 additions & 3 deletions design-system/Button/Button.example.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { VStack } from "@design-system/VStack";
import { useAppTheme } from "@theme/useAppTheme";
import { Button } from "./Button";
import { Icon } from "../Icon/Icon";

type IExampleProps = {
onPress?: () => void;
Expand Down Expand Up @@ -36,14 +37,27 @@ export function ButtonExample(args: IExampleProps) {
<Button text="Button with Icon" icon="search" onPress={onPress} />

{/* Custom Accessories */}
{/* <Button
<Button
size="sm"
text="Custom Left Accessory"
LeftAccessory={({ style }) => (
<Icon icon="chevron.left" color="white" style={style} />
<Icon
icon="chevron.left"
size={theme.iconSize.md}
color={theme.colors.global.primary}
style={style}
/>
)}
RightAccessory={({ style }) => (
<Icon
icon="chevron.right"
size={theme.iconSize.md}
color={theme.colors.global.primary}
style={style}
/>
)}
onPress={onPress}
/> */}
/>

{/* i18n Example */}
{/* <Button tx="cancel" txOptions={{ name: "John" }} onPress={onPress} /> */}
Expand Down
31 changes: 25 additions & 6 deletions design-system/Examples.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import { TextFieldExample } from "@design-system/TextField/TextField.example";
import { VStack } from "@design-system/VStack";
import { useAppTheme } from "@theme/useAppTheme";
import { useState } from "react";
import { Switch, useColorScheme } from "react-native";
import { Text } from "@design-system/Text/Text";
import { HStack } from "./HStack";
import { HeaderExample } from "./Header/Header.example";

type IDesignSystemComponent =
| "buttons"
Expand All @@ -22,7 +26,8 @@ type IDesignSystemComponent =
| "snackbar";

export function Examples() {
const { theme } = useAppTheme();
const { theme, toggleTheme, themeContext } = useAppTheme();
const colorScheme = useColorScheme();

const [selectedComponent, setSelectedComponent] =
useState<IDesignSystemComponent | null>(null);
Expand All @@ -36,6 +41,18 @@ export function Examples() {
paddingHorizontal: theme.spacing.lg,
}}
>
<VStack style={{ gap: theme.spacing.xl }}>
<HStack
style={{
alignItems: "center",
justifyContent: "space-between",
paddingVertical: theme.spacing.sm,
}}
>
<Text preset="body">Toggle Dark Mode</Text>
<Switch value={themeContext === "dark"} onValueChange={toggleTheme} />
</HStack>
</VStack>
{selectedComponent ? (
<VStack style={{ gap: theme.spacing.lg }}>
<Button
Expand All @@ -50,7 +67,7 @@ export function Examples() {
{selectedComponent === "text-field" && <TextFieldExample />}
{selectedComponent === "icon" && <IconExample />}
{selectedComponent === "snackbar" && <SnackbarExample />}
{/* {selectedComponent === "header" && <HeaderExample />} */}
{selectedComponent === "header" && <HeaderExample />}
{selectedComponent === "bottom-sheet" && <BottomSheetExample />}
</VStack>
</VStack>
Expand All @@ -74,10 +91,12 @@ export function Examples() {
onPress={() => setSelectedComponent("text-field")}
/>
<Button text="Icon" onPress={() => setSelectedComponent("icon")} />
{/* <Button
text="Header"
onPress={() => setSelectedComponent("header")}
/> */}
{
<Button
text="Header"
onPress={() => setSelectedComponent("header")}
/>
}
<Button
text="Bottom Sheet"
onPress={() => setSelectedComponent("bottom-sheet")}
Expand Down
94 changes: 94 additions & 0 deletions design-system/Header/Header.example.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import { VStack } from "@design-system/VStack";
import { ThemedStyle, useAppTheme } from "@theme/useAppTheme";
import { Header } from "./Header";
import { Icon } from "@design-system/Icon/Icon";
import { Text } from "@design-system/Text/Text";
import { TextStyle } from "react-native";

type IExampleProps = {
onPress?: () => void;
};

export function HeaderExample(args: IExampleProps) {
const { onPress } = args;

return (
<VStack>
{/* Basic Header */}
<Header
title="Basic Header"
onLeftPress={onPress}
onRightPress={onPress}
/>

{/* Header with title and left icon */}
<Header title="Header with Text" leftIcon="chevron.left" />

{/* Header with title and right icon */}
<Header title="Header with Text" rightIcon="chevron.right" />

{/* Header with left and right icons */}
<Header
title="Header with Icons"
leftIcon="chevron.left"
rightIcon="chevron.right"
onLeftPress={onPress}
onRightPress={onPress}
/>

{/* Header with custom title, left and right action components */}
<Header
titleComponent={<CustomTitle />}
LeftActionComponent={<CustomLeftAction />}
RightActionComponent={<CustomRightAction />}
onLeftPress={onPress}
onRightPress={onPress}
/>
</VStack>
);
}

function CustomTitle() {
const { themed } = useAppTheme();
return (
<Text style={themed($headerTextStyle)}>Custom Header Title Component</Text>
);
}

function CustomLeftAction() {
const { theme, themed } = useAppTheme();
return (
<Text
style={themed($sideTextStyle({ hasLeftText: true, hasRightText: false }))}
>
<Icon size={theme.iconSize.lg} icon="chevron.left" />
</Text>
);
}

function CustomRightAction() {
const { theme, themed } = useAppTheme();
return (
<Text
style={themed($sideTextStyle({ hasLeftText: false, hasRightText: true }))}
>
<Icon size={theme.iconSize.lg} icon="chevron.right" />
</Text>
);
}

const $headerTextStyle: ThemedStyle<TextStyle> = ({ colors }) => ({
fontWeight: "bold",
color: colors.text.primary,
});

const $sideTextStyle =
(props: {
hasLeftText: boolean;
hasRightText: boolean;
}): ThemedStyle<TextStyle> =>
({ spacing, colors }) => ({
color: colors.text.secondary,
marginTop: spacing.xxxs,
marginHorizontal: props.hasLeftText && props.hasRightText ? spacing.sm : 0,
});
Loading

0 comments on commit b84d2c3

Please sign in to comment.