add Bitget wallet
This commit is contained in:
parent
799f70d63c
commit
ae3d3d1344
@ -1,6 +1,7 @@
|
||||
import { PassportWallet } from "@/components/chain/wallet/PassportWallet";
|
||||
import { MetaMaskWallet } from '@/components/chain/wallet/MetaMaskWallet';
|
||||
import { OkxWallet } from '@/components/chain/wallet/OkxWallet';
|
||||
import { BitgetWallet } from '@/components/chain/wallet/BitgetWallet';
|
||||
import { walletStore } from "@/store/wallet";
|
||||
import WalletSelectModel from "@/components/chain/WalletSelectModel.vue";
|
||||
import {createModal} from "@/utils/model.util";
|
||||
@ -16,7 +17,8 @@ import { Widgets } from "./Widgets";
|
||||
export const allProviders = {
|
||||
1: MetaMaskWallet,
|
||||
2: OkxWallet,
|
||||
3: PassportWallet
|
||||
3: PassportWallet,
|
||||
4: BitgetWallet
|
||||
}
|
||||
|
||||
export class BlockChain {
|
||||
@ -87,7 +89,7 @@ export class BlockChain {
|
||||
this.wallet = new allProviders[walletType]();
|
||||
const { provider, accounts } = await this.wallet.web3Provider();
|
||||
await this.updateInfo({provider, accounts })
|
||||
if ((walletType == 1 || walletType == 2) && this.store.passportAddress) {
|
||||
if ((walletType == 1 || walletType == 2 || walletType == 4) && this.store.passportAddress) {
|
||||
await this.appendPassport();
|
||||
} else if (walletType == 3 && this.store.eoaType) {
|
||||
await this.restoreEoa();
|
||||
@ -170,7 +172,7 @@ export class BlockChain {
|
||||
}
|
||||
|
||||
async token() {
|
||||
const suffix = (this.store.walletType == 2 || this.store.walletType == 1) ? '.cf' : ''
|
||||
const suffix = (this.store.walletType == 2 || this.store.walletType == 1 || this.store.walletType == 4) ? '.cf' : ''
|
||||
let token = this.store.token;
|
||||
if (!suffix && this.store.walletType == 3) {
|
||||
const res = await this.wallet.getAccessToken();
|
||||
@ -184,7 +186,7 @@ export class BlockChain {
|
||||
}
|
||||
// 检查是否已登录eoa
|
||||
get eoaLogined() {
|
||||
return this.store.walletType == 1 || this.store.walletType == 2 || !!this.eoaProvider
|
||||
return this.store.walletType == 1 || this.store.walletType == 2 || this.store.walletType == 4 || !!this.eoaProvider
|
||||
}
|
||||
|
||||
/**
|
||||
|
48
src/components/chain/wallet/BitgetWallet.js
Normal file
48
src/components/chain/wallet/BitgetWallet.js
Normal file
@ -0,0 +1,48 @@
|
||||
import { providers } from "ethers"
|
||||
import { signLogin } from '@/components/chain/utils.js'
|
||||
|
||||
export class BitgetWallet{
|
||||
constructor() {
|
||||
if (BitgetWallet.instance) {
|
||||
return BitgetWallet.instance;
|
||||
}
|
||||
BitgetWallet.instance = this;
|
||||
this._nativeProvider = window.bitkeep?.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 getAccessToken() {
|
||||
const accounts = await this.nativeProvider.request({ method: "eth_requestAccounts" });
|
||||
const { token, refreshToken } = await signLogin(this.nativeProvider, accounts[0]);
|
||||
return { token, refreshToken }
|
||||
}
|
||||
|
||||
get installed() {
|
||||
console.log('bitget install: ', window.bitkeep, window.bitkeep.ethereum)
|
||||
return !!window.bitkeep && !!window.bitkeep.ethereum;
|
||||
}
|
||||
|
||||
async logout() {
|
||||
await this.nativeProvider.request({
|
||||
"method": "wallet_revokePermissions",
|
||||
"params": [
|
||||
{
|
||||
"eth_accounts": {}
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async getChainId() {
|
||||
const chainId = await this.nativeProvider.request({ method: "eth_chainId" });
|
||||
return parseInt(chainId);
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user