Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion signers/signer-solana/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ export {
getSolanaRpcNodes,
simulateTransaction,
} from './utils/index.js';
export type { SolanaWeb3Signer } from './utils/index.js';
export type {
SolanaWeb3Signer,
SolanaExternalProvider,
} from './utils/index.js';
export { setSolanaSignerConfig } from './config.js';
18 changes: 18 additions & 0 deletions wallets/core/src/namespaces/solana/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,21 @@ export function connect(
);
};
}
export function canEagerConnect(instance: () => ProviderAPI) {
return async () => {
const solanaInstance = instance();

if (!solanaInstance) {
throw new Error(
'Trying to eagerly connect to your Solana wallet, but seems its instance is not available.'
);
}

try {
const result = await solanaInstance.connect({ onlyIfTrusted: true });
return !!result;
} catch {
return false;
}
};
}
4 changes: 2 additions & 2 deletions wallets/provider-all/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as leapCosmos from '@rango-dev/provider-leap-cosmos';
import { versions as ledger } from '@rango-dev/provider-ledger';
import * as mathwallet from '@rango-dev/provider-math-wallet';
import { versions as metamask } from '@rango-dev/provider-metamask';
import * as okx from '@rango-dev/provider-okx';
import { versions as okx } from '@rango-dev/provider-okx';
import { versions as phantom } from '@rango-dev/provider-phantom';
import { versions as rabby } from '@rango-dev/provider-rabby';
import * as ready from '@rango-dev/provider-ready';
Expand Down Expand Up @@ -117,7 +117,7 @@ export const allProviders = (
lazyProvider(legacyProviderImportsToVersionsInterface(cosmostation)),
lazyProvider(legacyProviderImportsToVersionsInterface(exodus)),
lazyProvider(legacyProviderImportsToVersionsInterface(mathwallet)),
lazyProvider(legacyProviderImportsToVersionsInterface(okx)),
okx,
lazyProvider(legacyProviderImportsToVersionsInterface(tokenpocket)),
lazyProvider(legacyProviderImportsToVersionsInterface(tomo)),
lazyProvider(legacyProviderImportsToVersionsInterface(halo)),
Expand Down
12 changes: 6 additions & 6 deletions wallets/provider-okx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"version": "0.52.0",
"license": "MIT",
"type": "module",
"source": "./src/index.ts",
"main": "./dist/index.js",
"source": "./src/mod.ts",
"main": "./dist/mod.js",
"exports": {
".": "./dist/index.js"
".": "./dist/mod.js"
},
"typings": "dist/index.d.ts",
"typings": "dist/mod.d.ts",
"files": [
"dist",
"src"
],
"scripts": {
"build": "node ../../scripts/build/command.mjs --path wallets/provider-okx",
"build": "node ../../scripts/build/command.mjs --path wallets/provider-okx --inputs src/mod.ts",
"ts-check": "tsc --declaration --emitDeclarationOnly -p ./tsconfig.json",
"clean": "rimraf dist",
"format": "prettier --write '{.,src}/**/*.{ts,tsx}'",
Expand All @@ -30,4 +30,4 @@
"publishConfig": {
"access": "public"
}
}
}
62 changes: 61 additions & 1 deletion wallets/provider-okx/readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,61 @@
# @rango-dev/provider-okx
# OKX Wallet
OKX Wallet integration for hub.
[Homepage](https://www.okx.com/web3) | [Docs](https://www.okx.com/web3/build/docs)

More about implementation status can be found [here](../readme.md).

## Implementation notes/limitations

### Group

#### ✅ Solana
- Fully supported in this integration.
- No known limitations.

---

#### ⚠️ EVM
Supported networks :
- Ethereum
- BSC
- Polygon
- Fantom
- Arbitrum
- Optimism
- Cronos
- Boba
- Gnosis
- Moonbeam
- Moonriver
- Harmony
- Avalanche C-Chain


#### 🚧 Cosmos
The wallet supports Cosmos, but it is **not implemented** in the current integration.


#### 🚧 TON
The wallet supports TON, but it is **not implemented** in the current integration.


#### 🚧 Sui
The wallet supports Sui, but it is **not implemented** in the current integration.


#### 🚧 UTXO Chains
The wallet supports UTXO-based networks, but they are **not implemented** in the current integration.

### Feature

#### ⚠️ Disconnect
After a dApp is disconnected, it **cannot reconnect automatically** unless the user also manually disconnects from the wallet itself.

#### ⚠️ Switch Account
Switching accounts from the wallet interface **is not reflected in the dApp**.
The previously connected account remains active until the user performs a **full disconnect and reconnect**.


---

More wallet information can be found in [readme.md](../readme.md).
68 changes: 68 additions & 0 deletions wallets/provider-okx/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { type ProviderMetadata } from '@rango-dev/wallets-core';
import { LegacyNetworks } from '@rango-dev/wallets-core/legacy';
import { type BlockchainMeta, solanaBlockchain } from 'rango-types';

import getSigners from './signer.js';
import { getInstanceOrThrow } from './utils.js';

export const WALLET_ID = 'okx';
export const OKX_WALLET_SUPPORTED_CHAINS = [
LegacyNetworks.ETHEREUM,
LegacyNetworks.BSC,
LegacyNetworks.POLYGON,
LegacyNetworks.FANTOM,
LegacyNetworks.ARBITRUM,
LegacyNetworks.OPTIMISM,
LegacyNetworks.CRONOS,
LegacyNetworks.BOBA,
LegacyNetworks.GNOSIS,
LegacyNetworks.MOONBEAM,
LegacyNetworks.MOONRIVER,
LegacyNetworks.HARMONY,
LegacyNetworks.AVAX_CCHAIN,
];

export const metadata: ProviderMetadata = {
name: 'OKX',
icon: 'https://raw.githubusercontent.com/rango-exchange/assets/main/wallets/okx/icon.svg',
extensions: {
chrome:
'https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',
brave:
'https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge',
firefox: 'https://addons.mozilla.org/en-US/firefox/addon/okexwallet',
homepage: 'https://www.okx.com/web3',
},
properties: [
{
name: 'namespaces',
value: {
selection: 'multiple',
data: [
{
label: 'EVM',
value: 'EVM',
id: 'ETH',
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
allBlockchains.filter((blockchainMeta) =>
OKX_WALLET_SUPPORTED_CHAINS.includes(
blockchainMeta.name as LegacyNetworks
)
),
},
{
label: 'Solana',
value: 'Solana',
id: 'SOLANA',
getSupportedChains: (allBlockchains: BlockchainMeta[]) =>
solanaBlockchain(allBlockchains),
},
],
},
},
{
name: 'signers',
value: { getSigners: async () => getSigners(getInstanceOrThrow()) },
},
],
};
55 changes: 0 additions & 55 deletions wallets/provider-okx/src/helpers.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { LegacyProviderInterface } from '@rango-dev/wallets-core/legacy';
import type {
CanEagerConnect,
CanSwitchNetwork,
Expand All @@ -14,18 +15,16 @@ import {
canSwitchNetworkToEvm,
chooseInstance,
getEvmAccounts,
getSolanaAccounts,
Networks,
switchNetworkForEvm,
WalletTypes,
} from '@rango-dev/wallets-shared';
import { isEvmBlockchain } from 'rango-types';

import {
getSolanaAccounts,
okx_instance,
OKX_WALLET_SUPPORTED_CHAINS,
} from './helpers.js';
import signer from './signer.js';
import { OKX_WALLET_SUPPORTED_CHAINS } from '../constants.js';
import signer from '../signer.js';
import { okx } from '../utils.js';

const WALLET = WalletTypes.OKX;

Expand All @@ -34,20 +33,22 @@ export const config = {
defaultNetwork: Networks.ETHEREUM,
};

export const getInstance = okx_instance;
export const getInstance = okx;
export const connect: Connect = async ({ instance, meta }) => {
let results: ProviderConnectResult[] = [];
const results: ProviderConnectResult[] = [];

const evm_instance = chooseInstance(instance, meta, Networks.ETHEREUM);
const evmInstance = chooseInstance(instance, meta, Networks.ETHEREUM);

if (evm_instance) {
const evm = await getEvmAccounts(evm_instance);
results.push(evm);
if (evmInstance) {
const evmResults = await getEvmAccounts(evmInstance);
results.push(evmResults);
}

const solanaResults = await getSolanaAccounts(instance);

results = [...results, ...solanaResults];
results.push(
...(Array.isArray(solanaResults) ? solanaResults : [solanaResults])
);

return results;
};
Expand All @@ -60,8 +61,14 @@ export const subscribe: Subscribe = ({ instance, updateAccounts, meta }) => {
.find((blockchain) => blockchain.name === Networks.ETHEREUM)?.chainId;

updateAccounts(addresses, eth_chainId);
const [{ accounts, chainId }] = await getSolanaAccounts(instance);
updateAccounts(accounts, chainId);
const solanaResults = await getSolanaAccounts(instance);
const resultsArray = Array.isArray(solanaResults)
? solanaResults
: [solanaResults];

resultsArray.forEach(({ chainId, accounts }) => {
updateAccounts(accounts, chainId);
});
};
ethInstance?.on?.('accountsChanged', handleEvmAccountsChanged);

Expand All @@ -84,7 +91,10 @@ export const switchNetwork: SwitchNetwork = async (options) => {

export const canSwitchNetworkTo: CanSwitchNetwork = canSwitchNetworkToEvm;

export const getSigners: (provider: any) => Promise<SignerFactory> = signer;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Provider = any;
export const getSigners: (provider: Provider) => Promise<SignerFactory> =
signer;

export const canEagerConnect: CanEagerConnect = async ({ instance, meta }) => {
const evm_instance = chooseInstance(instance, meta, Networks.ETHEREUM);
Expand Down Expand Up @@ -112,3 +122,16 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
OKX_WALLET_SUPPORTED_CHAINS.includes(blockchainMeta.name as Networks)
),
});
const buildLegacyProvider: () => LegacyProviderInterface = () => ({
config,
getInstance,
connect,
subscribe,
switchNetwork,
canSwitchNetworkTo,
getSigners,
getWalletInfo,
canEagerConnect,
});

export { buildLegacyProvider };
12 changes: 12 additions & 0 deletions wallets/provider-okx/src/mod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { defineVersions } from '@rango-dev/wallets-core/utils';

import { buildLegacyProvider } from './legacy/index.js';
import { buildProvider } from './provider.js';

const versions = () =>
defineVersions()
.version('0.0.0', buildLegacyProvider())
.version('1.0.0', buildProvider())
.build();

export { versions };
Loading