@rango-dev/provider-walletconnect-2 0.6.0 → 0.7.1-next.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 +0 -1
- package/src/helpers.ts +21 -17
- package/src/session.ts +30 -13
package/dist/session.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
1
2
|
import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
|
|
2
|
-
import { PairingTypes, SessionTypes, SignClientTypes } from '@walletconnect/types';
|
|
3
|
-
import { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
3
|
+
import type { PairingTypes, SessionTypes, SignClientTypes } from '@walletconnect/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":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAe9B,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,CA+C9B;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;;;IAkBlE;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.7.1-next.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.14.0",
|
|
27
|
+
"@rango-dev/signer-evm": "^0.14.0",
|
|
28
|
+
"@rango-dev/signer-solana": "^0.14.0",
|
|
29
|
+
"@rango-dev/wallets-shared": "^0.14.0",
|
|
30
30
|
"@solana/web3.js": "^1.67.2",
|
|
31
31
|
"@walletconnect/encoding": "^1.0.2",
|
|
32
|
+
"@walletconnect/modal": "^2.6.1",
|
|
32
33
|
"@walletconnect/sign-client": "^2.9.1",
|
|
33
34
|
"@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,7 +3,6 @@
|
|
|
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.
|
|
7
6
|
- 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`.
|
|
8
7
|
- Signing a transaction on Metamask goes through an internal error.
|
|
9
8
|
- 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,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { CosmosMeta } from './types';
|
|
2
|
+
import type { WalletState } from '@rango-dev/wallets-shared';
|
|
3
|
+
import type { ProposalTypes } from '@walletconnect/types';
|
|
4
|
+
import type { BlockchainMeta } from 'rango-types';
|
|
5
|
+
|
|
2
6
|
import { Networks } from '@rango-dev/wallets-shared';
|
|
3
|
-
import {
|
|
7
|
+
import { WalletConnectModal } from '@walletconnect/modal';
|
|
4
8
|
import { ChainId } from 'caip';
|
|
5
|
-
import {
|
|
6
|
-
import { Web3Modal } from '@web3modal/standalone';
|
|
9
|
+
import { cosmosBlockchains, evmBlockchains } from 'rango-types';
|
|
7
10
|
|
|
8
11
|
import {
|
|
9
12
|
DEFAULT_COSMOS_METHODS,
|
|
@@ -14,22 +17,20 @@ import {
|
|
|
14
17
|
NAMESPACES,
|
|
15
18
|
} from './constants';
|
|
16
19
|
import { getLastSession } from './session';
|
|
17
|
-
import { CosmosMeta } from './types';
|
|
18
20
|
|
|
19
|
-
let web3Modal:
|
|
21
|
+
let web3Modal: WalletConnectModal;
|
|
20
22
|
export function createModalInstance(projectId: string) {
|
|
21
23
|
if (!web3Modal) {
|
|
22
|
-
web3Modal = new
|
|
24
|
+
web3Modal = new WalletConnectModal({
|
|
23
25
|
projectId,
|
|
24
26
|
themeMode: 'light',
|
|
25
|
-
walletConnectVersion: 2,
|
|
26
27
|
themeVariables: {
|
|
27
|
-
'--
|
|
28
|
+
'--wcm-z-index': '999999999',
|
|
28
29
|
},
|
|
29
30
|
});
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
|
-
export function getModal():
|
|
33
|
+
export function getModal(): WalletConnectModal {
|
|
33
34
|
return web3Modal;
|
|
34
35
|
}
|
|
35
36
|
|
|
@@ -162,14 +163,15 @@ export async function simulateRequest(
|
|
|
162
163
|
|
|
163
164
|
if (chainId) {
|
|
164
165
|
return chainId;
|
|
165
|
-
} else {
|
|
166
|
-
const firstChain = standaloneChains[0];
|
|
167
|
-
const chainId = new ChainId(firstChain);
|
|
168
|
-
return chainId.reference;
|
|
169
166
|
}
|
|
170
|
-
|
|
171
|
-
|
|
167
|
+
|
|
168
|
+
const firstIndex = 0;
|
|
169
|
+
const firstChain = standaloneChains[firstIndex];
|
|
170
|
+
const firstChainId = new ChainId(firstChain);
|
|
171
|
+
return firstChainId.reference;
|
|
172
172
|
}
|
|
173
|
+
|
|
174
|
+
throw new Error(`Couldn't find any chain on namespace`);
|
|
173
175
|
}
|
|
174
176
|
throw new Error('Dissallowed method:', params);
|
|
175
177
|
}
|
|
@@ -182,7 +184,9 @@ export function getChainIdByNetworkName(
|
|
|
182
184
|
(blockchain) => blockchain.name === network
|
|
183
185
|
);
|
|
184
186
|
const chainIdInHex = targetBlockchain?.chainId;
|
|
185
|
-
if (!chainIdInHex)
|
|
187
|
+
if (!chainIdInHex) {
|
|
188
|
+
return undefined;
|
|
189
|
+
}
|
|
186
190
|
|
|
187
191
|
const chainId = String(parseInt(chainIdInHex));
|
|
188
192
|
|
package/src/session.ts
CHANGED
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Networks, timeout } from '@rango-dev/wallets-shared';
|
|
1
|
+
import type { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
3
2
|
import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
|
|
4
|
-
import {
|
|
3
|
+
import type {
|
|
5
4
|
PairingTypes,
|
|
6
5
|
SessionTypes,
|
|
7
6
|
SignClientTypes,
|
|
8
7
|
} from '@walletconnect/types';
|
|
8
|
+
|
|
9
|
+
import { Networks, timeout } from '@rango-dev/wallets-shared';
|
|
9
10
|
import { getSdkError } from '@walletconnect/utils';
|
|
11
|
+
import { AccountId } from 'caip';
|
|
10
12
|
|
|
13
|
+
import { PING_TIMEOUT } from './constants';
|
|
11
14
|
import {
|
|
12
15
|
generateOptionalNamespace,
|
|
13
16
|
generateRequiredNamespace,
|
|
@@ -15,8 +18,6 @@ import {
|
|
|
15
18
|
getModal,
|
|
16
19
|
solanaChainIdToNetworkName,
|
|
17
20
|
} from './helpers';
|
|
18
|
-
import { PING_TIMEOUT } from './constants';
|
|
19
|
-
import { ConnectParams, CreateSessionParams, WCInstance } from './types';
|
|
20
21
|
|
|
21
22
|
export function getLastSession(client: SignClient) {
|
|
22
23
|
return client.session.values[client.session.values.length - 1];
|
|
@@ -66,6 +67,7 @@ export async function createSession(
|
|
|
66
67
|
});
|
|
67
68
|
|
|
68
69
|
// Open QRCode modal if a URI was returned (i.e. we're not connecting an existing pairing).
|
|
70
|
+
let onCloseModal;
|
|
69
71
|
if (uri) {
|
|
70
72
|
// Create a flat array of all requested chains across namespaces.
|
|
71
73
|
const allNamespaces = {
|
|
@@ -77,14 +79,27 @@ export async function createSession(
|
|
|
77
79
|
.map((namespace) => namespace.chains)
|
|
78
80
|
.flat() as string[];
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
const modal = getModal();
|
|
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
|
+
});
|
|
81
93
|
}
|
|
82
94
|
|
|
83
|
-
const session =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
95
|
+
const session = approval();
|
|
96
|
+
|
|
97
|
+
if (onCloseModal) {
|
|
98
|
+
const result = await Promise.race([session, onCloseModal]);
|
|
99
|
+
// We know onClose only reject a modal and never returns a value.
|
|
100
|
+
return result as SessionTypes.Struct;
|
|
101
|
+
}
|
|
102
|
+
return await session;
|
|
88
103
|
} finally {
|
|
89
104
|
getModal().closeModal();
|
|
90
105
|
}
|
|
@@ -266,8 +281,10 @@ export function getAccountsFromSession(session: SessionTypes.Struct) {
|
|
|
266
281
|
.flat()
|
|
267
282
|
.map((account) => {
|
|
268
283
|
const { address, chainId } = new AccountId(account);
|
|
269
|
-
|
|
270
|
-
|
|
284
|
+
/*
|
|
285
|
+
* Note: Solana has a specific ID, we need to convert it back to network name.
|
|
286
|
+
* It will return the chain id itslef if it's not that specific ID.
|
|
287
|
+
*/
|
|
271
288
|
const chain = solanaChainIdToNetworkName(chainId.reference);
|
|
272
289
|
return {
|
|
273
290
|
accounts: [address],
|