Skip to content

Commit

Permalink
fix: react hook return value (#217)
Browse files Browse the repository at this point in the history
Also updates the initialization of the server
  • Loading branch information
Justkant authored Aug 23, 2023
1 parent 3765ad9 commit 96dd717
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/lemon-books-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ledgerhq/wallet-api-server": patch
---

fix: react hook return value
18 changes: 9 additions & 9 deletions packages/server/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ export function useWalletAPIServer({
permission: Permission;
}) {
const server = useRef<WalletAPIServer>();

useEffect(() => {
// I don't really like this but it comes from the doc
// https://react.dev/reference/react/useRef#avoiding-recreating-the-ref-contents
if (server.current === undefined) {
server.current = new WalletAPIServer(transport, config, logger);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}

useEffect(() => {
server?.current?.setConfig(config);
server.current?.setConfig(config);
}, [config]);

useEffect(() => {
server?.current?.setPermissions(permission);
server.current?.setPermissions(permission);
}, [permission]);

useEffect(() => {
server?.current?.setCurrencies(currencies);
server.current?.setCurrencies(currencies);
}, [currencies]);

useEffect(() => {
server?.current?.setAccounts(accounts);
server.current?.setAccounts(accounts);
}, [accounts]);

const onMessage = useCallback(
Expand All @@ -55,7 +55,7 @@ export function useWalletAPIServer({
);

return {
server,
server: server.current,
onMessage,
};
}

2 comments on commit 96dd717

@vercel
Copy link

@vercel vercel bot commented on 96dd717 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-api – ./apps/docs

wallet-api-ledgerhq.vercel.app
wallet-api-git-main-ledgerhq.vercel.app
wallet.api.live.ledger.com

@vercel
Copy link

@vercel vercel bot commented on 96dd717 Aug 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

wallet-api-wallet-api-tools – ./apps/wallet-api-tools

wallet-api-wallet-api-tools.vercel.app
wallet-api-wallet-api-tools-ledgerhq.vercel.app
wallet-api-wallet-api-tools-git-main-ledgerhq.vercel.app

Please sign in to comment.