Skip to content

Commit b2fc396

Browse files
authored
Merge pull request #957 from tkhq/ethan/sessionless-stamping-v2
fixed export and handleAddOauth for sessionless stamping
2 parents 899e0b0 + f648b96 commit b2fc396

File tree

4 files changed

+168
-143
lines changed

4 files changed

+168
-143
lines changed

examples/with-sdk-js/src/app/page.tsx

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,23 +1904,13 @@ export default function AuthPage() {
19041904
<button
19051905
onClick={async () => {
19061906
try {
1907-
console.log(
1908-
"Fetching wallets for organizationId and userId",
1909-
organizationId,
1910-
userId,
1911-
);
1912-
await turnkey.refreshWallets({
1913-
organizationId: organizationId,
1914-
userId: userId,
1915-
stampWith: StamperType.Passkey,
1916-
});
1917-
await turnkey.refreshUser({
1918-
organizationId: organizationId,
1919-
userId: userId,
1920-
stampWith: StamperType.Passkey,
1921-
});
1907+
await turnkey.loginWithPasskey();
1908+
await turnkey.refreshWallets();
1909+
await turnkey.refreshUser();
19221910
} catch (e) {
19231911
console.error(e);
1912+
} finally {
1913+
await turnkey.clearSession();
19241914
}
19251915
}}
19261916
style={{

packages/react-wallet-kit/src/components/export/Export.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export function ExportComponent(params: {
3333
keyFormat?: KeyFormat | undefined;
3434
stampWith?: StamperType | undefined;
3535
organizationId?: string;
36+
onSuccess: () => void;
37+
onError: (error: any) => void;
3638
}) {
3739
const {
3840
exportType,
@@ -41,6 +43,8 @@ export function ExportComponent(params: {
4143
stampWith,
4244
target,
4345
organizationId,
46+
onSuccess,
47+
onError,
4448
} = params;
4549
const { config } = useTurnkey();
4650

@@ -92,10 +96,12 @@ export function ExportComponent(params: {
9296
});
9397
setExportIframeClient(newExportIframeClient);
9498
} catch (error) {
95-
throw new TurnkeyError(
96-
`Error initializing IframeStamper`,
97-
TurnkeyErrorCodes.INITIALIZE_IFRAME_ERROR,
98-
error,
99+
onError(
100+
new TurnkeyError(
101+
`Error initializing IframeStamper`,
102+
TurnkeyErrorCodes.INITIALIZE_IFRAME_ERROR,
103+
error,
104+
),
99105
);
100106
}
101107
};
@@ -159,6 +165,7 @@ export function ExportComponent(params: {
159165
stampWith={stampWith}
160166
setExportIframeVisible={setExportIframeVisible}
161167
organizationId={organizationId}
168+
onError={onError}
162169
/>
163170
)}
164171
<div
@@ -209,7 +216,10 @@ export function ExportComponent(params: {
209216
<div className="mt-4">
210217
<ActionButton
211218
name="export-done"
212-
onClick={closeModal}
219+
onClick={() => {
220+
closeModal();
221+
onSuccess();
222+
}}
213223
spinnerClassName="text-primary-text-light dark:text-primary-text-dark"
214224
className="text-primary-text-light dark:text-primary-text-dark bg-primary-light dark:bg-primary-dark"
215225
>

packages/react-wallet-kit/src/components/export/ExportWarning.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function ExportWarning(props: {
2828
setExportIframeVisible?: (visible: boolean) => void;
2929
stampWith?: StamperType | undefined;
3030
organizationId?: string | undefined;
31+
onError: (error: any) => void;
3132
}) {
3233
const {
3334
target,
@@ -36,6 +37,7 @@ export function ExportWarning(props: {
3637
exportType,
3738
keyFormat,
3839
stampWith,
40+
onError,
3941
} = props;
4042

4143
const [isLoading, setIsLoading] = useState(false);
@@ -99,9 +101,11 @@ export function ExportWarning(props: {
99101
organizationId,
100102
});
101103
if (!exportBundle) {
102-
throw new TurnkeyError(
103-
"Failed to retrieve export bundle",
104-
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
104+
onError(
105+
new TurnkeyError(
106+
"Failed to retrieve export bundle",
107+
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
108+
),
105109
);
106110
}
107111
await exportIframeClient?.injectWalletExportBundle(
@@ -118,9 +122,11 @@ export function ExportWarning(props: {
118122
organizationId,
119123
});
120124
if (!exportBundle) {
121-
throw new TurnkeyError(
122-
"Failed to retrieve export bundle",
123-
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
125+
onError(
126+
new TurnkeyError(
127+
"Failed to retrieve export bundle",
128+
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
129+
),
124130
);
125131
}
126132
await exportIframeClient?.injectKeyExportBundle(
@@ -138,9 +144,11 @@ export function ExportWarning(props: {
138144
organizationId,
139145
});
140146
if (!exportBundle) {
141-
throw new TurnkeyError(
142-
"Failed to retrieve export bundle",
143-
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
147+
onError(
148+
new TurnkeyError(
149+
"Failed to retrieve export bundle",
150+
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
151+
),
144152
);
145153
}
146154
await exportIframeClient?.injectKeyExportBundle(
@@ -159,10 +167,12 @@ export function ExportWarning(props: {
159167
props.setExportIframeVisible(true);
160168
}
161169
} catch (error) {
162-
throw new TurnkeyError(
163-
`Error exporting wallet`,
164-
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
165-
error,
170+
onError(
171+
new TurnkeyError(
172+
`Error exporting wallet`,
173+
TurnkeyErrorCodes.EXPORT_WALLET_ERROR,
174+
error,
175+
),
166176
);
167177
} finally {
168178
setIsLoading(false);

0 commit comments

Comments
 (0)