Skip to content

Commit

Permalink
chore: layer setup okx wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasRalee committed Mar 1, 2024
1 parent 64ba728 commit 7ad40fb
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 27 deletions.
42 changes: 42 additions & 0 deletions layer/icons/wallet/okx-wallet.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<template>
<svg
id="Layer_1"
xmlns:xodm="http://www.corel.com/coreldraw/odm/2003"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
version="1.1"
x="0px"
y="0px"
viewBox="0 0 2500 2500"
style="enable-background: new 0 0 2500 2500"
xml:space="preserve"
>
<g id="Layer_x0020_1">
<g id="_2187289728928">
<rect y="0" class="okx-st0" width="2500" height="2500" />
<g>
<path
d="M1464.3,1015.3h-405.2c-17.2,0-31.3,14.1-31.3,31.3v405.2c0,17.2,14.1,31.3,31.3,31.3h405.2c17.2,0,31.3-14.1,31.3-31.3 v-405.2C1495.6,1029.4,1481.5,1015.3,1464.3,1015.3z"
/>
<path
d="M996.6,549.1H591.4c-17.2,0-31.3,14.1-31.3,31.3v405.2c0,17.2,14.1,31.3,31.3,31.3h405.2c17.2,0,31.3-14.1,31.3-31.3 V580.4C1027.8,563.2,1013.8,549.1,996.6,549.1z"
/>
<path
d="M1930.5,549.1h-405.2c-17.2,0-31.3,14.1-31.3,31.3v405.2c0,17.2,14.1,31.3,31.3,31.3h405.2c17.2,0,31.3-14.1,31.3-31.3 V580.4C1961.8,563.2,1947.7,549.1,1930.5,549.1z"
/>
<path
d="M996.6,1481.5H591.4c-17.2,0-31.3,14.1-31.3,31.3V1918c0,17.2,14.1,31.3,31.3,31.3h405.2c17.2,0,31.3-14.1,31.3-31.3 v-405.2C1027.8,1495.6,1013.8,1481.5,996.6,1481.5z"
/>
<path
d="M1930.5,1481.5h-405.2c-17.2,0-31.3,14.1-31.3,31.3V1918c0,17.2,14.1,31.3,31.3,31.3h405.2c17.2,0,31.3-14.1,31.3-31.3 v-405.2C1961.8,1495.6,1947.7,1481.5,1930.5,1481.5z"
/>
</g>
</g>
</g>
</svg>
</template>
<style scoped>
.okx-st0 {
fill: none;
}
</style>
2 changes: 1 addition & 1 deletion layer/nuxt-config/vite/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default defineConfig({

optimizeDeps: {
exclude: ['fsevents'],
include: ['@injectivelabs/sdk-ts']
include: []
}
}) as ViteConfig

