From 467ba45f59969702439744ee42c8aae6d375e698 Mon Sep 17 00:00:00 2001 From: CounterFire2023 <136581895+CounterFire2023@users.noreply.github.com> Date: Wed, 17 Jul 2024 11:43:46 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E8=8B=B1=E9=9B=84=E4=B8=8A=E9=93=BE?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=8B=AC=E7=AB=8B=E5=87=BA=E6=9D=A5,=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=AF=E6=8C=87=E5=AE=9A=E7=9B=AE=E6=A0=87?= =?UTF-8?q?=E5=9C=B0=E5=9D=80=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/chain/BlockChain.js | 36 +++++++++++++ src/components/chain/WalletSelectModel.vue | 26 +++++++--- src/components/chain/contract/Locker.js | 59 +++++++++++++++------- src/utils/marketplace.js | 12 ++--- 4 files changed, 103 insertions(+), 30 deletions(-) diff --git a/src/components/chain/BlockChain.js b/src/components/chain/BlockChain.js index db1942b..174442a 100644 --- a/src/components/chain/BlockChain.js +++ b/src/components/chain/BlockChain.js @@ -132,6 +132,20 @@ export class BlockChain { return token+suffix } + /** + * 如果是用passport登录的, 直接返回store中的token, 否则调用passport的getAccessToken + * @returns + */ + async passportToken() { + if (this.store.walletType == 3) { + return this.store.token + } + if (!this.passportProvider) { + return '' + } + const res = await new PassportWallet().getAccessToken(); + return res.token + } async logout() { if (this.store.walletType != 3 && this.passportProvider) { @@ -176,4 +190,26 @@ export class BlockChain { await this.appendPassport(); } } + + async selectAddress({title, subTitle, targetChainId}) { + const initData = {} + initData[this.store.walletType] = this.store.address + const rewardModal = createModal(WalletSelectModel, { + title: title || 'Select Address', + message: subTitle || 'Please select the address you want to use', + initData: { 1: 'MetaMask', 2: 'OKX Wallet', 3: 'Passport' } + }); + const { errcode, errmsg, walletInstance, provider, accounts } = await rewardModal.show(); + if (errcode) { + console.log(`select address result : ${errmsg}`); + throw new Error(errmsg); + } + targetChainId = targetChainId || cfgChainId; + let chainId = await walletInstance.getChainId(); + if (chainId !== targetChainId) { + console.log(`current chain: ${chainId}, want: ${targetChainId}`) + chainId = await switchEthereumChain(provider.provider, targetChainId); + } + return { provider, address: accounts[0] }; + } } diff --git a/src/components/chain/WalletSelectModel.vue b/src/components/chain/WalletSelectModel.vue index 6eddbfc..e0b7874 100644 --- a/src/components/chain/WalletSelectModel.vue +++ b/src/components/chain/WalletSelectModel.vue @@ -3,7 +3,7 @@