diff --git a/layer/package.json b/layer/package.json index 1930ce5a..bb4d1c32 100644 --- a/layer/package.json +++ b/layer/package.json @@ -11,11 +11,11 @@ "@injectivelabs/nuxt-bugsnag": "0.0.3", "@injectivelabs/utils": "1.14.11-beta.3", "@injectivelabs/networks": "1.14.11-beta.4", - "@injectivelabs/sdk-ts": "1.14.11-beta.29", "@injectivelabs/ts-types": "1.14.11-beta.1", - "@injectivelabs/sdk-ui-ts": "1.14.11-beta.41", - "@injectivelabs/token-metadata": "1.14.11-beta.22", - "@injectivelabs/wallet-ts": "1.14.11-beta.37", + "@injectivelabs/sdk-ts": "1.14.11-beta.31", + "@injectivelabs/sdk-ui-ts": "1.14.11-beta.43", + "@injectivelabs/wallet-ts": "1.14.11-beta.39", + "@injectivelabs/token-metadata": "1.14.11-beta.23", "@vueuse/integrations": "^10.7.1", "floating-vue": "2.0.0-beta.24", "vue-gtag": "^2.0.1", diff --git a/layer/store/wallet.ts b/layer/store/wallet.ts index 5e3fa594..7333040f 100644 --- a/layer/store/wallet.ts +++ b/layer/store/wallet.ts @@ -11,20 +11,21 @@ import { isCosmosWallet, isCosmosBrowserWallet } from '@injectivelabs/wallet-ts' +import { + validateCosmosWallet, + confirmCorrectKeplrAddress +} from './../wallet/cosmos' import { validateTrustWallet, isTrustWalletInstalled } from './../wallet/trust-wallet' -import { validateOkxWallet, isOkxWalletInstalled } from './../wallet/okx-wallet' -import { isPhantomInstalled } from './../wallet/phantom' import { IS_DEVNET } from './../utils/constant' -import { - validateCosmosWallet, - confirmCorrectKeplrAddress -} from './../wallet/cosmos' +import { isPhantomInstalled } from './../wallet/phantom' import { walletStrategy } from './../wallet/wallet-strategy' import { confirm, connect, getAddresses } from './../wallet/wallet' +import { isBitGetInstalled, validateBitGet } from './../wallet/bitget' import { validateMetamask, isMetamaskInstalled } from './../wallet/metamask' +import { validateOkxWallet, isOkxWalletInstalled } from './../wallet/okx-wallet' import { EventBus, WalletConnectStatus } from './../types' type WalletStoreState = { @@ -34,6 +35,7 @@ type WalletStoreState = { addressConfirmation: string addresses: string[] hwAddresses: string[] + bitGetInstalled: boolean phantomInstalled: boolean metamaskInstalled: boolean okxWalletInstalled: boolean @@ -50,6 +52,7 @@ const initialStateFactory = (): WalletStoreState => ({ addresses: [], hwAddresses: [], wallet: Wallet.Metamask, + bitGetInstalled: false, phantomInstalled: false, metamaskInstalled: false, okxWalletInstalled: false, @@ -101,6 +104,10 @@ export const useSharedWalletStore = defineStore('sharedWallet', { await validateOkxWallet(walletStore.address) } + if (walletStore.wallet === Wallet.BitGet) { + await validateBitGet(walletStore.address) + } + if (isCosmosBrowserWallet(walletStore.wallet)) { await validateCosmosWallet({ wallet: walletStore.wallet, @@ -172,6 +179,14 @@ export const useSharedWalletStore = defineStore('sharedWallet', { }) }, + async checkIsBitGetInstalled() { + const walletStore = useSharedWalletStore() + + walletStore.$patch({ + bitGetInstalled: await isBitGetInstalled() + }) + }, + async checkIsPhantomWalletInstalled() { const walletStore = useSharedWalletStore() @@ -464,6 +479,24 @@ export const useSharedWalletStore = defineStore('sharedWallet', { await walletStore.onConnect() }, + async connectBitGet() { + const walletStore = useSharedWalletStore() + + await walletStore.connectWallet(Wallet.BitGet) + + const addresses = await getAddresses() + const [address] = addresses + + walletStore.$patch({ + address, + addresses, + addressConfirmation: await confirm(address), + injectiveAddress: getInjectiveAddress(address) + }) + + await walletStore.onConnect() + }, + async logout() { const walletStore = useSharedWalletStore() @@ -472,11 +505,12 @@ export const useSharedWalletStore = defineStore('sharedWallet', { walletStore.$patch({ ...initialStateFactory(), queueStatus: StatusType.Idle, + bitGetInstalled: walletStore.bitGetInstalled, phantomInstalled: walletStore.phantomInstalled, metamaskInstalled: walletStore.metamaskInstalled, okxWalletInstalled: walletStore.okxWalletInstalled, walletConnectStatus: WalletConnectStatus.disconnected, - trustWalletInstalled: walletStore.trustWalletInstalled, + trustWalletInstalled: walletStore.trustWalletInstalled }) } } diff --git a/layer/wallet/bitget.ts b/layer/wallet/bitget.ts new file mode 100644 index 00000000..695f59b3 --- /dev/null +++ b/layer/wallet/bitget.ts @@ -0,0 +1,69 @@ +import { EthereumChainId, AccountAddress } from '@injectivelabs/ts-types' +import { + ErrorType, + GeneralException, + UnspecifiedErrorCode, + BitGetException +} from '@injectivelabs/exceptions' +import { UtilsWallets } from '@injectivelabs/wallet-ts' +import { ETHEREUM_CHAIN_ID } from './../utils/constant' +import { walletStrategy } from './wallet-strategy' + +export const isBitGetInstalled = async (): Promise => { + const provider = await UtilsWallets.getBitGetProvider() + + return !!provider +} + +export const validateBitGet = async ( + address: AccountAddress, + chainId: EthereumChainId = ETHEREUM_CHAIN_ID +) => { + const addresses = await walletStrategy.getAddresses() + const bitGetIsLocked = addresses.length === 0 + + if (bitGetIsLocked) { + throw new BitGetException( + new Error('Your BitGet is currently locked. Please unlock your BitGet.'), + { + code: UnspecifiedErrorCode, + type: ErrorType.WalletError + } + ) + } + + const [bitGetActiveAddress] = addresses + const bitGetActiveAddressDoesntMatchTheActiveAddress = + address && bitGetActiveAddress.toLowerCase() !== address.toLowerCase() + + if (bitGetActiveAddressDoesntMatchTheActiveAddress) { + throw new BitGetException( + new Error( + 'You are connected to the wrong address. Please logout and connect to BitGet again' + ), + { + code: UnspecifiedErrorCode, + type: ErrorType.WalletError + } + ) + } + + const bitGetChainId = parseInt(await walletStrategy.getEthereumChainId(), 16) + const bitGetChainIdDoesntMatchTheActiveChainId = chainId !== bitGetChainId + + if (bitGetChainIdDoesntMatchTheActiveChainId) { + return await UtilsWallets.updateBitGetNetwork(chainId) + } + + const bitGetProvider = await UtilsWallets.getBitGetProvider() + + if (!bitGetProvider) { + throw new GeneralException( + new Error('You are connected to the wrong wallet. Please use BitGet.'), + { + code: UnspecifiedErrorCode, + type: ErrorType.WalletError + } + ) + } +} diff --git a/layer/wallet/cosmos.ts b/layer/wallet/cosmos.ts index dd8c7788..28ad0b36 100644 --- a/layer/wallet/cosmos.ts +++ b/layer/wallet/cosmos.ts @@ -1,7 +1,6 @@ import { ErrorType, UnspecifiedErrorCode, - ChainCosmosErrorCode, CosmosWalletException } from '@injectivelabs/exceptions' import { PublicKey } from '@injectivelabs/sdk-ts' diff --git a/layer/yarn.lock b/layer/yarn.lock index bf76976c..63b98bcc 100644 --- a/layer/yarn.lock +++ b/layer/yarn.lock @@ -1605,10 +1605,10 @@ "@bugsnag/source-maps" "^2.3.1" "@nuxt/kit" "^3.0.0-rc.13" -"@injectivelabs/sdk-ts@1.14.11-beta.29", "@injectivelabs/sdk-ts@^1.14.11-beta.29": - version "1.14.11-beta.29" - resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-1.14.11-beta.29.tgz#9d4ae1edd6f721eb0d29ebfb3eb35c0cc1d784a7" - integrity sha512-iiOPhQ3twmQW8ijUzKVb0vtwxhWw5jSskTRSUbV76ARcofe5Z7FIeNKgBHpeaBdn/UI55q5uS1pdiVOo4Eluew== +"@injectivelabs/sdk-ts@1.14.11-beta.31", "@injectivelabs/sdk-ts@^1.14.11-beta.31": + version "1.14.11-beta.31" + resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-1.14.11-beta.31.tgz#d9efa916f02834d66e56e8369e5958f3db7b8599" + integrity sha512-DMHWw+RNMKWRAlwm2y0vCYGlZ0LbF8uzjqikJ94AfYgLG+k5svKp+y585bRjd8hnK/Otb/q1OsYD7Ibpqyjrrw== dependencies: "@apollo/client" "^3.5.8" "@cosmjs/amino" "^0.32.2" @@ -1627,7 +1627,7 @@ "@injectivelabs/mito-proto-ts" "1.0.63" "@injectivelabs/networks" "^1.14.11-beta.4" "@injectivelabs/test-utils" "^1.14.5-beta.0" - "@injectivelabs/token-metadata" "^1.14.11-beta.22" + "@injectivelabs/token-metadata" "^1.14.11-beta.23" "@injectivelabs/ts-types" "^1.14.11-beta.1" "@injectivelabs/utils" "^1.14.11-beta.3" "@metamask/eth-sig-util" "^4.0.0" @@ -1648,16 +1648,16 @@ shx "^0.3.2" snakecase-keys "^5.4.1" -"@injectivelabs/sdk-ui-ts@1.14.11-beta.41": - version "1.14.11-beta.41" - resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.11-beta.41.tgz#32a742fd5b8e419eaf0f39d83351af5940b014e1" - integrity sha512-XcdWC8tsCFtecKSf1yhqfTs65rI2RvAgJQ57tr4s/18ufqi9hcpUlIsUX9rYDBtn1APmuDwk46QMFN5DztjjwA== +"@injectivelabs/sdk-ui-ts@1.14.11-beta.43": + version "1.14.11-beta.43" + resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.11-beta.43.tgz#24eea90274e89d6384ab6f8b4d4af98dbcf9cfc3" + integrity sha512-iNBQ3PcK7EYuG6j4tg62bZdXQ8L9wEZqBjih3WYrLjBSbUL0I9kcNeUIpug9LaxVH+hm6RiMCi6cV1/IFycp0A== dependencies: "@injectivelabs/contracts" "^1.14.11-beta.4" "@injectivelabs/exceptions" "^1.14.11-beta.3" "@injectivelabs/networks" "^1.14.11-beta.4" - "@injectivelabs/sdk-ts" "^1.14.11-beta.29" - "@injectivelabs/token-metadata" "^1.14.11-beta.22" + "@injectivelabs/sdk-ts" "^1.14.11-beta.31" + "@injectivelabs/token-metadata" "^1.14.11-beta.23" "@injectivelabs/token-utils" "^1.14.11-beta.3" "@injectivelabs/ts-types" "^1.14.11-beta.1" "@injectivelabs/utils" "^1.14.11-beta.3" @@ -1678,10 +1678,10 @@ snakecase-keys "^5.1.2" store2 "^2.12.0" -"@injectivelabs/token-metadata@1.14.11-beta.22", "@injectivelabs/token-metadata@^1.14.11-beta.22": - version "1.14.11-beta.22" - resolved "https://registry.yarnpkg.com/@injectivelabs/token-metadata/-/token-metadata-1.14.11-beta.22.tgz#106fca98a12ff3296708efb3297d77cddca7d6da" - integrity sha512-yVjor2mE/AheADUSf/CQXHoIH65Qu86baIOJH8/3g+z0J4MM3mzSlv9VzuwDaIwX0ctNjcJNpwh5PLUAOMo4Jg== +"@injectivelabs/token-metadata@1.14.11-beta.23", "@injectivelabs/token-metadata@^1.14.11-beta.23": + version "1.14.11-beta.23" + resolved "https://registry.yarnpkg.com/@injectivelabs/token-metadata/-/token-metadata-1.14.11-beta.23.tgz#565686dfc4e017f119bca74e269a2a10e7437698" + integrity sha512-abxCl4GHsVKjy5krp5Q+xX1HPuRs7Sy42kxTAxlNz36tIPF4MB2+6KkYL1DyADRZsb3Zc0/uFHdRZX5xOdPd3Q== dependencies: "@injectivelabs/exceptions" "^1.14.11-beta.3" "@injectivelabs/networks" "^1.14.11-beta.4" @@ -1728,10 +1728,10 @@ snakecase-keys "^5.1.2" store2 "^2.12.0" -"@injectivelabs/wallet-ts@1.14.11-beta.37": - version "1.14.11-beta.37" - resolved "https://registry.yarnpkg.com/@injectivelabs/wallet-ts/-/wallet-ts-1.14.11-beta.37.tgz#8463692c4d0af2c64611b967f4ebc4715bfadfda" - integrity sha512-ALCU0UqCKg5RJABCw6Pu8yF4yQDr14wKdhIlZRZ0PDhDo2yMzw4qydMnDgrExtlBH2+QB5OkdPd85ZhUUWcRWw== +"@injectivelabs/wallet-ts@1.14.11-beta.39": + version "1.14.11-beta.39" + resolved "https://registry.yarnpkg.com/@injectivelabs/wallet-ts/-/wallet-ts-1.14.11-beta.39.tgz#ca4047be248dd463aee71f546da5f6b4d21e2ef6" + integrity sha512-qSpyrI9+sI37ZKsWbP1KJ1HdnFFz2x2OBvEHtq7Kq/3hmGFb15SFP27aZayVl3BnZZ4brhQzX59ks7sO7cEROQ== dependencies: "@cosmjs/launchpad" "0.27.1" "@cosmjs/proto-signing" "0.32.2" @@ -1741,7 +1741,7 @@ "@ethereumjs/tx" "^4.1.1" "@injectivelabs/exceptions" "^1.14.11-beta.3" "@injectivelabs/networks" "^1.14.11-beta.4" - "@injectivelabs/sdk-ts" "^1.14.11-beta.29" + "@injectivelabs/sdk-ts" "^1.14.11-beta.31" "@injectivelabs/ts-types" "^1.14.11-beta.1" "@injectivelabs/utils" "^1.14.11-beta.3" "@keplr-wallet/cosmos" "^0.12.71"