@luno-kit/react 0.0.12-beta.2 → 0.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-7BEPQQMD.cjs +2 -0
- package/dist/chunk-7BEPQQMD.cjs.map +1 -0
- package/dist/{chunk-JJEEWE3N.cjs → chunk-NNF3FZ3W.cjs} +2 -2
- package/dist/chunk-NNF3FZ3W.cjs.map +1 -0
- package/dist/chunk-QCEMRLYF.js +2 -0
- package/dist/chunk-QCEMRLYF.js.map +1 -0
- package/dist/{chunk-62JXEP3B.js → chunk-ZBVBO5KX.js} +2 -2
- package/dist/chunk-ZBVBO5KX.js.map +1 -0
- package/dist/index.cjs +2 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/state-BFuwUpY4.d.cts +34 -0
- package/dist/state-BFuwUpY4.d.ts +34 -0
- package/dist/types/index.cjs +1 -1
- package/dist/types/index.d.cts +3 -30
- package/dist/types/index.d.ts +3 -30
- package/dist/types/index.js +1 -1
- package/dist/utils/index.cjs +1 -1
- package/dist/utils/index.d.cts +3 -2
- package/dist/utils/index.d.ts +3 -2
- package/dist/utils/index.js +1 -1
- package/package.json +2 -2
- package/dist/chunk-62JXEP3B.js.map +0 -1
- package/dist/chunk-A6LYVRYZ.js +0 -2
- package/dist/chunk-A6LYVRYZ.js.map +0 -1
- package/dist/chunk-CMKLBFDC.cjs +0 -2
- package/dist/chunk-CMKLBFDC.cjs.map +0 -1
- package/dist/chunk-JJEEWE3N.cjs.map +0 -1
package/dist/types/index.d.ts
CHANGED
|
@@ -1,34 +1,7 @@
|
|
|
1
|
-
import { Config, Connector, Account, HexString, Chain } from '@luno-kit/core/types';
|
|
2
1
|
export * from '@luno-kit/core/types';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
declare enum ConnectionStatus {
|
|
6
|
-
Disconnected = "disconnected",
|
|
7
|
-
Connecting = "connecting",
|
|
8
|
-
Disconnecting = "disconnecting",
|
|
9
|
-
Connected = "connected"
|
|
10
|
-
}
|
|
11
|
-
interface LunoState {
|
|
12
|
-
config?: Config;
|
|
13
|
-
status: ConnectionStatus;
|
|
14
|
-
activeConnector?: Connector;
|
|
15
|
-
accounts: Account[];
|
|
16
|
-
account?: Account;
|
|
17
|
-
setAccount: (accountOrPubkey?: Account | HexString) => Promise<void>;
|
|
18
|
-
currentChainId?: string;
|
|
19
|
-
currentChain?: Chain;
|
|
20
|
-
currentApi?: LegacyClient;
|
|
21
|
-
isApiReady: boolean;
|
|
22
|
-
apiError: Error | null;
|
|
23
|
-
_setConfig: (config: Config) => Promise<void>;
|
|
24
|
-
connect: (connectorId: string, targetChainId?: string) => Promise<void>;
|
|
25
|
-
disconnect: () => Promise<void>;
|
|
26
|
-
switchChain: (newChainId: string) => Promise<void>;
|
|
27
|
-
_setApi: (api?: LegacyClient) => void;
|
|
28
|
-
_setIsApiReady: (isApiReady: boolean) => void;
|
|
29
|
-
_setApiError: (error: Error | null) => void;
|
|
30
|
-
}
|
|
2
|
+
export { C as ConnectionStatus, a as LunoState } from '../state-BFuwUpY4.js';
|
|
3
|
+
import 'dedot';
|
|
31
4
|
|
|
32
5
|
type TxStatus = 'idle' | 'signing' | 'pending' | 'success' | 'failed';
|
|
33
6
|
|
|
34
|
-
export
|
|
7
|
+
export type { TxStatus };
|
package/dist/types/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{a as ConnectionStatus}from'../chunk-
|
|
1
|
+
export{a as ConnectionStatus}from'../chunk-ZBVBO5KX.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/utils/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var chunk7BEPQQMD_cjs=require('../chunk-7BEPQQMD.cjs');Object.defineProperty(exports,"convertAddress",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.d}});Object.defineProperty(exports,"createApi",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.a}});Object.defineProperty(exports,"defineChain",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.e}});Object.defineProperty(exports,"formatAddress",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.f}});Object.defineProperty(exports,"formatBalance",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.g}});Object.defineProperty(exports,"formatBalanceWithUnit",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.h}});Object.defineProperty(exports,"getChainToken",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.i}});Object.defineProperty(exports,"getExplorerUrl",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.j}});Object.defineProperty(exports,"getPublicKey",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.k}});Object.defineProperty(exports,"getReadableDispatchError",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.b}});Object.defineProperty(exports,"isMobileDevice",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.l}});Object.defineProperty(exports,"isSameAddress",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.m}});Object.defineProperty(exports,"isValidAddress",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.n}});Object.defineProperty(exports,"sleep",{enumerable:true,get:function(){return chunk7BEPQQMD_cjs.c}});//# sourceMappingURL=index.cjs.map
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/utils/index.d.cts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { convertAddress, defineChain, formatAddress, formatBalance, formatBalanceWithUnit, getChainToken, getExplorerUrl, getPublicKey, isMobileDevice, isSameAddress, isValidAddress } from '@luno-kit/core/utils';
|
|
2
|
-
import { LegacyClient } from 'dedot';
|
|
3
2
|
import { Config } from '@luno-kit/core/types';
|
|
3
|
+
import { L as LunoClient } from '../state-BFuwUpY4.cjs';
|
|
4
|
+
import { LegacyClient } from 'dedot';
|
|
4
5
|
import { DispatchError } from 'dedot/codecs';
|
|
5
6
|
|
|
6
7
|
interface CreateApiOptions {
|
|
7
8
|
config: Config;
|
|
8
9
|
chainId: string;
|
|
9
10
|
}
|
|
10
|
-
declare const createApi: ({ config, chainId }: CreateApiOptions) => Promise<
|
|
11
|
+
declare const createApi: ({ config, chainId }: CreateApiOptions) => Promise<LunoClient>;
|
|
11
12
|
|
|
12
13
|
declare function getReadableDispatchError(api: LegacyClient, dispatchError: DispatchError): string;
|
|
13
14
|
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
export { convertAddress, defineChain, formatAddress, formatBalance, formatBalanceWithUnit, getChainToken, getExplorerUrl, getPublicKey, isMobileDevice, isSameAddress, isValidAddress } from '@luno-kit/core/utils';
|
|
2
|
-
import { LegacyClient } from 'dedot';
|
|
3
2
|
import { Config } from '@luno-kit/core/types';
|
|
3
|
+
import { L as LunoClient } from '../state-BFuwUpY4.js';
|
|
4
|
+
import { LegacyClient } from 'dedot';
|
|
4
5
|
import { DispatchError } from 'dedot/codecs';
|
|
5
6
|
|
|
6
7
|
interface CreateApiOptions {
|
|
7
8
|
config: Config;
|
|
8
9
|
chainId: string;
|
|
9
10
|
}
|
|
10
|
-
declare const createApi: ({ config, chainId }: CreateApiOptions) => Promise<
|
|
11
|
+
declare const createApi: ({ config, chainId }: CreateApiOptions) => Promise<LunoClient>;
|
|
11
12
|
|
|
12
13
|
declare function getReadableDispatchError(api: LegacyClient, dispatchError: DispatchError): string;
|
|
13
14
|
|
package/dist/utils/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export{d as convertAddress,a as createApi,e as defineChain,f as formatAddress,g as formatBalance,h as formatBalanceWithUnit,i as getChainToken,j as getExplorerUrl,k as getPublicKey,b as getReadableDispatchError,l as isMobileDevice,m as isSameAddress,n as isValidAddress,c as sleep}from'../chunk-
|
|
1
|
+
export{d as convertAddress,a as createApi,e as defineChain,f as formatAddress,g as formatBalance,h as formatBalanceWithUnit,i as getChainToken,j as getExplorerUrl,k as getPublicKey,b as getReadableDispatchError,l as isMobileDevice,m as isSameAddress,n as isValidAddress,c as sleep}from'../chunk-QCEMRLYF.js';//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@luno-kit/react",
|
|
3
3
|
"description": "React Hooks and Provider for Luno, enabling easy Polkadot wallet interactions in React applications.",
|
|
4
|
-
"version": "0.0.12
|
|
4
|
+
"version": "0.0.12",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"@dedot/chaintypes": "0.152.0",
|
|
52
52
|
"dedot": "0.16.0",
|
|
53
53
|
"zustand": "5.0.4",
|
|
54
|
-
"@luno-kit/core": "0.0.12
|
|
54
|
+
"@luno-kit/core": "0.0.12"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@tanstack/react-query": "5.81.5",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/state.ts"],"names":["ConnectionStatus"],"mappings":"kCAIO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAAA,CAAA,aAAe,cAAA,CACfA,CAAAA,CAAA,UAAA,CAAa,YAAA,CACbA,EAAA,aAAA,CAAgB,eAAA,CAChBA,CAAAA,CAAA,SAAA,CAAY,YAJFA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA","file":"chunk-62JXEP3B.js","sourcesContent":["import type { HexString } from '@luno-kit/core/types';\nimport type { LegacyClient } from 'dedot';\nimport type { Account, Chain, Config, Connector } from '.';\n\nexport enum ConnectionStatus {\n Disconnected = 'disconnected',\n Connecting = 'connecting',\n Disconnecting = 'disconnecting',\n Connected = 'connected',\n}\n\nexport interface LunoState {\n config?: Config;\n\n status: ConnectionStatus;\n\n activeConnector?: Connector;\n\n accounts: Account[];\n account?: Account;\n setAccount: (accountOrPubkey?: Account | HexString) => Promise<void>;\n\n currentChainId?: string;\n currentChain?: Chain;\n currentApi?: LegacyClient;\n isApiReady: boolean;\n apiError: Error | null;\n\n _setConfig: (config: Config) => Promise<void>;\n\n connect: (connectorId: string, targetChainId?: string) => Promise<void>;\n disconnect: () => Promise<void>;\n\n switchChain: (newChainId: string) => Promise<void>;\n\n _setApi: (api?: LegacyClient) => void;\n\n _setIsApiReady: (isApiReady: boolean) => void;\n _setApiError: (error: Error | null) => void;\n}\n"]}
|
package/dist/chunk-A6LYVRYZ.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
export{convertAddress as d,defineChain as e,formatAddress as f,formatBalance as g,formatBalanceWithUnit as h,getChainToken as i,getExplorerUrl as j,getPublicKey as k,isMobileDevice as l,isSameAddress as m,isValidAddress as n}from'@luno-kit/core/utils';import {wsProvider}from'@luno-kit/core';import {LegacyClient}from'dedot';var l=async({config:r,chainId:e})=>{let t=r.chains.find(n=>n.genesisHash===e),o=r.transports[e];if(!t||!o)throw new Error(`Configuration missing for chainId: ${e}`);let s={provider:wsProvider(o),cacheMetadata:r.cacheMetadata,metadata:r.metadata,scaledResponses:{...r.scaledResponses,...r.customTypes},runtimeApis:r.runtimeApis,cacheStorage:r.cacheStorage},i=new LegacyClient(s);try{await i.connect();let n=await i.rpc.chain_getBlockHash(0);if(n!==e)throw await i.disconnect(),new Error(`Chain genesis hash mismatch. Expected: ${e}, Got: ${n}. This might indicate connecting to the wrong network or incorrect chain configuration.`);return i}catch(n){throw new Error(`Failed to connect to ${t.name}: ${n?.message||n}`)}};function f(r,e){if(e.type==="Module")try{let t=r.registry.findErrorMeta(e);if(t){let{docs:o,name:a,pallet:s,fields:i,fieldCodecs:n}=t;return `[useSendTransaction]: ${s}.${a} error, ${o.join(" ")}`}return `[useSendTransaction]: Module Error (index: ${e.value.index}, error: ${e.value.error})`}catch(t){let{value:{error:o,index:a}}=e;return `[useSendTransaction]: Module Error (index: ${a}, error: ${o}) - Failed to decode: ${t instanceof Error?t.message:"Unknown error"}`}else if(e.type==="Token")return `[useSendTransaction]: Token Error: ${e.value}`;return "value"in e?`[useSendTransaction]: ${e.type} Error: ${e.value}`:`[useSendTransaction]: Error: ${e.type}`}var y=(r=1e3)=>new Promise(e=>setTimeout(e,r));export{l as a,f as b,y as c};//# sourceMappingURL=chunk-A6LYVRYZ.js.map
|
|
2
|
-
//# sourceMappingURL=chunk-A6LYVRYZ.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/createApi.ts","../src/utils/dispatchError.ts","../src/utils/sleep.ts"],"names":["createApi","config","chainId","chainConfig","c","transportConfig","apiOptions","wsProvider","newApi","LegacyClient","actualGenesisHash","error","getReadableDispatchError","api","dispatchError","errorMeta","docs","name","pallet","fields","fieldCodecs","e","index","sleep","ms","resolve"],"mappings":"qUASO,IAAMA,CAAAA,CAAY,MAAO,CAAE,MAAA,CAAAC,CAAAA,CAAQ,OAAA,CAAAC,CAAQ,CAAA,GAA+C,CAC/F,IAAMC,CAAAA,CAAcF,CAAAA,CAAO,MAAA,CAAO,IAAA,CAAMG,GAAMA,CAAAA,CAAE,WAAA,GAAgBF,CAAO,CAAA,CACjEG,CAAAA,CAAkBJ,CAAAA,CAAO,UAAA,CAAWC,CAAO,CAAA,CAEjD,GAAI,CAACC,CAAAA,EAAe,CAACE,CAAAA,CACnB,MAAM,IAAI,MAAM,CAAA,mCAAA,EAAsCH,CAAO,CAAA,CAAE,CAAA,CAKjE,IAAMI,CAAAA,CAAyB,CAC7B,QAAA,CAHeC,UAAAA,CAAWF,CAAe,CAAA,CAIzC,aAAA,CAAeJ,CAAAA,CAAO,aAAA,CACtB,QAAA,CAAUA,CAAAA,CAAO,SACjB,eAAA,CAAiB,CACf,GAAGA,CAAAA,C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CF,EAAc,KAAA,CAAM,KAAK,CAAA,SAAA,EAAYA,CAAAA,CAAc,KAAA,CAAM,KAAK,CAAA,CAAA,CACrH,CAAA,MAASO,CAAAA,CAAG,CACV,GAAM,CACJ,KAAA,CAAO,CAAE,KAAA,CAAAV,CAAAA,CAAO,MAAAW,CAAM,CACxB,CAAA,CAAIR,CAAAA,CAEJ,OAAO,CAAA,2CAAA,EAA8CQ,CAAK,CAAA,SAAA,EAAYX,CAAK,CAAA,sBAAA,EAAyBU,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,eAAe,CAAA,CACtJ,SACSP,CAAAA,CAAc,IAAA,GAAS,OAAA,CAChC,OAAO,CAAA,mCAAA,EAAsCA,CAAAA,CAAc,KAAK,CAAA,CAAA,CAGlE,OAAI,OAAA,GAAWA,CAAAA,CACN,CAAA,sBAAA,EAAyBA,CAAAA,CAAc,IAAI,CAAA,QAAA,EAAWA,CAAAA,CAAc,KAAK,CAAA,CAAA,CAG3E,CAAA,6BAAA,EAAgCA,CAAAA,CAAc,IAAI,CAAA,CAC3D,CC7BO,IAAMS,CAAAA,CAAQ,CAACC,CAAAA,CAAK,GAAA,GAClB,IAAI,OAAA,CAASC,CAAAA,EAAY,UAAA,CAAWA,CAAAA,CAASD,CAAE,CAAC","file":"chunk-A6LYVRYZ.js","sourcesContent":["import { wsProvider } from '@luno-kit/core';\nimport { type ApiOptions, LegacyClient } from 'dedot';\nimport type { Config } from '../types';\n\ninterface CreateApiOptions {\n config: Config;\n chainId: string;\n}\n\nexport const createApi = async ({ config, chainId }: CreateApiOptions): Promise<LegacyClient> => {\n const chainConfig = config.chains.find((c) => c.genesisHash === chainId);\n const transportConfig = config.transports[chainId];\n\n if (!chainConfig || !transportConfig) {\n throw new Error(`Configuration missing for chainId: ${chainId}`);\n }\n\n const provider = wsProvider(transportConfig);\n\n const apiOptions: ApiOptions = {\n provider,\n cacheMetadata: config.cacheMetadata,\n metadata: config.metadata,\n scaledResponses: {\n ...config.scaledResponses,\n ...config.customTypes,\n },\n runtimeApis: config.runtimeApis,\n cacheStorage: config.cacheStorage,\n };\n\n const newApi = new LegacyClient(apiOptions);\n\n try {\n await newApi.connect();\n\n const actualGenesisHash = await newApi.rpc.chain_getBlockHash(0);\n\n if (actualGenesisHash !== chainId) {\n await newApi.disconnect();\n throw new Error(\n `Chain genesis hash mismatch. Expected: ${chainId}, Got: ${actualGenesisHash}. ` +\n 'This might indicate connecting to the wrong network or incorrect chain configuration.'\n );\n }\n\n return newApi;\n } catch (error: any) {\n throw new Error(`Failed to connect to ${chainConfig.name}: ${error?.message || error}`);\n }\n};\n","import type { LegacyClient } from 'dedot';\nimport type { DispatchError } from 'dedot/codecs';\n\nexport function getReadableDispatchError(api: LegacyClient, dispatchError: DispatchError): string {\n if (dispatchError.type === 'Module') {\n try {\n const errorMeta = api.registry.findErrorMeta(dispatchError);\n if (errorMeta) {\n const { docs, name, pallet, fields, fieldCodecs } = errorMeta;\n return `[useSendTransaction]: ${pallet}.${name} error, ${docs.join(' ')}`;\n }\n\n return `[useSendTransaction]: Module Error (index: ${dispatchError.value.index}, error: ${dispatchError.value.error})`;\n } catch (e) {\n const {\n value: { error, index },\n } = dispatchError;\n\n return `[useSendTransaction]: Module Error (index: ${index}, error: ${error}) - Failed to decode: ${e instanceof Error ? e.message : 'Unknown error'}`;\n }\n } else if (dispatchError.type === 'Token') {\n return `[useSendTransaction]: Token Error: ${dispatchError.value}`;\n }\n\n if ('value' in dispatchError) {\n return `[useSendTransaction]: ${dispatchError.type} Error: ${dispatchError.value}`;\n }\n\n return `[useSendTransaction]: Error: ${dispatchError.type}`;\n}\n","export const sleep = (ms = 1000): Promise<void> => {\n return new Promise((resolve) => setTimeout(resolve, ms));\n};\n"]}
|
package/dist/chunk-CMKLBFDC.cjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
'use strict';var utils=require('@luno-kit/core/utils'),core=require('@luno-kit/core'),dedot=require('dedot');var l=async({config:r,chainId:e})=>{let t=r.chains.find(n=>n.genesisHash===e),o=r.transports[e];if(!t||!o)throw new Error(`Configuration missing for chainId: ${e}`);let s={provider:core.wsProvider(o),cacheMetadata:r.cacheMetadata,metadata:r.metadata,scaledResponses:{...r.scaledResponses,...r.customTypes},runtimeApis:r.runtimeApis,cacheStorage:r.cacheStorage},i=new dedot.LegacyClient(s);try{await i.connect();let n=await i.rpc.chain_getBlockHash(0);if(n!==e)throw await i.disconnect(),new Error(`Chain genesis hash mismatch. Expected: ${e}, Got: ${n}. This might indicate connecting to the wrong network or incorrect chain configuration.`);return i}catch(n){throw new Error(`Failed to connect to ${t.name}: ${n?.message||n}`)}};function f(r,e){if(e.type==="Module")try{let t=r.registry.findErrorMeta(e);if(t){let{docs:o,name:a,pallet:s,fields:i,fieldCodecs:n}=t;return `[useSendTransaction]: ${s}.${a} error, ${o.join(" ")}`}return `[useSendTransaction]: Module Error (index: ${e.value.index}, error: ${e.value.error})`}catch(t){let{value:{error:o,index:a}}=e;return `[useSendTransaction]: Module Error (index: ${a}, error: ${o}) - Failed to decode: ${t instanceof Error?t.message:"Unknown error"}`}else if(e.type==="Token")return `[useSendTransaction]: Token Error: ${e.value}`;return "value"in e?`[useSendTransaction]: ${e.type} Error: ${e.value}`:`[useSendTransaction]: Error: ${e.type}`}var y=(r=1e3)=>new Promise(e=>setTimeout(e,r));Object.defineProperty(exports,"d",{enumerable:true,get:function(){return utils.convertAddress}});Object.defineProperty(exports,"e",{enumerable:true,get:function(){return utils.defineChain}});Object.defineProperty(exports,"f",{enumerable:true,get:function(){return utils.formatAddress}});Object.defineProperty(exports,"g",{enumerable:true,get:function(){return utils.formatBalance}});Object.defineProperty(exports,"h",{enumerable:true,get:function(){return utils.formatBalanceWithUnit}});Object.defineProperty(exports,"i",{enumerable:true,get:function(){return utils.getChainToken}});Object.defineProperty(exports,"j",{enumerable:true,get:function(){return utils.getExplorerUrl}});Object.defineProperty(exports,"k",{enumerable:true,get:function(){return utils.getPublicKey}});Object.defineProperty(exports,"l",{enumerable:true,get:function(){return utils.isMobileDevice}});Object.defineProperty(exports,"m",{enumerable:true,get:function(){return utils.isSameAddress}});Object.defineProperty(exports,"n",{enumerable:true,get:function(){return utils.isValidAddress}});exports.a=l;exports.b=f;exports.c=y;//# sourceMappingURL=chunk-CMKLBFDC.cjs.map
|
|
2
|
-
//# sourceMappingURL=chunk-CMKLBFDC.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils/createApi.ts","../src/utils/dispatchError.ts","../src/utils/sleep.ts"],"names":["createApi","config","chainId","chainConfig","c","transportConfig","apiOptions","wsProvider","newApi","LegacyClient","actualGenesisHash","error","getReadableDispatchError","api","dispatchError","errorMeta","docs","name","pallet","fields","fieldCodecs","e","index","sleep","ms","resolve"],"mappings":"6GASO,IAAMA,CAAAA,CAAY,MAAO,CAAE,MAAA,CAAAC,CAAAA,CAAQ,OAAA,CAAAC,CAAQ,CAAA,GAA+C,CAC/F,IAAMC,CAAAA,CAAcF,CAAAA,CAAO,MAAA,CAAO,IAAA,CAAMG,GAAMA,CAAAA,CAAE,WAAA,GAAgBF,CAAO,CAAA,CACjEG,CAAAA,CAAkBJ,CAAAA,CAAO,UAAA,CAAWC,CAAO,CAAA,CAEjD,GAAI,CAACC,CAAAA,EAAe,CAACE,CAAAA,CACnB,MAAM,IAAI,MAAM,CAAA,mCAAA,EAAsCH,CAAO,CAAA,CAAE,CAAA,CAKjE,IAAMI,CAAAA,CAAyB,CAC7B,QAAA,CAHeC,eAAAA,CAAWF,CAAe,CAAA,CAIzC,aAAA,CAAeJ,CAAAA,CAAO,aAAA,CACtB,QAAA,CAAUA,CAAAA,CAAO,SACjB,eAAA,CAAiB,CACf,GAAGA,CAAAA,CAAO,eAAA,CACV,GAAGA,CAAAA,CAAO,WACZ,CAAA,CACA,WAAA,CAAaA,CAAAA,CAAO,WAAA,CACpB,YAAA,CAAcA,CAAAA,CAAO,YACvB,CAAA,CAEMO,EAAS,IAAIC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O,CAAE,KAAA,CAAAV,CAAAA,CAAO,MAAAW,CAAM,CACxB,CAAA,CAAIR,CAAAA,CAEJ,OAAO,CAAA,2CAAA,EAA8CQ,CAAK,CAAA,SAAA,EAAYX,CAAK,CAAA,sBAAA,EAAyBU,CAAAA,YAAa,KAAA,CAAQA,CAAAA,CAAE,OAAA,CAAU,eAAe,CAAA,CACtJ,SACSP,CAAAA,CAAc,IAAA,GAAS,OAAA,CAChC,OAAO,CAAA,mCAAA,EAAsCA,CAAAA,CAAc,KAAK,CAAA,CAAA,CAGlE,OAAI,OAAA,GAAWA,CAAAA,CACN,CAAA,sBAAA,EAAyBA,CAAAA,CAAc,IAAI,CAAA,QAAA,EAAWA,CAAAA,CAAc,KAAK,CAAA,CAAA,CAG3E,CAAA,6BAAA,EAAgCA,CAAAA,CAAc,IAAI,CAAA,CAC3D,CC7BO,IAAMS,CAAAA,CAAQ,CAACC,CAAAA,CAAK,GAAA,GAClB,IAAI,OAAA,CAASC,CAAAA,EAAY,UAAA,CAAWA,CAAAA,CAASD,CAAE,CAAC","file":"chunk-CMKLBFDC.cjs","sourcesContent":["import { wsProvider } from '@luno-kit/core';\nimport { type ApiOptions, LegacyClient } from 'dedot';\nimport type { Config } from '../types';\n\ninterface CreateApiOptions {\n config: Config;\n chainId: string;\n}\n\nexport const createApi = async ({ config, chainId }: CreateApiOptions): Promise<LegacyClient> => {\n const chainConfig = config.chains.find((c) => c.genesisHash === chainId);\n const transportConfig = config.transports[chainId];\n\n if (!chainConfig || !transportConfig) {\n throw new Error(`Configuration missing for chainId: ${chainId}`);\n }\n\n const provider = wsProvider(transportConfig);\n\n const apiOptions: ApiOptions = {\n provider,\n cacheMetadata: config.cacheMetadata,\n metadata: config.metadata,\n scaledResponses: {\n ...config.scaledResponses,\n ...config.customTypes,\n },\n runtimeApis: config.runtimeApis,\n cacheStorage: config.cacheStorage,\n };\n\n const newApi = new LegacyClient(apiOptions);\n\n try {\n await newApi.connect();\n\n const actualGenesisHash = await newApi.rpc.chain_getBlockHash(0);\n\n if (actualGenesisHash !== chainId) {\n await newApi.disconnect();\n throw new Error(\n `Chain genesis hash mismatch. Expected: ${chainId}, Got: ${actualGenesisHash}. ` +\n 'This might indicate connecting to the wrong network or incorrect chain configuration.'\n );\n }\n\n return newApi;\n } catch (error: any) {\n throw new Error(`Failed to connect to ${chainConfig.name}: ${error?.message || error}`);\n }\n};\n","import type { LegacyClient } from 'dedot';\nimport type { DispatchError } from 'dedot/codecs';\n\nexport function getReadableDispatchError(api: LegacyClient, dispatchError: DispatchError): string {\n if (dispatchError.type === 'Module') {\n try {\n const errorMeta = api.registry.findErrorMeta(dispatchError);\n if (errorMeta) {\n const { docs, name, pallet, fields, fieldCodecs } = errorMeta;\n return `[useSendTransaction]: ${pallet}.${name} error, ${docs.join(' ')}`;\n }\n\n return `[useSendTransaction]: Module Error (index: ${dispatchError.value.index}, error: ${dispatchError.value.error})`;\n } catch (e) {\n const {\n value: { error, index },\n } = dispatchError;\n\n return `[useSendTransaction]: Module Error (index: ${index}, error: ${error}) - Failed to decode: ${e instanceof Error ? e.message : 'Unknown error'}`;\n }\n } else if (dispatchError.type === 'Token') {\n return `[useSendTransaction]: Token Error: ${dispatchError.value}`;\n }\n\n if ('value' in dispatchError) {\n return `[useSendTransaction]: ${dispatchError.type} Error: ${dispatchError.value}`;\n }\n\n return `[useSendTransaction]: Error: ${dispatchError.type}`;\n}\n","export const sleep = (ms = 1000): Promise<void> => {\n return new Promise((resolve) => setTimeout(resolve, ms));\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types/state.ts"],"names":["ConnectionStatus"],"mappings":"uDAIO,IAAKA,CAAAA,CAAAA,CAAAA,CAAAA,GACVA,CAAAA,CAAA,aAAe,cAAA,CACfA,CAAAA,CAAA,UAAA,CAAa,YAAA,CACbA,EAAA,aAAA,CAAgB,eAAA,CAChBA,CAAAA,CAAA,SAAA,CAAY,YAJFA,CAAAA,CAAAA,EAAAA,CAAAA,EAAA,EAAA","file":"chunk-JJEEWE3N.cjs","sourcesContent":["import type { HexString } from '@luno-kit/core/types';\nimport type { LegacyClient } from 'dedot';\nimport type { Account, Chain, Config, Connector } from '.';\n\nexport enum ConnectionStatus {\n Disconnected = 'disconnected',\n Connecting = 'connecting',\n Disconnecting = 'disconnecting',\n Connected = 'connected',\n}\n\nexport interface LunoState {\n config?: Config;\n\n status: ConnectionStatus;\n\n activeConnector?: Connector;\n\n accounts: Account[];\n account?: Account;\n setAccount: (accountOrPubkey?: Account | HexString) => Promise<void>;\n\n currentChainId?: string;\n currentChain?: Chain;\n currentApi?: LegacyClient;\n isApiReady: boolean;\n apiError: Error | null;\n\n _setConfig: (config: Config) => Promise<void>;\n\n connect: (connectorId: string, targetChainId?: string) => Promise<void>;\n disconnect: () => Promise<void>;\n\n switchChain: (newChainId: string) => Promise<void>;\n\n _setApi: (api?: LegacyClient) => void;\n\n _setIsApiReady: (isApiReady: boolean) => void;\n _setApiError: (error: Error | null) => void;\n}\n"]}
|