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 { Connection } from " @solana/web3.js" ;
8+ import { useSignAndSendTransaction , useSignMessage as useSolanaSignMessage , useSignTransaction , useSolanaWallet } from " @web3auth/modal/vue/solana"
9+ import { useAccount , useBalance , useChainId , useSignMessage , useSignTypedData } from " @wagmi/vue" ;
10+
11+ import { LAMPORTS_PER_SOL , PublicKey , SystemProgram , Transaction } from " @solana/web3.js" ;
912import { ProviderConfig } from " @toruslabs/base-controllers" ;
1013import { SUPPORTED_NETWORKS } from " @toruslabs/ethereum-controllers" ;
1114import { computed , ref , watch } from " vue" ;
1215import { NFT_CHECKOUT_CONTRACT_ID } from " ../config" ;
1316import {
14- getAccounts ,
15- getBalance ,
16- getChainId ,
1717 getPrivateKey ,
1818 sendEth ,
19- signEthMessage ,
2019 signTransaction as signEthTransaction ,
21- signPersonalMessage ,
22- signTypedMessage ,
2320} from " ../services/ethHandlers" ;
2421import {
22+ getConnection ,
2523 getBalance as getSolBalance ,
2624 getPrivateKey as getSolPrivateKey ,
2725 signAllTransactions ,
28- signAndSendTransaction ,
29- signMessage as signSolMessage ,
30- signTransaction as signSolTransaction ,
3126} from " ../services/solHandlers" ;
32- // import {
33- // walletSendEth,
34- // walletSignPersonalMessage,
35- // walletSignSolanaMessage,
36- // walletSignSolanaVersionedTransaction,
37- // walletSignTypedMessage,
38- // } from "../services/walletServiceHandlers";
3927import { formDataStore } from " ../store/form" ;
4028import { SOLANA_SUPPORTED_NETWORKS } from " ../utils/constants" ;
4129
@@ -58,13 +46,22 @@ const { showWalletUI, loading: showWalletUILoading } = useWalletUI();
5846const { showWalletConnectScanner, loading : showWalletConnectScannerLoading } = useWalletConnectScanner ();
5947const { showCheckout, loading : showCheckoutLoading } = useCheckout ();
6048const { authenticateUser, loading : authenticateUserLoading } = useIdentityToken ();
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 ();
6161
6262const currentChainId = ref <string | undefined >(web3Auth .value ?.currentChain ?.chainId );
6363const currentChainConfig = computed (() => supportedNetworks [currentChainId .value as keyof typeof supportedNetworks ]);
6464const currentChainNamespace = computed (() => currentChainConfig .value ?.chainNamespace );
65- const connection = computed (() => {
66- return currentChainConfig ?.value ? new Connection (currentChainConfig ?.value .rpcTarget ) : null ;
67- });
6865
6966const chainChangedListener = (chainId : string ) => {
7067 currentChainId .value = chainId ;
@@ -142,28 +139,9 @@ const printToConsole = (...args: unknown[]) => {
142139 }
143140};
144141
145- // const onWalletSignPersonalMessage = async () => {
146- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
147- // await walletSignPersonalMessage(walletPlugin.wsEmbedInstance.provider, printToConsole);
148- // };
149- // const onWalletSignTypedData_v4 = async () => {
150- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
151- // await walletSignTypedMessage(walletPlugin.wsEmbedInstance.provider, printToConsole);
152- // };
153- // const onWalletSendEth = async () => {
154- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
155- // await walletSendEth(walletPlugin.wsEmbedInstance.provider, printToConsole);
156- // };
157-
158- // const onWalletSignSolanaMessage = async () => {
159- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
160- // await walletSignSolanaMessage(walletPlugin.wsEmbedInstance.provider as IProvider, printToConsole);
161- // };
162-
163- // const onWalletSignSolanaVersionedTransaction = async () => {
164- // const walletPlugin = web3Auth.value?.getPlugin(WALLET_PLUGINS.WALLET_SERVICES) as WalletServicesPluginType;
165- // await walletSignSolanaVersionedTransaction(walletPlugin.wsEmbedInstance.provider as IProvider, connection.value as Connection, printToConsole);
166- // };
142+ watch (status , (newStatus ) => {
143+ console .log (" wagmi status" , newStatus );
144+ }, { immediate: true });
167145
168146// NFT Checkout
169147const showPaidMintNFTCheckout = async () => {
@@ -190,35 +168,66 @@ const onSendEth = async () => {
190168};
191169
192170const onSignEthMessage = async () => {
193- await signEthMessage (provider .value as IProvider , printToConsole );
171+ const result = await signMessageAsync ({
172+ message: " Hello, Bob!" ,
173+ });
174+ printToConsole (" result" , result );
194175};
195176
196177const onGetAccounts = async () => {
197- await getAccounts ( provider . value as IProvider , printToConsole );
178+ printToConsole ( ' account ' , address . value );
198179};
199180
200181const onGetPrivateKey = async () => {
201182 await getPrivateKey (provider .value as IProvider , printToConsole );
202183};
203184
204185const getConnectedChainId = async () => {
205- await getChainId ( provider . value as IProvider , printToConsole );
186+ printToConsole ( ' chainId ' , chainId . value );
206187};
207188
208189const onGetBalance = async () => {
209- await getBalance ( provider . value as IProvider , printToConsole );
190+ printToConsole ( " balance " , balance . data . value ?. formatted );
210191};
211192
212193const onSignEthTransaction = async () => {
213194 await signEthTransaction (provider .value as IProvider , printToConsole );
214195};
215196
216197const onSignTypedData_v4 = async () => {
217- 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 );
218224};
219225
220226const onSignPersonalMsg = async () => {
221- await signPersonalMessage (provider .value as IProvider , printToConsole );
227+ const result = await signMessageAsync ({
228+ message: " Hello, Bob!" ,
229+ });
230+ printToConsole (" result" , result );
222231};
223232
224233// Solana
@@ -227,15 +236,52 @@ const onGetSolPrivateKey = async () => {
227236};
228237
229238const onSignAndSendTransaction = async () => {
230- 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 );
231258};
232259
233260const onSignSolTransaction = async () => {
234- 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 );
235280};
236281
237282const onSignSolMessage = async () => {
238- await signSolMessage (provider .value as IProvider , printToConsole );
283+ const result = await signSolanaMessage (" Hello, Bob!" );
284+ printToConsole (" result" , result );
239285};
240286
241287const onGetSolBalance = async () => {
0 commit comments