@rango-dev/provider-walletconnect-2 0.7.0 → 0.7.1-next.1

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/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
  *
@@ -1 +1 @@
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,E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AMG;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"}
@@ -1,7 +1,6 @@
1
- import { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
- import { SessionTypes } from '@walletconnect/types';
3
- import type { GenericSigner } from 'rango-types';
4
- import { CosmosTransaction } from 'rango-types';
1
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
+ import type { SessionTypes } from '@walletconnect/types';
3
+ import type { CosmosTransaction, GenericSigner } from 'rango-types';
5
4
  declare class COSMOSSigner implements GenericSigner<CosmosTransaction> {
6
5
  private client;
7
6
  private session;
@@ -1 +1 @@
1
- {"version":3,"file":"cosmos.d.ts","sourceRoot":"","sources":["../../src/signers/cosmos.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAA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;AAED,eAAe,YAAY,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-walletconnect-2",
3
- "version": "0.7.0",
3
+ "version": "0.7.1-next.1",
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.14.0",
26
+ "@rango-dev/signer-cosmos": "^0.14.1-next.0",
27
27
  "@rango-dev/signer-evm": "^0.14.0",
28
28
  "@rango-dev/signer-solana": "^0.14.0",
29
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 { WalletState } from '@rango-dev/wallets-shared';
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 { ProposalTypes } from '@walletconnect/types';
7
+ import { WalletConnectModal } from '@walletconnect/modal';
4
8
  import { ChainId } from 'caip';
5
- import { BlockchainMeta, cosmosBlockchains, evmBlockchains } from 'rango-types';
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: Web3Modal;
21
+ let web3Modal: WalletConnectModal;
20
22
  export function createModalInstance(projectId: string) {
21
23
  if (!web3Modal) {
22
- web3Modal = new Web3Modal({
24
+ web3Modal = new WalletConnectModal({
23
25
  projectId,
24
26
  themeMode: 'light',
25
- walletConnectVersion: 2,
26
27
  themeVariables: {
27
- '--w3m-z-index': '999999999',
28
+ '--wcm-z-index': '999999999',
28
29
  },
29
30
  });
30
31
  }
31
32
  }
32
- export function getModal(): Web3Modal {
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
- } else {
171
- throw new Error(`Couldn't find any chain on namespace`);
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) return undefined;
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 { AccountId } from 'caip';
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
- getModal().openModal({ uri, standaloneChains });
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 = await approval();
84
- return session;
85
- } catch (e) {
86
- console.error(e);
87
- throw e;
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
- // 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.
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],
@@ -1,20 +1,20 @@
1
- import { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
- import { SessionTypes } from '@walletconnect/types';
1
+ import type { AminoSignResponse } from '@cosmjs/launchpad';
2
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
3
+ import type { SessionTypes } from '@walletconnect/types';
4
+ import type { CosmosTransaction, GenericSigner } from 'rango-types';
5
+
6
+ import { BroadcastMode, makeSignDoc } from '@cosmjs/launchpad';
7
+ import { cosmos } from '@keplr-wallet/cosmos';
8
+ import { getsignedTx } from '@rango-dev/signer-cosmos';
9
+ import { uint8ArrayToHex } from '@rango-dev/wallets-shared';
3
10
  import { AccountId, ChainId } from 'caip';
4
- import type { GenericSigner } from 'rango-types';
5
- import { SignerError, CosmosTransaction, SignerErrorCode } from 'rango-types';
11
+ import { formatDirectSignDoc, stringifySignDocValues } from 'cosmos-wallet';
12
+ import { SignerError, SignerErrorCode } from 'rango-types';
13
+
6
14
  import { CosmosRPCMethods, NAMESPACES } from '../constants';
7
- import { getsignedTx, manipulateMsg } from '@rango-dev/signer-cosmos';
8
- import {
9
- AminoSignResponse,
10
- BroadcastMode,
11
- makeSignDoc,
12
- } from '@cosmjs/launchpad';
15
+
13
16
  import { sendTx } from './helper';
14
17
  import { supportedChains } from './mock';
15
- import { uint8ArrayToHex } from '@rango-dev/wallets-shared';
16
- import { cosmos } from '@keplr-wallet/cosmos';
17
- import { formatDirectSignDoc, stringifySignDocValues } from 'cosmos-wallet';
18
18
 
19
19
  const NAMESPACE_NAME = NAMESPACES.COSMOS;
20
20
  type DirectSignResponse = {
@@ -60,22 +60,25 @@ class COSMOSSigner implements GenericSigner<CosmosTransaction> {
60
60
  const { memo, sequence, account_number, chainId, msgs, fee, signType } =
61
61
  tx.data;
62
62
  const msgsWithoutType = msgs.map((m) => ({
63
- ...manipulateMsg(m),
63
+ ...m,
64
64
  __type: undefined,
65
65
  '@type': undefined,
66
66
  }));
67
- if (!chainId)
67
+ if (!chainId) {
68
68
  throw SignerError.AssertionFailed('chainId is undefined from server');
69
- if (!account_number)
69
+ }
70
+ if (!account_number) {
70
71
  throw SignerError.AssertionFailed(
71
72
  'account_number is undefined from server'
72
73
  );
73
- if (!sequence)
74
+ }
75
+ if (!sequence) {
74
76
  throw SignerError.AssertionFailed('sequence is undefined from server');
77
+ }
75
78
 
76
79
  if (signType === 'AMINO') {
77
80
  const signDoc = makeSignDoc(
78
- msgsWithoutType as any,
81
+ msgsWithoutType,
79
82
  fee as any,
80
83
  chainId,
81
84
  memo || undefined,
@@ -185,15 +188,17 @@ class COSMOSSigner implements GenericSigner<CosmosTransaction> {
185
188
  console.log({ result });
186
189
 
187
190
  return { hash: uint8ArrayToHex(result) };
188
- } else {
189
- throw new SignerError(
190
- SignerErrorCode.OPERATION_UNSUPPORTED,
191
- `Sign type for cosmos not supported, type: ${signType}`
192
- );
193
191
  }
192
+ throw new SignerError(
193
+ SignerErrorCode.OPERATION_UNSUPPORTED,
194
+ `Sign type for cosmos not supported, type: ${signType}`
195
+ );
194
196
  } catch (err) {
195
- if (SignerError.isSignerError(err)) throw err;
196
- else throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, err);
197
+ if (SignerError.isSignerError(err)) {
198
+ throw err;
199
+ } else {
200
+ throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, err);
201
+ }
197
202
  }
198
203
  }
199
204