Skip to content

Commit

Permalink
Implement okx wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ccali11 committed May 19, 2023
1 parent 8c865d4 commit 97de2d9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
10 changes: 10 additions & 0 deletions apps/web/src/components/Wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
>
Select Ledger
</button>
<button
class="okx-btn"
@click="selectProvider('OkxWallet')"
>
Select OKX Wallet
</button>
<button
class="trezor-btn"
@click="selectProvider('Trezor')"
Expand Down Expand Up @@ -320,6 +326,10 @@ button {
background-color: rgb(0, 0, 0);
}
.okx-btn {
background-color: rgb(125, 1, 182);
}
.trezor-btn {
background-color: rgb(34, 99, 55);
}
Expand Down
17 changes: 10 additions & 7 deletions apps/web/src/composables/ethers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import useEnvironment from '@/composables/environment'
const { createSiweMessage, signInWithEthereum } = useAuth()
const { ethereumURL } = useEnvironment()

const defaultProviders = {
MetaMask: window.ethereum?.providerMap?.get('MetaMask') || undefined,
CoinbaseWallet: window.ethereum?.providerMap?.get('CoinbaseWallet') || undefined,
}

export default function useEthers() {
const ethersProviderList = ['CoinbaseWallet', 'MetaMask', 'BraveWallet', 'TrustWallet']
const ethersProviderList = ['BraveWallet', 'CoinbaseWallet', 'MetaMask', 'OkxWallet', 'TrustWallet']

async function addEthersNetwork (providerString: ProviderString, network: any) {
const provider = availableProviders.value[providerString as keyof BrowserProviders]
Expand Down Expand Up @@ -264,11 +259,13 @@ export default function useEthers() {

function getBrowserProvider(providerString: ProviderString) {
if (providerString === 'MetaMask' || providerString === 'CoinbaseWallet') {
return defaultProviders[providerString] as EthersProvider
return window.ethereum?.providerMap?.get(providerString) || undefined
} else if (providerString === 'BraveWallet') {
return getBraveWallet()
} else if (providerString === 'TrustWallet') {
return getTrustWallet()
} else if (providerString === 'OkxWallet') {
return getOkxWallet()
}
}

Expand All @@ -281,6 +278,12 @@ function getBraveWallet() {
}
}

function getOkxWallet() {
const { okxwallet } = window as any
const { okexchain } = window as any
return okxwallet || okexchain
}

function getTrustWallet() {
const { ethereum } = window as any
const providers = ethereum?.providers
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/interfaces/BrowserProviders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface BrowserProviders {
BraveWallet?: EthersProvider
CoinbaseWallet?: EthersProvider
MetaMask?: EthersProvider
OkxWallet?: EthersProvider
TrustWallet?: EthersProvider
// Phantom?: any // TODO: Fix this.
}

0 comments on commit 97de2d9

Please sign in to comment.