Expand Down
6 changes: 3 additions & 3 deletions layer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"@injectivelabs/nuxt-bugsnag": "0.0.3",
"@injectivelabs/utils": "1.14.6-beta.10",
"@injectivelabs/networks": "1.14.6-beta.13",
"@injectivelabs/sdk-ts": "1.14.6-beta.54",
"@injectivelabs/sdk-ui-ts": "1.14.6-beta.61",
"@injectivelabs/sdk-ts": "1.14.6-beta.58",
"@injectivelabs/sdk-ui-ts": "1.14.6-beta.65",
"@injectivelabs/token-metadata": "1.14.6-beta.45",
"@injectivelabs/wallet-ts": "1.14.6-beta.61",
"@injectivelabs/wallet-ts": "1.14.6-beta.65",
"@vueuse/integrations": "^10.7.1",
"floating-vue": "2.0.0-beta.24",
"vue-gtag": "^2.0.1",
Expand Down
40 changes: 38 additions & 2 deletions layer/store/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ 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 {
Expand All @@ -35,6 +36,7 @@ type WalletStoreState = {
hwAddresses: string[]
phantomInstalled: boolean
metamaskInstalled: boolean
okxWalletInstalled: boolean
trustWalletInstalled: boolean
wallet: Wallet
queueStatus: StatusType
Expand All @@ -50,6 +52,7 @@ const initialStateFactory = (): WalletStoreState => ({
wallet: Wallet.Metamask,
phantomInstalled: false,
metamaskInstalled: false,
okxWalletInstalled: false,
trustWalletInstalled: false,
queueStatus: StatusType.Idle
})
Expand Down Expand Up @@ -94,6 +97,10 @@ export const useSharedWalletStore = defineStore('sharedWallet', {
await validateTrustWallet(walletStore.address)
}

if (walletStore.wallet === Wallet.OkxWallet) {
await validateOkxWallet(walletStore.address)
}

if (isCosmosBrowserWallet(walletStore.wallet)) {
await validateCosmosWallet({
wallet: walletStore.wallet,
Expand Down Expand Up @@ -157,6 +164,16 @@ export const useSharedWalletStore = defineStore('sharedWallet', {
})
},

async checkIsOkxWalletInstalled() {
const walletStore = useSharedWalletStore()

console.log('check okx', await isOkxWalletInstalled())

walletStore.$patch({
okxWalletInstalled: await isOkxWalletInstalled()
})
},

async checkIsPhantomWalletInstalled() {
const walletStore = useSharedWalletStore()

Expand Down Expand Up @@ -402,8 +419,26 @@ export const useSharedWalletStore = defineStore('sharedWallet', {
walletStore.$patch({
address,
addresses,
injectiveAddress: getInjectiveAddress(address),
addressConfirmation: await confirm(address)
addressConfirmation: await confirm(address),
injectiveAddress: getInjectiveAddress(address)
})

await walletStore.onConnect()
},

async connectOkxWallet() {
const walletStore = useSharedWalletStore()

await walletStore.connectWallet(Wallet.OkxWallet)

const addresses = await getAddresses()
const [address] = addresses

walletStore.$patch({
address,
addresses,
addressConfirmation: await confirm(address),
injectiveAddress: getInjectiveAddress(address)
})

await walletStore.onConnect()
Expand All @@ -417,6 +452,7 @@ export const useSharedWalletStore = defineStore('sharedWallet', {
walletStore.$patch({
...initialStateFactory(),
metamaskInstalled: walletStore.metamaskInstalled,
okxWalletInstalled: walletStore.okxWalletInstalled,
walletConnectStatus: WalletConnectStatus.disconnected
})
}
Expand Down
6 changes: 5 additions & 1 deletion layer/wallet/metamask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ export const validateMetamask = async (address: string) => {
)
}

if (!metamaskProvider.isMetaMask || metamaskProvider.isPhantom) {
if (
metamaskProvider.isPhantom ||
metamaskProvider.isOkxWallet ||
metamaskProvider.isTrustWallet
) {
throw new GeneralException(
new Error('You are connected to the wrong wallet. Please use Metamask.'),
{
Expand Down
75 changes: 75 additions & 0 deletions layer/wallet/okx-wallet.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { EthereumChainId, AccountAddress } from '@injectivelabs/ts-types'
import {
ErrorType,
GeneralException,
OkxWalletException,
UnspecifiedErrorCode
} from '@injectivelabs/exceptions'
import { UtilsWallets } from '@injectivelabs/wallet-ts'
import { walletStrategy } from './wallet-strategy'
import { ETHEREUM_CHAIN_ID } from './../utils/constant'

export const isOkxWalletInstalled = async (): Promise<boolean> => {
const provider = await UtilsWallets.getOkxWalletProvider()

return !!provider
}

export const validateOkxWallet = async (
address: AccountAddress,
chainId: EthereumChainId = ETHEREUM_CHAIN_ID
) => {
const addresses = await walletStrategy.getAddresses()
const okxWalletIsLocked = addresses.length === 0

if (okxWalletIsLocked) {
throw new OkxWalletException(
new Error(
'Your OkxWallet is currently locked. Please unlock your OkxWallet.'
),
{
code: UnspecifiedErrorCode,
type: ErrorType.WalletError
}
)
}

const [okxWalletActiveAddress] = addresses
const okxWalletActiveAddressDoesntMatchTheActiveAddress =
address && okxWalletActiveAddress.toLowerCase() !== address.toLowerCase()

if (okxWalletActiveAddressDoesntMatchTheActiveAddress) {
throw new OkxWalletException(
new Error(
'You are connected to the wrong address. Please logout and connect to OkxWallet again'
),
{
code: UnspecifiedErrorCode,
type: ErrorType.WalletError
}
)
}

const okxWalletChainId = parseInt(
await walletStrategy.getEthereumChainId(),
16
)
const okxWalletChainIdDoesntMatchTheActiveChainId =
chainId !== okxWalletChainId

if (okxWalletChainIdDoesntMatchTheActiveChainId) {
return await UtilsWallets.updateOkxWalletNetwork(chainId)
}

const okxProvider = await UtilsWallets.getOkxWalletProvider()

if (!okxProvider) {
throw new GeneralException(
new Error('You are connected to the wrong wallet. Please use Metamask.'),
{
code: UnspecifiedErrorCode,
type: ErrorType.WalletError
}
)
}
}
2 changes: 1 addition & 1 deletion layer/wallet/trust-wallet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { EthereumChainId, AccountAddress } from '@injectivelabs/ts-types'
import { AccountAddress } from '@injectivelabs/ts-types'
import {
ErrorType,
UnspecifiedErrorCode,
Expand Down
38 changes: 19 additions & 19 deletions layer/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1434,10 +1434,10 @@
protobufjs "^7.0.0"
rxjs "^7.4.0"

"@injectivelabs/[email protected].59":
version "1.0.59"
resolved "https://registry.yarnpkg.com/@injectivelabs/mito-proto-ts/-/mito-proto-ts-1.0.59.tgz#7e842dd0893c04afad5984640347d9f6641e0ed5"
integrity sha512-eQZ9unwCci6/OlL78k8WSAB8DWPjQJwLFAWr452UwenOYo1antqXuhdXrsRu09OMYy4Du2NXR7NpUZt0pF1mvg==
"@injectivelabs/[email protected].62":
version "1.0.62"
resolved "https://registry.yarnpkg.com/@injectivelabs/mito-proto-ts/-/mito-proto-ts-1.0.62.tgz#45fc0746af7d1b283625816caeb9fff9887e050f"
integrity sha512-WtoO80Y597nZiAuE4H+L208I0i3ByWytR+HqABdCaA26uJ7F1LhXw8YXxh3pP9z0LAeW31T+N7bwtOMlVR4riA==
dependencies:
"@injectivelabs/grpc-web" "^0.0.1"
google-protobuf "^3.14.0"
Expand Down Expand Up @@ -1465,10 +1465,10 @@
"@bugsnag/source-maps" "^2.3.1"
"@nuxt/kit" "^3.0.0-rc.13"

"@injectivelabs/[email protected].53", "@injectivelabs/sdk-ts@^1.14.6-beta.53":
version "1.14.6-beta.53"
resolved "https://registry.npmjs.org/@injectivelabs/sdk-ts/-/sdk-ts-1.14.6-beta.53.tgz#d80c600ca8fcd5154721ef9b7ad0768938abb6f8"
integrity sha512-j08Z2BQzdTCqdNYpk0pPS3k/iJ0o9ADtrjYsXUYbqcEEe+c4sKEunkK51Qn+5mFjuNdpaoXP+F/aaRR8M2XsEQ==
"@injectivelabs/[email protected].58", "@injectivelabs/sdk-ts@^1.14.6-beta.58":
version "1.14.6-beta.58"
resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ts/-/sdk-ts-1.14.6-beta.58.tgz#0700a705a467347d2cd5fd5f94c1a9aa716215d7"
integrity sha512-g1fu/OB3r63b+6uRthR3ekcuBK6E9CF3uJ7Qpl5k6UZkZ9NvhJGkbveEPs1hMCYHsbDGWl3iXZuEM7McTkMrdw==
dependencies:
"@apollo/client" "^3.5.8"
"@cosmjs/amino" "^0.32.2"
Expand All @@ -1484,7 +1484,7 @@
"@injectivelabs/grpc-web-node-http-transport" "^0.0.2"
"@injectivelabs/grpc-web-react-native-transport" "^0.0.2"
"@injectivelabs/indexer-proto-ts" "1.11.36"
"@injectivelabs/mito-proto-ts" "1.0.59"
"@injectivelabs/mito-proto-ts" "1.0.62"
"@injectivelabs/networks" "^1.14.6-beta.13"
"@injectivelabs/test-utils" "^1.14.3"
"@injectivelabs/token-metadata" "^1.14.6-beta.45"
Expand All @@ -1508,15 +1508,15 @@
shx "^0.3.2"
snakecase-keys "^5.4.1"

"@injectivelabs/[email protected].60":
version "1.14.6-beta.60"
resolved "https://registry.npmjs.org/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.6-beta.60.tgz#9d57267412519ff7f8bae4f2edfcb7d83a9fcb29"
integrity sha512-fJ7/yToFpNK0T/oDWUDm4jK6xH6c5xSU7EwMtC1y2P58xS1XmIfjKYaiiQXm+Is0QvdzzUWkYuNHbwFcmdraVg==
"@injectivelabs/[email protected].65":
version "1.14.6-beta.65"
resolved "https://registry.yarnpkg.com/@injectivelabs/sdk-ui-ts/-/sdk-ui-ts-1.14.6-beta.65.tgz#52b8a200896033ddcb4ed7779f8a44580fb05724"
integrity sha512-SByLhhaz62FgFHfbzJqzPOYnUOn1536Vailci6G7s42Sb0mROlxmW14BDQ9UaST75vDS1AnnYWDwWkKKmip7Gw==
dependencies:
"@injectivelabs/contracts" "^1.14.6-beta.13"
"@injectivelabs/exceptions" "^1.14.6-beta.9"
"@injectivelabs/networks" "^1.14.6-beta.13"
"@injectivelabs/sdk-ts" "^1.14.6-beta.53"
"@injectivelabs/sdk-ts" "^1.14.6-beta.58"
"@injectivelabs/token-metadata" "^1.14.6-beta.45"
"@injectivelabs/token-utils" "^1.14.6-beta.10"
"@injectivelabs/ts-types" "^1.14.6-beta.5"
Expand Down Expand Up @@ -1588,10 +1588,10 @@
snakecase-keys "^5.1.2"
store2 "^2.12.0"

"@injectivelabs/[email protected].60":
version "1.14.6-beta.60"
resolved "https://registry.npmjs.org/@injectivelabs/wallet-ts/-/wallet-ts-1.14.6-beta.60.tgz#37c9b72c58d482cb4a463188db2b22ae1c224152"
integrity sha512-mlsuLaB6vhhAoANu+AhJuAS5zSFfoSVRZSGOpBpjZaOMlNsreQLTQPqBLzeKHXP59Yt/VpwZe/x6rNgWLHGe9g==
"@injectivelabs/[email protected].65":
version "1.14.6-beta.65"
resolved "https://registry.yarnpkg.com/@injectivelabs/wallet-ts/-/wallet-ts-1.14.6-beta.65.tgz#78fb34bf40a159fda4bee20f3ab276db21f82e84"
integrity sha512-Sbds9TVXjD2EAxYDsaLpW5O7zyYhqHljz2gI67yv4i07WHuPUoVl/fOioNkbYmTuaAwgQN+8LV/FAbD7ErePXw==
dependencies:
"@cosmjs/launchpad" "0.27.1"
"@cosmjs/proto-signing" "0.32.2"
Expand All @@ -1601,7 +1601,7 @@
"@ethereumjs/tx" "^4.1.1"
"@injectivelabs/exceptions" "^1.14.6-beta.9"
"@injectivelabs/networks" "^1.14.6-beta.13"
"@injectivelabs/sdk-ts" "^1.14.6-beta.53"
"@injectivelabs/sdk-ts" "^1.14.6-beta.58"
"@injectivelabs/ts-types" "^1.14.6-beta.5"
"@injectivelabs/utils" "^1.14.6-beta.10"
"@keplr-wallet/cosmos" "^0.11.58"
Expand Down

0 comments on commit 7ad40fb

Please sign in to comment.