thirdweb 5.70.0 → 5.70.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/exports/utils.js +8 -1
- package/dist/cjs/exports/utils.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/screens/PrivateKey.js +43 -4
- package/dist/cjs/react/web/ui/ConnectWallet/screens/PrivateKey.js.map +1 -1
- package/dist/cjs/react/web/ui/prebuilt/Token/icon.js +1 -1
- package/dist/cjs/react/web/ui/prebuilt/Token/icon.js.map +1 -1
- package/dist/cjs/utils/abi/decodeError.js +32 -0
- package/dist/cjs/utils/abi/decodeError.js.map +1 -0
- package/dist/cjs/utils/abi/decodeFunctionData.js +32 -0
- package/dist/cjs/utils/abi/decodeFunctionData.js.map +1 -0
- package/dist/cjs/utils/abi/decodeFunctionResult.js +32 -0
- package/dist/cjs/utils/abi/decodeFunctionResult.js.map +1 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/exports/utils.js +4 -1
- package/dist/esm/exports/utils.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/screens/PrivateKey.js +45 -6
- package/dist/esm/react/web/ui/ConnectWallet/screens/PrivateKey.js.map +1 -1
- package/dist/esm/react/web/ui/prebuilt/Token/icon.js +1 -1
- package/dist/esm/react/web/ui/prebuilt/Token/icon.js.map +1 -1
- package/dist/esm/utils/abi/decodeError.js +29 -0
- package/dist/esm/utils/abi/decodeError.js.map +1 -0
- package/dist/esm/utils/abi/decodeFunctionData.js +29 -0
- package/dist/esm/utils/abi/decodeFunctionData.js.map +1 -0
- package/dist/esm/utils/abi/decodeFunctionResult.js +29 -0
- package/dist/esm/utils/abi/decodeFunctionResult.js.map +1 -0
- package/dist/esm/version.js +1 -1
- package/dist/types/exports/utils.d.ts +4 -1
- package/dist/types/exports/utils.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
- package/dist/types/react/web/ui/ConnectWallet/screens/PrivateKey.d.ts +2 -0
- package/dist/types/react/web/ui/ConnectWallet/screens/PrivateKey.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeError.d.ts +22 -0
- package/dist/types/utils/abi/decodeError.d.ts.map +1 -0
- package/dist/types/utils/abi/decodeFunctionData.d.ts +21 -0
- package/dist/types/utils/abi/decodeFunctionData.d.ts.map +1 -0
- package/dist/types/utils/abi/decodeFunctionResult.d.ts +21 -0
- package/dist/types/utils/abi/decodeFunctionResult.d.ts.map +1 -0
- package/dist/types/version.d.ts +1 -1
- package/package.json +1 -1
- package/src/event/actions/get-events.test.ts +2 -1
- package/src/exports/utils.ts +7 -1
- package/src/react/web/ui/ConnectWallet/Details.tsx +1 -0
- package/src/react/web/ui/ConnectWallet/screens/PrivateKey.tsx +61 -7
- package/src/react/web/ui/prebuilt/Token/icon.tsx +1 -1
- package/src/utils/abi/decodeError.ts +36 -0
- package/src/utils/abi/decodeFunctionData.ts +35 -0
- package/src/utils/abi/decodeFunctionResult.ts +35 -0
- package/src/version.ts +1 -1
@@ -1,13 +1,16 @@
|
|
1
1
|
"use client";
|
2
|
-
import { useState } from "react";
|
2
|
+
import { useEffect, useState } from "react";
|
3
3
|
import type { ThirdwebClient } from "../../../../../client/client.js";
|
4
|
-
import {
|
4
|
+
import { getThirdwebBaseUrl } from "../../../../../utils/domains.js";
|
5
|
+
import { webLocalStorage } from "../../../../../utils/storage/webStorage.js";
|
5
6
|
import { isEcosystemWallet } from "../../../../../wallets/ecosystem/is-ecosystem-wallet.js";
|
7
|
+
import { ClientScopedStorage } from "../../../../../wallets/in-app/core/authentication/client-scoped-storage.js";
|
6
8
|
import type { Wallet } from "../../../../../wallets/interfaces/wallet.js";
|
7
9
|
import type { Theme } from "../../../../core/design-system/index.js";
|
8
10
|
import { Spacer } from "../../components/Spacer.js";
|
9
11
|
import { Spinner } from "../../components/Spinner.js";
|
10
12
|
import { Container, Line, ModalHeader } from "../../components/basic.js";
|
13
|
+
import type { ConnectLocale } from "../locale/types.js";
|
11
14
|
|
12
15
|
/**
|
13
16
|
* @internal
|
@@ -17,13 +20,62 @@ export function PrivateKey(props: {
|
|
17
20
|
wallet?: Wallet;
|
18
21
|
theme: "light" | "dark" | Theme;
|
19
22
|
client: ThirdwebClient;
|
23
|
+
connectLocale: ConnectLocale;
|
20
24
|
}) {
|
21
25
|
const [isLoading, setLoading] = useState(true);
|
26
|
+
useEffect(() => {
|
27
|
+
const loginReady = async (e: MessageEvent<{ eventType: string }>) => {
|
28
|
+
if (
|
29
|
+
typeof e.data === "object" &&
|
30
|
+
"eventType" in e.data &&
|
31
|
+
e.origin === baseDomain
|
32
|
+
) {
|
33
|
+
if (e.data.eventType === "exportPrivateKeyIframeLoaded") {
|
34
|
+
const iframe = document.getElementById(
|
35
|
+
`export-wallet-${props.wallet?.id}`,
|
36
|
+
);
|
37
|
+
|
38
|
+
if (!(iframe instanceof HTMLIFrameElement)) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
if (!props.wallet) {
|
42
|
+
return;
|
43
|
+
}
|
44
|
+
|
45
|
+
const clientStorage = new ClientScopedStorage({
|
46
|
+
clientId: props.client.clientId,
|
47
|
+
storage: webLocalStorage,
|
48
|
+
ecosystem: isEcosystemWallet(props.wallet)
|
49
|
+
? {
|
50
|
+
id: props.wallet.id,
|
51
|
+
partnerId: props.wallet.getConfig()?.partnerId,
|
52
|
+
}
|
53
|
+
: undefined,
|
54
|
+
});
|
55
|
+
if (iframe?.contentWindow) {
|
56
|
+
iframe.contentWindow.postMessage(
|
57
|
+
{
|
58
|
+
eventType: "initExportPrivateKey",
|
59
|
+
authToken: await clientStorage.getAuthCookie(),
|
60
|
+
},
|
61
|
+
e.origin,
|
62
|
+
);
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
};
|
67
|
+
window.addEventListener("message", loginReady);
|
68
|
+
|
69
|
+
return () => {
|
70
|
+
window.removeEventListener("message", loginReady);
|
71
|
+
};
|
72
|
+
}, [props.wallet, props.client.clientId]);
|
73
|
+
|
22
74
|
if (!props.wallet) {
|
23
75
|
throw new Error("[PrivateKey] No wallet found");
|
24
76
|
}
|
25
77
|
|
26
|
-
const baseDomain =
|
78
|
+
const baseDomain = getThirdwebBaseUrl("inAppWallet");
|
27
79
|
const ecosystem = isEcosystemWallet(props.wallet)
|
28
80
|
? { id: props.wallet.id, partnerId: props.wallet.getConfig()?.partnerId }
|
29
81
|
: undefined;
|
@@ -35,7 +87,10 @@ export function PrivateKey(props: {
|
|
35
87
|
}}
|
36
88
|
>
|
37
89
|
<Container p="lg">
|
38
|
-
<ModalHeader
|
90
|
+
<ModalHeader
|
91
|
+
title={props.connectLocale.manageWallet.exportPrivateKey}
|
92
|
+
onBack={props.onBack}
|
93
|
+
/>
|
39
94
|
</Container>
|
40
95
|
<Line />
|
41
96
|
<Container
|
@@ -68,6 +123,7 @@ export function PrivateKey(props: {
|
|
68
123
|
}}
|
69
124
|
>
|
70
125
|
<iframe
|
126
|
+
id={`export-wallet-${props.wallet.id}`}
|
71
127
|
title="Export In-App Wallet"
|
72
128
|
style={{
|
73
129
|
width: "100%",
|
@@ -78,9 +134,7 @@ export function PrivateKey(props: {
|
|
78
134
|
setLoading(false);
|
79
135
|
}}
|
80
136
|
allow="clipboard-read; clipboard-write"
|
81
|
-
src={`${
|
82
|
-
baseDomain.includes("localhost") ? "http" : "https"
|
83
|
-
}://${baseDomain}/sdk/2022-08-12/embedded-wallet/export-private-key?clientId=${
|
137
|
+
src={`${baseDomain}/sdk/2022-08-12/embedded-wallet/export-private-key?clientId=${
|
84
138
|
props.client.clientId
|
85
139
|
}&theme=${
|
86
140
|
typeof props.theme === "string" ? props.theme : props.theme.type
|
@@ -0,0 +1,36 @@
|
|
1
|
+
import { type Abi, AbiError } from "ox";
|
2
|
+
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
|
3
|
+
import type { ThirdwebContract } from "../../contract/contract.js";
|
4
|
+
import type { Hex } from "../encoding/hex.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Decodes an error.
|
8
|
+
* @param options - The options object.
|
9
|
+
* @returns The decoded error.
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* import { decodeError } from "thirdweb/utils";
|
13
|
+
*
|
14
|
+
* const data = "0x...";
|
15
|
+
* const error = await decodeError({ contract, data });
|
16
|
+
* ```
|
17
|
+
*
|
18
|
+
* @utils
|
19
|
+
*/
|
20
|
+
export async function decodeError<abi extends Abi.Abi>(options: {
|
21
|
+
contract: ThirdwebContract<abi>;
|
22
|
+
data: Hex;
|
23
|
+
}) {
|
24
|
+
const { contract, data } = options;
|
25
|
+
let abi = contract?.abi;
|
26
|
+
if (contract && !abi) {
|
27
|
+
abi = await resolveContractAbi(contract).catch(() => undefined);
|
28
|
+
}
|
29
|
+
if (!abi) {
|
30
|
+
throw new Error(
|
31
|
+
`No ABI found for contract ${contract.address} on chain ${contract.chain.id}`,
|
32
|
+
);
|
33
|
+
}
|
34
|
+
const abiError = AbiError.fromAbi(abi, data) as AbiError.AbiError;
|
35
|
+
return AbiError.decode(abiError, data);
|
36
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { type Abi, AbiFunction, type Hex } from "ox";
|
2
|
+
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
|
3
|
+
import type { ThirdwebContract } from "../../contract/contract.js";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Decodes the data of a function call.
|
7
|
+
* @param options - The options object.
|
8
|
+
* @returns The decoded data.
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* import { decodeFunctionData } from "thirdweb/utils";
|
12
|
+
*
|
13
|
+
* const data = "0x...";
|
14
|
+
* const decodedData = await decodeFunctionData({ contract, data });
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* @utils
|
18
|
+
*/
|
19
|
+
export async function decodeFunctionData<abi extends Abi.Abi>(options: {
|
20
|
+
contract: ThirdwebContract<abi>;
|
21
|
+
data: Hex.Hex;
|
22
|
+
}) {
|
23
|
+
const { contract, data } = options;
|
24
|
+
let abi = contract?.abi;
|
25
|
+
if (contract && !abi) {
|
26
|
+
abi = await resolveContractAbi(contract).catch(() => undefined);
|
27
|
+
}
|
28
|
+
if (!abi) {
|
29
|
+
throw new Error(
|
30
|
+
`No ABI found for contract ${contract.address} on chain ${contract.chain.id}`,
|
31
|
+
);
|
32
|
+
}
|
33
|
+
const abiFunction = AbiFunction.fromAbi(abi, data);
|
34
|
+
return AbiFunction.decodeData(abiFunction, data);
|
35
|
+
}
|
@@ -0,0 +1,35 @@
|
|
1
|
+
import { type Abi, AbiFunction, type Hex } from "ox";
|
2
|
+
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
|
3
|
+
import type { ThirdwebContract } from "../../contract/contract.js";
|
4
|
+
|
5
|
+
/**
|
6
|
+
* Decodes the result of a function call.
|
7
|
+
* @param options - The options object.
|
8
|
+
* @returns The decoded result.
|
9
|
+
* @example
|
10
|
+
* ```ts
|
11
|
+
* import { decodeFunctionResult } from "thirdweb/utils";
|
12
|
+
*
|
13
|
+
* const data = "0x...";
|
14
|
+
* const result = await decodeFunctionResult({ contract, data });
|
15
|
+
* ```
|
16
|
+
*
|
17
|
+
* @utils
|
18
|
+
*/
|
19
|
+
export async function decodeFunctionResult<abi extends Abi.Abi>(options: {
|
20
|
+
contract: ThirdwebContract<abi>;
|
21
|
+
data: Hex.Hex;
|
22
|
+
}) {
|
23
|
+
const { contract, ...rest } = options;
|
24
|
+
let abi = contract?.abi;
|
25
|
+
if (contract && !abi) {
|
26
|
+
abi = await resolveContractAbi(contract).catch(() => undefined);
|
27
|
+
}
|
28
|
+
if (!abi) {
|
29
|
+
throw new Error(
|
30
|
+
`No ABI found for contract ${contract.address} on chain ${contract.chain.id}`,
|
31
|
+
);
|
32
|
+
}
|
33
|
+
const abiFunction = AbiFunction.fromAbi(abi, rest.data);
|
34
|
+
return AbiFunction.decodeResult(abiFunction, rest.data);
|
35
|
+
}
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.70.
|
1
|
+
export const version = "5.70.1";
|