@openocean.finance/widget-sdk
Version:
OpenOcean Any-to-Any Cross-Chain-Swap SDK
40 lines • 1.59 kB
JavaScript
import { ChainType } from '@openocean.finance/widget-types';
import { parseAccount } from 'viem/accounts';
import { getAction } from 'viem/utils';
import { config } from '../../config.js';
export async function getCapabilities(client, parameters = {}) {
const { account = client.account, chainId } = parameters;
const account_ = account ? parseAccount(account) : undefined;
const capabilities_raw = await client.request({
method: 'wallet_getCapabilities',
params: [account_?.address],
}, {
dedupe: true,
retryCount: 0,
});
const capabilities = {};
for (const [key, value] of Object.entries(capabilities_raw)) {
capabilities[Number(key)] = value;
}
return (typeof chainId === 'number' ? capabilities[chainId] : capabilities);
}
export async function isBatchingSupported({ client, chainId, }) {
const _client = client ??
(await config.getProvider(ChainType.EVM)?.getWalletClient?.());
if (!_client) {
throw new Error('WalletClient is not provided.');
}
try {
const capabilities = await getAction(_client, getCapabilities, 'getCapabilities')({ chainId });
return (capabilities?.atomicBatch?.supported ||
capabilities?.atomic?.status === 'supported' ||
capabilities?.atomic?.status === 'ready' ||
false);
}
catch {
// If the wallet does not support getCapabilities or the call fails,
// we assume that atomic batch is not supported
return false;
}
}
//# sourceMappingURL=isBatchingSupported.js.map