Skip to content

Commit 488618d

Browse files
committed
[squash] fix build
1 parent 4c0d9ac commit 488618d

7 files changed

Lines changed: 67 additions & 51 deletions

File tree

turnkey/src/features/balances/use-balances.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use client";
12
import { skipToken, useQuery } from "@tanstack/react-query";
23
import { useOneBalanceAccountAddress } from "../onebalance-account/use-onebalance-account";
34
import { fetchBalances, fetchBTCBalance } from "./fetch-balances";

turnkey/src/features/onebalance-account/create-btc-wallet-ui.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
"use client";
2-
import { useState } from "react";
2+
import { useTurnkey } from "@turnkey/sdk-react";
33
import { useTurnkeyAuth } from "../turnkey/use-turnkey-auth";
44
import { useBTCAccount } from "./use-btc-account";
5-
import { useTurnkey } from "@turnkey/sdk-react";
5+
import { useRecoverBTCWallet } from "../turnkey/use-recover-btc-wallet";
66

77
export const BTCWalletUI = () => {
88
const { passkeyClient } = useTurnkey();
@@ -65,7 +65,7 @@ export const CreateBTCWalletUI = ({
6565
onSubmit: () => void;
6666
rootOrgId: string;
6767
}) => {
68-
const { btcLogin } = useTurnkeyAuth();
68+
const { btcLogin } = useRecoverBTCWallet();
6969

7070
return (
7171
<div className="p-5 text-left w-1/2 border border-surface-level-2 rounded-r-xl flex flex-col gap-2">

turnkey/src/features/onebalance-account/use-btc-account.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
1+
"use client";
12
import { skipToken, useMutation, useQuery } from "@tanstack/react-query";
23
import { useLocalStorage } from "@uidotdev/usehooks";
34
import { createBTCWallet } from "./create-btc-wallet";
45
import { fetchBTCWalletAddress } from "./fetch-btc-wallet-address";
56
import { useEnvironment } from "../environment/environment";
6-
7-
export const usePersistedBTCWallet = () => {
8-
// persisting these values in local storage is not advisable.
9-
// they should be persisted in a database against your user.
10-
// this integration example uses local storage to simulate
11-
// database persistance. Please exercise caution if copying this example
12-
const [value, setValue] = useLocalStorage<
13-
{ walletId: string; organizationId: string } | "null"
14-
>("btc-wallet", "null");
15-
16-
if (value === "null" || !value || Object.keys(value).length === 0)
17-
return [null, setValue] as const;
18-
19-
return [value, setValue] as const;
20-
};
7+
import { usePersistedBTCWallet } from "./use-persisted-btc-wallet";
218

229
const useCreateBTCAccount = ({
2310
onSuccess,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
"use client";
2+
import { useLocalStorage } from "@uidotdev/usehooks";
3+
4+
export const usePersistedBTCWallet = () => {
5+
// persisting these values in local storage is not advisable.
6+
// they should be persisted in a database against your user.
7+
// this integration example uses local storage to simulate
8+
// database persistance. Please exercise caution if copying this example
9+
const [value, setValue] = useLocalStorage<
10+
{ walletId: string; organizationId: string } | "null"
11+
>("btc-wallet", "null");
12+
13+
if (value === "null" || !value || Object.keys(value).length === 0)
14+
return [null, setValue] as const;
15+
16+
return [value, setValue] as const;
17+
};

turnkey/src/features/swap/use-swap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use client";
12
import { useMutation, useQuery } from "@tanstack/react-query";
23
import { useTurnkey } from "@turnkey/sdk-react";
34
import { FormEvent } from "react";
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"use client";
2+
import { useMutation } from "@tanstack/react-query";
3+
import { useTurnkey } from "@turnkey/sdk-react";
4+
import { usePersistedBTCWallet } from "../onebalance-account/use-persisted-btc-wallet";
5+
6+
export const useRecoverBTCWallet = () => {
7+
const { turnkey } = useTurnkey();
8+
const [, setBTCWallet] = usePersistedBTCWallet();
9+
10+
const { mutate: btcLogin } = useMutation({
11+
mutationFn: async ({ rootOrgId }: { rootOrgId: string }) => {
12+
return turnkey
13+
?.passkeyClient()
14+
.getWhoami({
15+
organizationId: rootOrgId,
16+
})
17+
.then((result) => {
18+
return turnkey
19+
?.passkeyClient()
20+
.getWallets({
21+
organizationId: result.organizationId,
22+
})
23+
.then((wallets) => {
24+
return [wallets, result] as const;
25+
});
26+
})
27+
.then(([{ wallets }, { organizationId }]) => {
28+
if (!wallets[0].walletName.toLowerCase().includes("btc wallet"))
29+
return;
30+
31+
setBTCWallet({
32+
walletId: wallets[0].walletId,
33+
organizationId,
34+
});
35+
});
36+
},
37+
});
38+
39+
return {
40+
btcLogin,
41+
};
42+
};

turnkey/src/features/turnkey/use-turnkey-auth.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1+
"use client";
12
import { useMutation, useQuery } from "@tanstack/react-query";
23
import { useTurnkey } from "@turnkey/sdk-react";
34
import { queryClient } from "../react-query";
4-
import { useEnvironment } from "../environment/environment";
5-
import { usePersistedBTCWallet } from "../onebalance-account/use-btc-account";
65

76
type TurnkeyBrowserSDK = NonNullable<ReturnType<typeof useTurnkey>["turnkey"]>;
87
export type TurnkeyPasskeyClient = NonNullable<
@@ -20,7 +19,6 @@ export const useTurnkeyAuth = () => {
2019
refetch();
2120
},
2221
});
23-
const [, setBTCWallet] = usePersistedBTCWallet();
2422

2523
const {
2624
data: user,
@@ -45,35 +43,6 @@ export const useTurnkeyAuth = () => {
4543
},
4644
});
4745

48-
const { mutate: btcLogin } = useMutation({
49-
mutationFn: async ({ rootOrgId }: { rootOrgId: string }) => {
50-
return turnkey
51-
?.passkeyClient()
52-
.getWhoami({
53-
organizationId: rootOrgId,
54-
})
55-
.then((result) => {
56-
return turnkey
57-
?.passkeyClient()
58-
.getWallets({
59-
organizationId: result.organizationId,
60-
})
61-
.then((wallets) => {
62-
return [wallets, result] as const;
63-
});
64-
})
65-
.then(([{ wallets }, { organizationId }]) => {
66-
if (!wallets[0].walletName.toLowerCase().includes("btc wallet"))
67-
return;
68-
69-
setBTCWallet({
70-
walletId: wallets[0].walletId,
71-
organizationId,
72-
});
73-
});
74-
},
75-
});
76-
7746
const { data: wallets } = useQuery({
7847
queryKey: ["wallets"],
7948
queryFn: async () => {
@@ -102,6 +71,5 @@ export const useTurnkeyAuth = () => {
10271
isLoginPending,
10372
isUserLoading,
10473
refreshAuthStatus: refetch,
105-
btcLogin,
10674
};
10775
};

0 commit comments

Comments
 (0)