Skip to content

Commit

Permalink
Always register codecs
Browse files Browse the repository at this point in the history
  • Loading branch information
nakajima committed Jun 20, 2023
1 parent 6e85b0a commit 13a2382
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
4 changes: 0 additions & 4 deletions src/contexts/ClientContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ export default function ClientProvider({
env: "dev",
});

client.enableGroupChat();
client.registerCodec(new AttachmentCodec());
client.registerCodec(new RemoteAttachmentCodec());

setClient(client);
setIsLoading(false);
})();
Expand Down
15 changes: 14 additions & 1 deletion src/hooks/useClient.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
import { useContext } from "react";
import { ClientContext } from "../contexts/ClientContext";
import { Client } from "@xmtp/xmtp-js";
import {
AttachmentCodec,
RemoteAttachmentCodec,
} from "xmtp-content-type-remote-attachment";

export function useClient() {
return useContext(ClientContext).client;
}

export function useSetClient() {
return useContext(ClientContext).setClient;
const setClient = useContext(ClientContext).setClient;

return (client: Client) => {
client.registerCodec(new AttachmentCodec());
client.registerCodec(new RemoteAttachmentCodec());
client.enableGroupChat();

setClient(client);
};
}
3 changes: 0 additions & 3 deletions src/views/LoginView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export default function LoginView(): ReactElement {
// Don't do this in real life.
localStorage.setItem("_insecurePrivateKey", wallet.privateKey);

client.enableGroupChat();
client.registerCodec(new AttachmentCodec());
client.registerCodec(new RemoteAttachmentCodec());
setClient(client);
}

Expand Down

0 comments on commit 13a2382

Please sign in to comment.