22import { Button , Card } from " @toruslabs/vue-components" ;
33import { CHAIN_NAMESPACES , IProvider , log , WALLET_CONNECTORS , WALLET_PLUGINS } from " @web3auth/modal" ;
44import { useCheckout , useEnableMFA , useIdentityToken , useManageMFA , useSwitchChain , useWalletConnectScanner , useWalletUI , useWeb3Auth , useWeb3AuthUser } from " @web3auth/modal/vue" ;
5- import { CustomChainConfig , type NFTCheckoutPluginType , type WalletServicesPluginType } from " @web3auth/no-modal" ;
5+ import { type CustomChainConfig , type NFTCheckoutPluginType } from " @web3auth/no-modal" ;
66import { useI18n } from " petite-vue-i18n" ;
77
8- import { useAccount } from " @wagmi/vue" ;
8+ import { useSignAndSendTransaction , useSignMessage as useSolanaSignMessage , useSignTransaction , useSolanaWallet } from " @web3auth/modal/vue/solana"
9+ import { useAccount , useBalance , useChainId , useSignMessage , useSignTypedData } from " @wagmi/vue" ;
910
10- import { Connection } from " @solana/web3.js" ;
11+ import { LAMPORTS_PER_SOL , PublicKey , SystemProgram , Transaction } from " @solana/web3.js" ;
1112import { ProviderConfig } from " @toruslabs/base-controllers" ;
1213import { SUPPORTED_NETWORKS } from " @toruslabs/ethereum-controllers" ;
1314import { computed , ref , watch } from " vue" ;
1415import { NFT_CHECKOUT_CONTRACT_ID } from " ../config" ;
1516import {
16- getAccounts ,
17- getBalance ,
18- getChainId ,
1917 getPrivateKey ,
2018 sendEth ,
21- signEthMessage ,
2219 signTransaction as signEthTransaction ,
23- signPersonalMessage ,
24- signTypedMessage ,
2520} from " ../services/ethHandlers" ;
2621import {
22+ getConnection ,
2723 getBalance as getSolBalance ,
2824 getPrivateKey as getSolPrivateKey ,
2925 signAllTransactions ,
30- signAndSendTransaction ,
31- signMessage as signSolMessage ,
32- signTransaction as signSolTransaction ,
3326} from " ../services/solHandlers" ;
34- // import {
35- // walletSendEth,
36- // walletSignPersonalMessage,
37- // walletSignSolanaMessage,
38- // walletSignSolanaVersionedTransaction,
39- // walletSignTypedMessage,
40- // } from "../services/walletServiceHandlers";
4127import { formDataStore } from " ../store/form" ;
4228import { SOLANA_SUPPORTED_NETWORKS } from " ../utils/constants" ;
4329
@@ -60,14 +46,22 @@ const { showWalletUI, loading: showWalletUILoading } = useWalletUI();
6046const { showWalletConnectScanner, loading : showWalletConnectScannerLoading } = useWalletConnectScanner ();
6147const { showCheckout, loading : showCheckoutLoading } = useCheckout ();
6248const { authenticateUser, loading : authenticateUserLoading } = useIdentityToken ();
63- const { status } = useAccount ();
49+ const { status, address } = useAccount ();
50+ const { signTypedDataAsync } = useSignTypedData ();
51+ const { signMessageAsync } = useSignMessage ();
52+ const chainId = useChainId ();
53+ const balance = useBalance ({
54+ address: address .value ,
55+ });
56+
57+ const { accounts : solanaAccounts } = useSolanaWallet ()
58+ const { signMessage : signSolanaMessage } = useSolanaSignMessage ();
59+ const { signTransaction : signSolTransaction } = useSignTransaction ();
60+ const { signAndSendTransaction } = useSignAndSendTransaction ();
6461
6562const currentChainId = ref <string | undefined >(web3Auth .value ?.currentChain ?.chainId );
6663const currentChainConfig = computed (() => supportedNetworks [currentChainId .value as keyof typeof supportedNetworks ]);
6764const currentChainNamespace = computed (() => currentChainConfig .value ?.chainNamespace );
68- const connection = computed (() => {
69- return currentChainConfig ?.value ? new Connection (currentChainConfig ?.value .rpcTarget ) : null ;
70- });
7165
7266const chainChangedListener = (chainId : string ) => {
7367 currentChainId .value = chainId ;
@@ -146,32 +140,9 @@ const printToConsole = (...args: unknown[]) => {
146140};
147141
148142watch (status , (newStatus ) => {
149- console .log (" status" , newStatus );
143+ console .log (" wagmi status" , newStatus );
150144}, { immediate: true });
151145
152- // const onWalletSignPersonalMessage = async () => {
153- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
154- // await walletSignPersonalMessage(walletPlugin.wsEmbedInstance.provider, printToConsole);
155- // };
156- // const onWalletSignTypedData_v4 = async () => {
157- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
158- // await walletSignTypedMessage(walletPlugin.wsEmbedInstance.provider, printToConsole);
159- // };
160- // const onWalletSendEth = async () => {
161- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
162- // await walletSendEth(walletPlugin.wsEmbedInstance.provider, printToConsole);
163- // };
164-
165- // const onWalletSignSolanaMessage = async () => {
166- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
167- // await walletSignSolanaMessage(walletPlugin.wsEmbedInstance.provider as IProvider, printToConsole);
168- // };
169-
170- // const onWalletSignSolanaVersionedTransaction = async () => {
171- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
172- // await walletSignSolanaVersionedTransaction(walletPlugin.wsEmbedInstance.provider as IProvider, connection.value as Connection, printToConsole);
173- // };
174-
175146// NFT Checkout
176147const showPaidMintNFTCheckout = async () => {
177148 const nftCheckoutPlugin = web3Auth .value ?.getPlugin (WALLET_PLUGINS .NFT_CHECKOUT ) as NFTCheckoutPluginType ;
@@ -197,35 +168,66 @@ const onSendEth = async () => {
197168};
198169
199170const onSignEthMessage = async () => {
200- await signEthMessage (provider .value as IProvider , printToConsole );
171+ const result = await signMessageAsync ({
172+ message: " Hello, Bob!" ,
173+ });
174+ printToConsole (" result" , result );
201175};
202176
203177const onGetAccounts = async () => {
204- await getAccounts ( provider . value as IProvider , printToConsole );
178+ printToConsole ( ' account ' , address . value );
205179};
206180
207181const onGetPrivateKey = async () => {
208182 await getPrivateKey (provider .value as IProvider , printToConsole );
209183};
210184
211185const getConnectedChainId = async () => {
212- await getChainId ( provider . value as IProvider , printToConsole );
186+ printToConsole ( ' chainId ' , chainId . value );
213187};
214188
215189const onGetBalance = async () => {
216- await getBalance ( provider . value as IProvider , printToConsole );
190+ printToConsole ( " balance " , balance . data . value ?. formatted );
217191};
218192
219193const onSignEthTransaction = async () => {
220194 await signEthTransaction (provider .value as IProvider , printToConsole );
221195};
222196
223197const onSignTypedData_v4 = async () => {
224- await signTypedMessage (provider .value as IProvider , printToConsole );
198+ const result = await signTypedDataAsync ({
199+ types: {
200+ Person: [
201+ { name: " name" , type: " string" },
202+ { name: ' wallet' , type: ' address' },
203+ ],
204+ Mail: [
205+ { name: ' from' , type: ' Person' },
206+ { name: ' to' , type: ' Person' },
207+ { name: ' contents' , type: ' string' },
208+ ],
209+ },
210+ primaryType: ' Mail' ,
211+ message: {
212+ from: {
213+ name: " Cow" ,
214+ wallet: " 0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826" ,
215+ },
216+ to: {
217+ name: " Bob" ,
218+ wallet: " 0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB" ,
219+ },
220+ contents: " Hello, Bob!" ,
221+ },
222+ });
223+ printToConsole (" result" , result );
225224};
226225
227226const onSignPersonalMsg = async () => {
228- await signPersonalMessage (provider .value as IProvider , printToConsole );
227+ const result = await signMessageAsync ({
228+ message: " Hello, Bob!" ,
229+ });
230+ printToConsole (" result" , result );
229231};
230232
231233// Solana
@@ -234,15 +236,52 @@ const onGetSolPrivateKey = async () => {
234236};
235237
236238const onSignAndSendTransaction = async () => {
237- await signAndSendTransaction (provider .value as IProvider , printToConsole );
239+ if (! solanaAccounts .value ) throw new Error (' No account connected' );
240+ const conn = await getConnection (provider .value as IProvider );
241+ const block = await conn .getLatestBlockhash (" finalized" );
242+ const pubKey = solanaAccounts .value [0 ];
243+
244+ const transactionInstruction = SystemProgram .transfer ({
245+ fromPubkey: new PublicKey (pubKey ),
246+ toPubkey: new PublicKey (pubKey ),
247+ lamports: 0.01 * LAMPORTS_PER_SOL ,
248+ });
249+
250+ const transaction = new Transaction ({
251+ blockhash: block .blockhash ,
252+ lastValidBlockHeight: block .lastValidBlockHeight ,
253+ feePayer: new PublicKey (pubKey ),
254+ }).add (transactionInstruction );
255+
256+ const data = await signAndSendTransaction (transaction );
257+ printToConsole (' result' , data );
238258};
239259
240260const onSignSolTransaction = async () => {
241- await signSolTransaction (provider .value as IProvider , printToConsole );
261+ if (! solanaAccounts .value ) throw new Error (' No account connected' );
262+ const conn = await getConnection (provider .value as IProvider );
263+ const block = await conn .getLatestBlockhash (" finalized" );
264+ const pubKey = solanaAccounts .value [0 ];
265+
266+ const transactionInstruction = SystemProgram .transfer ({
267+ fromPubkey: new PublicKey (pubKey ),
268+ toPubkey: new PublicKey (pubKey ),
269+ lamports: 0.01 * LAMPORTS_PER_SOL ,
270+ });
271+
272+ const transaction = new Transaction ({
273+ blockhash: block .blockhash ,
274+ lastValidBlockHeight: block .lastValidBlockHeight ,
275+ feePayer: new PublicKey (pubKey ),
276+ }).add (transactionInstruction );
277+
278+ const result = await signSolTransaction (transaction )
279+ printToConsole (' result' , result );
242280};
243281
244282const onSignSolMessage = async () => {
245- await signSolMessage (provider .value as IProvider , printToConsole );
283+ const result = await signSolanaMessage (" Hello, Bob!" );
284+ printToConsole (" result" , result );
246285};
247286
248287const onGetSolBalance = async () => {
0 commit comments