diff --git a/src/App.vue b/src/App.vue index db24ec2..4aa5c6d 100644 --- a/src/App.vue +++ b/src/App.vue @@ -12,6 +12,7 @@ import Notification from './components/global/Notification.vue' import { gsap } from "gsap"; import { ScrollTrigger } from "gsap/ScrollTrigger"; +import { BlockChain } from '@/components/chain/BlockChain'; gsap.registerPlugin(ScrollTrigger); @@ -21,6 +22,10 @@ const notification = ref(null); provide('addNotification', (title, message) => { notification.value.addNotification(title, message); }); + +onMounted(() => { + new BlockChain().preparePassport(); +}); diff --git a/src/components/chain/wallet/MetaMaskWallet.js b/src/components/chain/wallet/MetaMaskWallet.js new file mode 100644 index 0000000..30cf2d0 --- /dev/null +++ b/src/components/chain/wallet/MetaMaskWallet.js @@ -0,0 +1,31 @@ +import { providers } from "ethers" + +export class MetaMaskWallet{ + constructor() { + if (MetaMaskWallet.instance) { + return MetaMaskWallet.instance; + } + MetaMaskWallet.instance = this; + this._nativeProvider = window.ethereum; + } + + get nativeProvider() { + return this._nativeProvider + } + async web3Provider() { + const provider = new providers.Web3Provider(this.nativeProvider); + const accounts = await this.nativeProvider.request({ method: "eth_requestAccounts" }); + return { provider, accounts }; + } + + async logout() { + await this.nativeProvider.request({ + "method": "wallet_revokePermissions", + "params": [ + { + "eth_accounts": {} + } + ] + }); + } +} \ No newline at end of file diff --git a/src/components/chain/wallet/OkxWallet.js b/src/components/chain/wallet/OkxWallet.js new file mode 100644 index 0000000..985cad5 --- /dev/null +++ b/src/components/chain/wallet/OkxWallet.js @@ -0,0 +1,25 @@ +import { providers } from "ethers" + +export class OkxWallet{ + constructor() { + if (OkxWallet.instance) { + return OkxWallet.instance; + } + OkxWallet.instance = this; + this._nativeProvider = window.okxwallet; + } + + get nativeProvider() { + return this._nativeProvider + } + + async web3Provider() { + const provider = new providers.Web3Provider(this.nativeProvider); + const accounts = await this.nativeProvider.request({ method: "eth_requestAccounts" }); + return { provider, accounts }; + } + + async logout() { + await this.nativeProvider.request({ method: 'wallet_disconnect' }); + } +} \ No newline at end of file diff --git a/src/components/chain/PassportWallet.js b/src/components/chain/wallet/PassportWallet.js similarity index 84% rename from src/components/chain/PassportWallet.js rename to src/components/chain/wallet/PassportWallet.js index 5e2887f..9a9a6f8 100644 --- a/src/components/chain/PassportWallet.js +++ b/src/components/chain/wallet/PassportWallet.js @@ -1,5 +1,4 @@ import { config, passport, orderbook, checkout } from '@imtbl/sdk'; -import { createSingleton } from '@/utils/singleton'; import { providers } from 'ethers'; const environment = process.env.NODE_ENV === 'production' ? config.Environment.PRODUCTION : config.Environment.SANDBOX; @@ -10,8 +9,12 @@ const logoutRedirectUri = import.meta.env.VUE_APP_PASSPORT_LOGOUT_URI export const baseConfig = { environment, publishableKey } -class LPassportWallet { +export class PassportWallet { constructor() { + if (PassportWallet.instance) { + return PassportWallet.instance; + } + PassportWallet.instance = this; this.passportInstance = new passport.Passport({ baseConfig, clientId, // replace with your client ID from Hub @@ -55,9 +58,13 @@ class LPassportWallet { return this.passportInstance.connectEvm(); } - get web3Provider() { + async web3Provider() { const passportProvider = this.passportInstance.connectEvm(); - return new providers.Web3Provider(passportProvider); + const accounts = await passportProvider.request({ method: "eth_requestAccounts" }); + const provider = new providers.Web3Provider(passportProvider); + let accessToken = await this.passportInstance.getAccessToken() + console.log(`accesstoken`, accessToken) + return { provider, accounts }; } @@ -70,5 +77,3 @@ class LPassportWallet { } } - -export const PassportWallet = createSingleton(LPassportWallet) \ No newline at end of file diff --git a/src/components/layout/NavBar.vue b/src/components/layout/NavBar.vue index a75b5b7..06e4677 100644 --- a/src/components/layout/NavBar.vue +++ b/src/components/layout/NavBar.vue @@ -40,12 +40,12 @@