Skip to content

Commit 0072b95

Browse files
Merge pull request #2184 from Web3Auth/feat/analytics
add analytics using Segment
2 parents fc64a1a + 256234c commit 0072b95

File tree

33 files changed

+1030
-214
lines changed

33 files changed

+1030
-214
lines changed

demo/vue-app-new/package-lock.json

Lines changed: 22 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

demo/vue-app-new/src/MainView.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import {
1212
walletServicesPlugin,
1313
type AccountAbstractionMultiChainConfig,
1414
type Web3AuthOptions,
15-
WALLET_CONNECTOR_TYPE,
16-
ModalConfig,
1715
} from "@web3auth/modal";
1816
1917
import { type Web3AuthContextConfig, Web3AuthProvider } from "@web3auth/modal/vue";

demo/vue-app-new/src/components/AppDashboard.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { ProviderConfig } from "@toruslabs/base-controllers";
2323
import { SUPPORTED_NETWORKS } from "@toruslabs/ethereum-controllers";
2424
import { computed, ref, watch } from "vue";
2525
import { NFT_CHECKOUT_CONTRACT_ID } from "../config";
26-
import { getPrivateKey, sendEth, signTransaction as signEthTransaction } from "../services/ethHandlers";
26+
import { getPrivateKey, sendEth, sendEthWithSmartAccount, signTransaction as signEthTransaction } from "../services/ethHandlers";
2727
import { getBalance as getSolBalance, getPrivateKey as getSolPrivateKey, signAllTransactions } from "../services/solHandlers";
2828
import { formDataStore } from "../store/form";
2929
import { SOLANA_SUPPORTED_NETWORKS } from "../utils/constants";
@@ -237,6 +237,14 @@ const onSignPersonalMsg = async () => {
237237
printToConsole("result", result);
238238
};
239239
240+
const isSmartAccount = computed(() => {
241+
return web3Auth.value?.accountAbstractionProvider?.smartAccount && web3Auth.value?.accountAbstractionProvider?.bundlerClient;
242+
});
243+
244+
const onSendAATx = async () => {
245+
await sendEthWithSmartAccount(web3Auth.value, printToConsole);
246+
};
247+
240248
// Solana
241249
const onGetSolPrivateKey = async () => {
242250
await getSolPrivateKey(provider.value as IProvider, printToConsole);
@@ -438,6 +446,7 @@ const onSwitchChainNamespace = async () => {
438446
{{ t("app.buttons.btnSwitchChainNamespace") }} to Solana
439447
</Button>
440448
<Button block size="xs" pill class="mb-2" @click="onSendEth">{{ t("app.buttons.btnSendEth") }}</Button>
449+
<Button v-if="isSmartAccount" block size="xs" pill class="mb-2" @click="onSendAATx">{{ t("app.buttons.btnSendAATx") }}</Button>
441450
<Button block size="xs" pill class="mb-2" @click="onSignEthTransaction">
442451
{{ t("app.buttons.btnSignTransaction") }}
443452
</Button>

demo/vue-app-new/src/services/ethHandlers.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { IProvider, log } from "@web3auth/modal";
1+
import { IProvider, log, type Web3Auth } from "@web3auth/modal";
22
import { verifyMessage as eipVerifyMessage } from "@web3auth/sign-in-with-ethereum";
33
import { EVM_METHOD_TYPES } from "@web3auth/ws-embed";
44
import { BrowserProvider, parseEther, Transaction } from "ethers";
@@ -24,6 +24,31 @@ export const sendEth = async (provider: IProvider, uiConsole: (name: string, val
2424
}
2525
};
2626

27+
export const sendEthWithSmartAccount = async (web3Auth: Web3Auth | null, uiConsole: (name: string, value: unknown) => void) => {
28+
const { smartAccount, bundlerClient } = web3Auth?.accountAbstractionProvider || {};
29+
if (!smartAccount || !bundlerClient) {
30+
throw new Error("Smart account or bundler client not found");
31+
}
32+
33+
try {
34+
const hash = await bundlerClient.sendUserOperation({
35+
account: smartAccount,
36+
calls: [
37+
{
38+
to: smartAccount.address,
39+
value: parseEther("0.00001"),
40+
},
41+
],
42+
});
43+
44+
const { success, userOpHash, reason, receipt } = await bundlerClient.waitForUserOperationReceipt({ hash });
45+
uiConsole("result", { userOpHash, txHash: receipt.transactionHash, txStatus: receipt.status, userOpSuccess: success, userOpReason: reason });
46+
} catch (error) {
47+
log.error("error", error);
48+
uiConsole("error", error instanceof Error ? error.message : error);
49+
}
50+
};
51+
2752
export const signEthMessage = async (provider: IProvider, uiConsole: (name: string, value: unknown) => void) => {
2853
try {
2954
const ethProvider = new BrowserProvider(provider);

demo/vue-app-new/src/translations/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"btnGetPrivateKey": "Get Private Key",
6464
"btnGetBalance": "Get Balance",
6565
"btnSendEth": "Send ETH",
66+
"btnSendAATx": "Send ETH with Smart Account",
6667
"btnSignEthMessage": "Sign ETH Message",
6768
"btnGetConnectedChainId": "Get Connected Chain ID",
6869
"btnAddChain": "Add Chain",

0 commit comments

Comments
 (0)