Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add client prop to the react provider #423

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/three-numbers-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@ledgerhq/wallet-api-client-react": minor
---

feat: add client prop to the react provider

Allows to pass a user created client instead of creating it in the provider
10 changes: 4 additions & 6 deletions packages/client-react/src/components/WalletAPIProvider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function WalletAPIProvider({
logger,
getCustomModule,
eventHandlers,
client: providedClient,
}: WalletAPIProviderProps) {
const [state, setState] = useState<WalletAPIProviderContextState>(
initialContextValue.state,
Expand All @@ -23,12 +24,9 @@ export function WalletAPIProvider({
const client = useRef<WalletAPIClient>();

if (client.current === undefined) {
client.current = new WalletAPIClient(
transport,
logger,
getCustomModule,
eventHandlers,
);
client.current = providedClient
? providedClient
: new WalletAPIClient(transport, logger, getCustomModule, eventHandlers);
}

useEffect(() => {
Expand Down
22 changes: 16 additions & 6 deletions packages/client-react/src/components/WalletAPIProvider/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ export type Loadable<T> = {
value: T | null;
};

export type WalletAPIProviderProps = PropsWithChildren<{
transport: Transport;
logger?: Logger;
getCustomModule?: AnyCustomGetter;
eventHandlers?: EventHandlers;
}>;
export type WalletAPIProviderProps = PropsWithChildren<
| {
transport: Transport;
logger?: Logger;
getCustomModule?: AnyCustomGetter;
eventHandlers?: EventHandlers;
client?: never;
}
| {
transport?: never;
logger?: never;
getCustomModule?: never;
eventHandlers?: never;
client: WalletAPIClient;
}
>;

export type WalletAPIProviderContextState = {
accounts: Loadable<Account[]>;
Expand Down
Loading