diff --git a/js_api/src/index.ts b/js_api/src/index.ts index 9bcb4ce63..f1f763cfa 100644 --- a/js_api/src/index.ts +++ b/js_api/src/index.ts @@ -1,4 +1,5 @@ import { WsProvider, ApiPromise } from "@polkadot/api"; +import type { RegistryTypes } from '@polkadot/types-codec/types'; import { subscribeMessage, getNetworkConst, getNetworkProperties } from "./service/setting"; import keyring from "./service/keyring"; import account from "./service/account"; @@ -32,8 +33,9 @@ async function connectAll(nodes: string[]) { * connect to a specific node. * * @param {string} nodeEndpoint + * @param {RegistryTypes} types for ApiOptions */ -async function connect(nodes: string[]) { +async function connect(nodes: string[], types: RegistryTypes | undefined = undefined) { (window).api = undefined; return new Promise(async (resolve, reject) => { @@ -41,6 +43,7 @@ async function connect(nodes: string[]) { try { const res = await ApiPromise.create({ provider: wsProvider, + types: types, }); if (!(window).api) { (window).api = res; diff --git a/lib/api/api.dart b/lib/api/api.dart index b1892379f..21e4b9911 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -91,9 +91,10 @@ class PolkawalletApi { /// connect to a list of nodes, return null if connect failed. Future connectNode( - Keyring keyringStorage, List nodes) async { + Keyring keyringStorage, List nodes, + [Map? types]) async { _connectedNode = null; - final NetworkParams? res = await service.webView!.connectNode(nodes); + final NetworkParams? res = await service.webView!.connectNode(nodes, types); if (res != null) { _connectedNode = res; diff --git a/lib/plugin/index.dart b/lib/plugin/index.dart index 72ac4ab02..de3cc4e1c 100644 --- a/lib/plugin/index.dart +++ b/lib/plugin/index.dart @@ -155,10 +155,15 @@ abstract class PolkawalletPlugin implements PolkawalletPluginBase { /// 3. subscribe balances & set balancesStore. Future start(Keyring keyring, {List? nodes, + Map? types, KeyringEVM? keyringEVM, NetworkParams? nodeEVM}) async { if (nodeEVM == null) { - final res = await sdk.api.connectNode(keyring, nodes ?? nodeList); + final res = await sdk.api.connectNode( + keyring, + nodes ?? nodeList, + types, + ); if (res == null) return null; keyring.setSS58(res.ss58); diff --git a/lib/service/webViewRunner.dart b/lib/service/webViewRunner.dart index 11a027c77..2185d29fc 100644 --- a/lib/service/webViewRunner.dart +++ b/lib/service/webViewRunner.dart @@ -227,16 +227,21 @@ class WebViewRunner { return c.future; } - Future connectNode(List nodes) async { + Future connectNode( + List nodes, + Map? types, + ) async { final isAvatarSupport = (await evalJavascript( 'settings.connectAll ? {}:null', wrapPromise: false)) != null; + + final nodesEncoded = jsonEncode(nodes.map((e) => e.endpoint).toList()); + final typesEncoded = types != null ? ', ${jsonEncode(types)}' : ''; + final dynamic res = await (isAvatarSupport - ? evalJavascript( - 'settings.connectAll(${jsonEncode(nodes.map((e) => e.endpoint).toList())})') - : evalJavascript( - 'settings.connect(${jsonEncode(nodes.map((e) => e.endpoint).toList())})')); + ? evalJavascript('settings.connectAll($nodesEncoded$typesEncoded)') + : evalJavascript('settings.connect($nodesEncoded$typesEncoded)')); if (res != null) { final index = nodes.indexWhere((e) => e.endpoint!.trim() == res.trim()); if (_webViewOOMReload) {