Skip to content

Commit

Permalink
Don't throw error when no client (#811)
Browse files Browse the repository at this point in the history
  • Loading branch information
rygine authored Feb 1, 2025
1 parent 5af4ed8 commit fd43af4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
7 changes: 3 additions & 4 deletions apps/xmtp.chat/src/hooks/useConversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
SafeListMessagesOptions,
} from "@xmtp/browser-sdk";
import { useState } from "react";
import { ClientNotFoundError } from "../helpers/errors";
import { useClient } from "./useClient";

export const useConversation = (conversation?: Conversation) => {
Expand All @@ -19,7 +18,7 @@ export const useConversation = (conversation?: Conversation) => {
syncFromNetwork: boolean = false,
) => {
if (!client) {
throw new ClientNotFoundError("fetching messages");
return;
}

if (syncFromNetwork) {
Expand All @@ -39,7 +38,7 @@ export const useConversation = (conversation?: Conversation) => {

const sync = async () => {
if (!client) {
throw new ClientNotFoundError("syncing messages");
return;
}

setSyncing(true);
Expand All @@ -53,7 +52,7 @@ export const useConversation = (conversation?: Conversation) => {

const send = async (message: string) => {
if (!client) {
throw new ClientNotFoundError("sending message");
return;
}

setSending(true);
Expand Down
13 changes: 6 additions & 7 deletions apps/xmtp.chat/src/hooks/useConversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type {
SafeListConversationsOptions,
} from "@xmtp/browser-sdk";
import { useState } from "react";
import { ClientNotFoundError } from "../helpers/errors";
import { useClient } from "./useClient";

export const useConversations = () => {
Expand All @@ -16,7 +15,7 @@ export const useConversations = () => {
syncFromNetwork: boolean = false,
) => {
if (!client) {
throw new ClientNotFoundError("fetching conversations");
return;
}

if (syncFromNetwork) {
Expand All @@ -35,7 +34,7 @@ export const useConversations = () => {

const sync = async () => {
if (!client) {
throw new ClientNotFoundError("syncing conversations");
return;
}

setSyncing(true);
Expand All @@ -49,7 +48,7 @@ export const useConversations = () => {

const getConversationById = async (conversationId: string) => {
if (!client) {
throw new ClientNotFoundError("fetching a conversation by ID");
return;
}

setLoading(true);
Expand All @@ -65,7 +64,7 @@ export const useConversations = () => {

const getMessageById = async (messageId: string) => {
if (!client) {
throw new ClientNotFoundError("fetching a message by ID");
return;
}

setLoading(true);
Expand All @@ -83,7 +82,7 @@ export const useConversations = () => {
options: SafeCreateGroupOptions,
) => {
if (!client) {
throw new ClientNotFoundError("creating a new group");
return;
}

setLoading(true);
Expand All @@ -101,7 +100,7 @@ export const useConversations = () => {

const newDm = async (member: string) => {
if (!client) {
throw new ClientNotFoundError("creating a new DM");
return;
}

setLoading(true);
Expand Down
7 changes: 3 additions & 4 deletions apps/xmtp.chat/src/hooks/useIdentity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { SafeInstallation } from "@xmtp/browser-sdk";
import { useEffect, useState } from "react";
import { ClientNotFoundError } from "../helpers/errors";
import { useClient } from "./useClient";

export const useIdentity = (syncOnMount: boolean = false) => {
Expand All @@ -20,7 +19,7 @@ export const useIdentity = (syncOnMount: boolean = false) => {

const sync = async () => {
if (!client) {
throw new ClientNotFoundError("syncing");
return;
}

setSyncing(true);
Expand All @@ -41,7 +40,7 @@ export const useIdentity = (syncOnMount: boolean = false) => {

const revokeInstallation = async (installationIdBytes: Uint8Array) => {
if (!client) {
throw new ClientNotFoundError("revoking an installation");
return;
}

setRevoking(true);
Expand All @@ -55,7 +54,7 @@ export const useIdentity = (syncOnMount: boolean = false) => {

const revokeAllOtherInstallations = async () => {
if (!client) {
throw new ClientNotFoundError("revoking all other installations");
return;
}

setRevoking(true);
Expand Down

0 comments on commit fd43af4

Please sign in to comment.