Skip to content

Commit

Permalink
Merge cf94c83 into d67b353
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrisch authored Dec 4, 2024
2 parents d67b353 + cf94c83 commit 10f6515
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 40 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 };
}
5 changes: 0 additions & 5 deletions i18n/translations/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,6 @@ export const en = {
explanation:
"The secure inbox you own.\nConverse is built on XMTP, an open-source secure messaging protocol.",
},
secondSignature: {
title: "Allow Converse",
explanation:
"Converse needs your permission\nto send and receive messages.\nYou can revoke this anytime.",
},
valueProps: {
e2eEncryption: {
title: "End-to-end encrypted with MLS",
Expand Down

0 comments on commit 10f6515

Please sign in to comment.