Skip to content

Commit 58afb9b

Browse files
committed
feat: track siwe
1 parent 0497242 commit 58afb9b

File tree

13 files changed

+220
-237
lines changed

13 files changed

+220
-237
lines changed
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
import type { Ecosystem } from "src/wallets/in-app/core/wallet/types.js";
1+
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";
22
import type { ThirdwebClient } from "../../client/client.js";
33
import { track } from "./index.js";
44

55
/**
66
* @internal
77
*/
88
export async function trackConnect(args: {
9-
client: ThirdwebClient;
10-
ecosystem?: Ecosystem;
11-
walletType: string;
12-
walletAddress: string;
9+
client: ThirdwebClient;
10+
ecosystem?: Ecosystem;
11+
walletType: string;
12+
walletAddress: string;
1313
}) {
14-
const { client, ecosystem, walletType, walletAddress } = args;
15-
return track({
16-
client,
17-
ecosystem,
18-
data: {
19-
source: "connectWallet",
20-
action: "connect",
21-
walletType,
22-
walletAddress,
23-
},
24-
});
14+
const { client, ecosystem, walletType, walletAddress } = args;
15+
return track({
16+
client,
17+
ecosystem,
18+
data: {
19+
source: "connectWallet",
20+
action: "connect",
21+
walletType,
22+
walletAddress,
23+
},
24+
});
2525
}
Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Ecosystem } from "src/wallets/in-app/core/wallet/types.js";
1+
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";
22
import type { ThirdwebClient } from "../../client/client.js";
33
import { getClientFetch } from "../../utils/fetch.js";
44
import { stringify } from "../../utils/json.js";
@@ -9,22 +9,22 @@ const ANALYTICS_ENDPOINT = "https://c.thirdweb.com/event";
99
* @internal
1010
*/
1111
export async function track({
12-
client,
13-
ecosystem,
14-
data,
12+
client,
13+
ecosystem,
14+
data,
1515
}: {
16-
client: ThirdwebClient;
17-
ecosystem?: Ecosystem;
18-
data: object;
16+
client: ThirdwebClient;
17+
ecosystem?: Ecosystem;
18+
data: object;
1919
}) {
20-
const fetch = getClientFetch(client, ecosystem);
21-
const event = {
22-
source: "sdk",
23-
...data,
24-
};
20+
const fetch = getClientFetch(client, ecosystem);
21+
const event = {
22+
source: "sdk",
23+
...data,
24+
};
2525

26-
return fetch(ANALYTICS_ENDPOINT, {
27-
method: "POST",
28-
body: stringify(event),
29-
}).catch(() => { });
26+
return fetch(ANALYTICS_ENDPOINT, {
27+
method: "POST",
28+
body: stringify(event),
29+
}).catch(() => {});
3030
}
Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
import type { Ecosystem } from "src/wallets/in-app/core/wallet/types.js";
1+
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";
22
import type { ThirdwebClient } from "../../client/client.js";
33
import { track } from "./index.js";
44

55
/**
66
* @internal
77
*/
88
export async function trackPayEvent(args: {
9-
client: ThirdwebClient;
10-
ecosystem?: Ecosystem;
11-
event: string;
12-
walletAddress?: string;
13-
walletType?: string;
14-
fromToken?: string;
15-
fromAmount?: string;
16-
toToken?: string;
17-
toAmount?: string;
18-
chainId?: number;
19-
dstChainId?: number;
9+
client: ThirdwebClient;
10+
ecosystem?: Ecosystem;
11+
event: string;
12+
walletAddress?: string;
13+
walletType?: string;
14+
fromToken?: string;
15+
fromAmount?: string;
16+
toToken?: string;
17+
toAmount?: string;
18+
chainId?: number;
19+
dstChainId?: number;
2020
}) {
21-
return track({
22-
client: args.client,
23-
ecosystem: args.ecosystem,
24-
data: {
25-
source: "pay",
26-
action: args.event,
27-
clientId: args.client.clientId,
28-
chainId: args.chainId,
29-
walletAddress: args.walletAddress,
30-
walletType: args.walletType,
31-
tokenAddress: args.fromToken,
32-
amountWei: args.fromAmount,
33-
dstTokenAddress: args.toToken,
34-
dstChainId: args.chainId,
35-
},
36-
});
21+
return track({
22+
client: args.client,
23+
ecosystem: args.ecosystem,
24+
data: {
25+
source: "pay",
26+
action: args.event,
27+
clientId: args.client.clientId,
28+
chainId: args.chainId,
29+
walletAddress: args.walletAddress,
30+
walletType: args.walletType,
31+
tokenAddress: args.fromToken,
32+
amountWei: args.fromAmount,
33+
dstTokenAddress: args.toToken,
34+
dstChainId: args.chainId,
35+
},
36+
});
3737
}

packages/thirdweb/src/analytics/track/siwe.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ describe("SIWE tracking", () => {
5656
}),
5757
);
5858

59-
await trackLoginError({
59+
await trackLogin({
6060
client: mockClient,
6161
walletAddress: "0x1234567890123456789012345678901234567890",
6262
walletType: "metamask",

packages/thirdweb/src/analytics/track/siwe.ts

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Ecosystem } from "src/wallets/in-app/core/wallet/types.js";
1+
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";
22
import type { ThirdwebClient } from "../../client/client.js";
33
import { stringify } from "../../utils/json.js";
44
import { track } from "./index.js";
@@ -15,31 +15,10 @@ type SiweEvent = {
1515
};
1616
};
1717

18-
type SiweSuccessEvent = SiweEvent & {
19-
error?: undefined;
20-
};
21-
22-
/**
23-
* @internal
24-
*/
25-
export async function trackLogin(event: SiweSuccessEvent) {
26-
return trackSiweEvent({
27-
...event,
28-
action: "login:attempt",
29-
});
30-
}
31-
32-
type SiweErrorEvent = SiweEvent & {
33-
error: {
34-
message: string;
35-
code: string;
36-
};
37-
};
38-
3918
/**
4019
* @internal
4120
*/
42-
export async function trackLoginError(event: SiweErrorEvent) {
21+
export async function trackLogin(event: SiweEvent) {
4322
return trackSiweEvent({
4423
...event,
4524
action: "login:attempt",

packages/thirdweb/src/analytics/track/transaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Ecosystem } from "src/wallets/in-app/core/wallet/types.js";
1+
import type { Ecosystem } from "../../wallets/in-app/core/wallet/types.js";
22
import type { ThirdwebClient } from "../../client/client.js";
33
import { stringify } from "../../utils/json.js";
44
import type { WalletId } from "../../wallets/wallet-types.js";

packages/thirdweb/src/auth/auth.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ import { verifyLoginPayload } from "./core/verify-login-payload.js";
3434
* @auth
3535
*/
3636
export function createAuth(options: AuthOptions) {
37-
return {
38-
generatePayload: generateLoginPayload(options),
39-
verifyPayload: verifyLoginPayload(options),
40-
generateJWT: generateJWT(options),
41-
verifyJWT: verifyJWT(options),
42-
};
37+
return {
38+
generatePayload: generateLoginPayload(options),
39+
verifyPayload: verifyLoginPayload(options),
40+
generateJWT: generateJWT(options),
41+
verifyJWT: verifyJWT(options),
42+
};
4343
}

0 commit comments

Comments
 (0)