diff --git a/src/utils/webapi.js b/src/utils/webapi.js index 09ae8b6..ede9d58 100644 --- a/src/utils/webapi.js +++ b/src/utils/webapi.js @@ -35,10 +35,9 @@ const httpGet = async (url) => { const base58Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz'; export const hexToBase58 = (hexString) => { - const bytes = hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)); - + hexString.match(/.{1,2}/g).map(byte => parseInt(byte, 16)); let base58String = ''; - + // eslint-disable-next-line no-undef let num = BigInt('0x' + hexString); while (num > 0n) { const remainder = num % 58n; diff --git a/src/wallet/index.js b/src/wallet/index.js index 7f30342..b2e6e6b 100644 --- a/src/wallet/index.js +++ b/src/wallet/index.js @@ -5,7 +5,7 @@ import { loginNonce, hexToBase58, aesEncrypt, loginWithSignature } from '@/utils import { SiweMessage } from '@/utils/siwe.js'; import { GlobalData } from '@/utils/GlobalData.js'; -import { parseTokenData, base64ToHex } from '@/utils/utils.js'; +import { parseTokenData } from '@/utils/utils.js'; import { setToken } from '@/utils/cookies.js'; import store from '@/store' import { treasureAbi } from './abi.js' @@ -54,6 +54,7 @@ const connectWc = async () => { icons: ['https://www.counterfire.games/favicon.ico'], }, }); + await wc.connect() return wc; }; export class Wallet { @@ -223,6 +224,13 @@ export class Wallet { async loginWithEthereum(activity) { const web3 = new Web3(this.provider); let addresses = await web3.eth.getAccounts(); + let tryCount = 0; + while (addresses.length === 0) { + addresses = await web3.eth.getAccounts(); + if (tryCount++ > 10) { + throw new Error('No address found'); + } + } let address = web3.utils.toChecksumAddress(addresses[0]); store.commit('wallet/updateAddress', address) // return