@rango-dev/provider-walletconnect-2 0.7.1-next.0 → 0.8.0
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/CHANGELOG.md +4 -0
- package/dist/helpers.d.ts +5 -5
- package/dist/helpers.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +3 -3
- package/dist/session.d.ts +2 -2
- package/dist/session.d.ts.map +1 -1
- package/package.json +6 -6
- package/readme.md +1 -0
- package/src/helpers.ts +17 -21
- package/src/session.ts +13 -30
package/dist/session.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
2
1
|
import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
|
|
3
|
-
import
|
|
2
|
+
import { PairingTypes, SessionTypes, SignClientTypes } from '@walletconnect/types';
|
|
3
|
+
import { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
4
4
|
export declare function getLastSession(client: SignClient): SessionTypes.Struct;
|
|
5
5
|
/**
|
|
6
6
|
*
|
package/dist/session.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../src/session.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAW9B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAEzE,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,uBAEhD;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,YAAY,CAAC,MAAM,GAC3B,OAAO,CAAC,YAAY,CAAC,MAAM,GAAG,SAAS,CAAC,CAW1C;AAED;;;;;;;GAOG;AACH,wBAAsB,aAAa,CACjC,MAAM,EAAE,UAAU,EAClB,OAAO,EAAE,mBAAmB,GAC3B,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAiC9B;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,UAAU,GACjB,YAAY,CAAC,MAAM,GAAG,SAAS,CAMjC;AAED;;;;GAIG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,UAAU,EAClB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAkC9B;AAED;;;;GAIG;AACH,wBAAsB,6BAA6B,CACjD,QAAQ,EAAE,UAAU,EACpB,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CA0B9B;AAoBD;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,iBAiB3E;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,UAAU,mBAwB1D;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,YAAY,CAAC,MAAM;;;IAgBlE;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC;IACnC,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC;CACrC,CAAC;;;IAeH"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/provider-walletconnect-2",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -23,15 +23,15 @@
|
|
|
23
23
|
"@cosmjs/launchpad": "^0.27.1",
|
|
24
24
|
"@keplr-wallet/cosmos": "^0.9.12",
|
|
25
25
|
"@keplr-wallet/simple-fetch": "^0.12.14",
|
|
26
|
-
"@rango-dev/signer-cosmos": "^0.
|
|
27
|
-
"@rango-dev/signer-evm": "^0.
|
|
28
|
-
"@rango-dev/signer-solana": "^0.
|
|
29
|
-
"@rango-dev/wallets-shared": "^0.
|
|
26
|
+
"@rango-dev/signer-cosmos": "^0.15.0",
|
|
27
|
+
"@rango-dev/signer-evm": "^0.15.0",
|
|
28
|
+
"@rango-dev/signer-solana": "^0.15.0",
|
|
29
|
+
"@rango-dev/wallets-shared": "^0.15.0",
|
|
30
30
|
"@solana/web3.js": "^1.67.2",
|
|
31
31
|
"@walletconnect/encoding": "^1.0.2",
|
|
32
|
-
"@walletconnect/modal": "^2.6.1",
|
|
33
32
|
"@walletconnect/sign-client": "^2.9.1",
|
|
34
33
|
"@walletconnect/utils": "^2.9.1",
|
|
34
|
+
"@web3modal/standalone": "^2.4.3",
|
|
35
35
|
"bs58": "^5.0.0",
|
|
36
36
|
"caip": "^1.1.0",
|
|
37
37
|
"cosmos-wallet": "^1.2.0",
|
package/readme.md
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
## Known issues
|
|
5
5
|
|
|
6
|
+
- Trust wallet doesn't return optional namespaces other than evms on its response. So Solana and Cosmos will be ask for connect in wallet but we can not use them.
|
|
6
7
|
- Using Private key to import wallets other than `Ethereum` will be problematic. Because it imports only a single blockchain and we are by default asking for `Ethereum`.
|
|
7
8
|
- Signing a transaction on Metamask goes through an internal error.
|
|
8
9
|
- We couldn't update exist session during a bug in `@walletconnect/utils`, so we are creating new session for accessing to new chains.
|
package/src/helpers.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { WalletState } from '@rango-dev/wallets-shared';
|
|
3
|
-
import type { ProposalTypes } from '@walletconnect/types';
|
|
4
|
-
import type { BlockchainMeta } from 'rango-types';
|
|
5
|
-
|
|
1
|
+
import { WalletState } from '@rango-dev/wallets-shared';
|
|
6
2
|
import { Networks } from '@rango-dev/wallets-shared';
|
|
7
|
-
import {
|
|
3
|
+
import { ProposalTypes } from '@walletconnect/types';
|
|
8
4
|
import { ChainId } from 'caip';
|
|
9
|
-
import { cosmosBlockchains, evmBlockchains } from 'rango-types';
|
|
5
|
+
import { BlockchainMeta, cosmosBlockchains, evmBlockchains } from 'rango-types';
|
|
6
|
+
import { Web3Modal } from '@web3modal/standalone';
|
|
10
7
|
|
|
11
8
|
import {
|
|
12
9
|
DEFAULT_COSMOS_METHODS,
|
|
@@ -17,20 +14,22 @@ import {
|
|
|
17
14
|
NAMESPACES,
|
|
18
15
|
} from './constants';
|
|
19
16
|
import { getLastSession } from './session';
|
|
17
|
+
import { CosmosMeta } from './types';
|
|
20
18
|
|
|
21
|
-
let web3Modal:
|
|
19
|
+
let web3Modal: Web3Modal;
|
|
22
20
|
export function createModalInstance(projectId: string) {
|
|
23
21
|
if (!web3Modal) {
|
|
24
|
-
web3Modal = new
|
|
22
|
+
web3Modal = new Web3Modal({
|
|
25
23
|
projectId,
|
|
26
24
|
themeMode: 'light',
|
|
25
|
+
walletConnectVersion: 2,
|
|
27
26
|
themeVariables: {
|
|
28
|
-
'--
|
|
27
|
+
'--w3m-z-index': '999999999',
|
|
29
28
|
},
|
|
30
29
|
});
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
|
-
export function getModal():
|
|
32
|
+
export function getModal(): Web3Modal {
|
|
34
33
|
return web3Modal;
|
|
35
34
|
}
|
|
36
35
|
|
|
@@ -163,15 +162,14 @@ export async function simulateRequest(
|
|
|
163
162
|
|
|
164
163
|
if (chainId) {
|
|
165
164
|
return chainId;
|
|
165
|
+
} else {
|
|
166
|
+
const firstChain = standaloneChains[0];
|
|
167
|
+
const chainId = new ChainId(firstChain);
|
|
168
|
+
return chainId.reference;
|
|
166
169
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const firstChain = standaloneChains[firstIndex];
|
|
170
|
-
const firstChainId = new ChainId(firstChain);
|
|
171
|
-
return firstChainId.reference;
|
|
170
|
+
} else {
|
|
171
|
+
throw new Error(`Couldn't find any chain on namespace`);
|
|
172
172
|
}
|
|
173
|
-
|
|
174
|
-
throw new Error(`Couldn't find any chain on namespace`);
|
|
175
173
|
}
|
|
176
174
|
throw new Error('Dissallowed method:', params);
|
|
177
175
|
}
|
|
@@ -184,9 +182,7 @@ export function getChainIdByNetworkName(
|
|
|
184
182
|
(blockchain) => blockchain.name === network
|
|
185
183
|
);
|
|
186
184
|
const chainIdInHex = targetBlockchain?.chainId;
|
|
187
|
-
if (!chainIdInHex)
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
185
|
+
if (!chainIdInHex) return undefined;
|
|
190
186
|
|
|
191
187
|
const chainId = String(parseInt(chainIdInHex));
|
|
192
188
|
|
package/src/session.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { AccountId } from 'caip';
|
|
2
|
+
import { Networks, timeout } from '@rango-dev/wallets-shared';
|
|
2
3
|
import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
|
|
3
|
-
import
|
|
4
|
+
import {
|
|
4
5
|
PairingTypes,
|
|
5
6
|
SessionTypes,
|
|
6
7
|
SignClientTypes,
|
|
7
8
|
} from '@walletconnect/types';
|
|
8
|
-
|
|
9
|
-
import { Networks, timeout } from '@rango-dev/wallets-shared';
|
|
10
9
|
import { getSdkError } from '@walletconnect/utils';
|
|
11
|
-
import { AccountId } from 'caip';
|
|
12
10
|
|
|
13
|
-
import { PING_TIMEOUT } from './constants';
|
|
14
11
|
import {
|
|
15
12
|
generateOptionalNamespace,
|
|
16
13
|
generateRequiredNamespace,
|
|
@@ -18,6 +15,8 @@ import {
|
|
|
18
15
|
getModal,
|
|
19
16
|
solanaChainIdToNetworkName,
|
|
20
17
|
} from './helpers';
|
|
18
|
+
import { PING_TIMEOUT } from './constants';
|
|
19
|
+
import { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
21
20
|
|
|
22
21
|
export function getLastSession(client: SignClient) {
|
|
23
22
|
return client.session.values[client.session.values.length - 1];
|
|
@@ -67,7 +66,6 @@ export async function createSession(
|
|
|
67
66
|
});
|
|
68
67
|
|
|
69
68
|
// Open QRCode modal if a URI was returned (i.e. we're not connecting an existing pairing).
|
|
70
|
-
let onCloseModal;
|
|
71
69
|
if (uri) {
|
|
72
70
|
// Create a flat array of all requested chains across namespaces.
|
|
73
71
|
const allNamespaces = {
|
|
@@ -79,27 +77,14 @@ export async function createSession(
|
|
|
79
77
|
.map((namespace) => namespace.chains)
|
|
80
78
|
.flat() as string[];
|
|
81
79
|
|
|
82
|
-
|
|
83
|
-
void modal.openModal({ uri, standaloneChains });
|
|
84
|
-
|
|
85
|
-
onCloseModal = new Promise((_, reject) => {
|
|
86
|
-
modal.subscribeModal((state) => {
|
|
87
|
-
// the modal was closed so reject the promise
|
|
88
|
-
if (!state.open) {
|
|
89
|
-
reject(new Error('Modal has been closed.'));
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
});
|
|
80
|
+
getModal().openModal({ uri, standaloneChains });
|
|
93
81
|
}
|
|
94
82
|
|
|
95
|
-
const session = approval();
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return result as SessionTypes.Struct;
|
|
101
|
-
}
|
|
102
|
-
return await session;
|
|
83
|
+
const session = await approval();
|
|
84
|
+
return session;
|
|
85
|
+
} catch (e) {
|
|
86
|
+
console.error(e);
|
|
87
|
+
throw e;
|
|
103
88
|
} finally {
|
|
104
89
|
getModal().closeModal();
|
|
105
90
|
}
|
|
@@ -281,10 +266,8 @@ export function getAccountsFromSession(session: SessionTypes.Struct) {
|
|
|
281
266
|
.flat()
|
|
282
267
|
.map((account) => {
|
|
283
268
|
const { address, chainId } = new AccountId(account);
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
* It will return the chain id itslef if it's not that specific ID.
|
|
287
|
-
*/
|
|
269
|
+
// Note: Solana has a specific ID, we need to convert it back to network name.
|
|
270
|
+
// It will return the chain id itslef if it's not that specific ID.
|
|
288
271
|
const chain = solanaChainIdToNetworkName(chainId.reference);
|
|
289
272
|
return {
|
|
290
273
|
accounts: [address],
|