@rango-dev/provider-walletconnect-2 0.7.1-next.1 → 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/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 type { PairingTypes, SessionTypes, SignClientTypes } from '@walletconnect/types';
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
  *
@@ -1 +1 @@
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,CA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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;;;IAgBlE;AAED,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,eAAe,CAAC,aAAa,CAAC;IACnC,UAAU,EAAE,YAAY,CAAC,UAAU,CAAC;CACrC,CAAC;;;IAeH"}
@@ -1,6 +1,7 @@
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';
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';
4
5
  declare class COSMOSSigner implements GenericSigner<CosmosTransaction> {
5
6
  private client;
6
7
  private session;
@@ -1 +1 @@
1
- {"version":3,"file":"cosmos.d.ts","sourceRoot":"","sources":["../../src/signers/cosmos.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,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C;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.1-next.1",
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.14.1-next.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",
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 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
-
1
+ import { WalletState } from '@rango-dev/wallets-shared';
6
2
  import { Networks } from '@rango-dev/wallets-shared';
7
- import { WalletConnectModal } from '@walletconnect/modal';
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: WalletConnectModal;
19
+ let web3Modal: Web3Modal;
22
20
  export function createModalInstance(projectId: string) {
23
21
  if (!web3Modal) {
24
- web3Modal = new WalletConnectModal({
22
+ web3Modal = new Web3Modal({
25
23
  projectId,
26
24
  themeMode: 'light',
25
+ walletConnectVersion: 2,
27
26
  themeVariables: {
28
- '--wcm-z-index': '999999999',
27
+ '--w3m-z-index': '999999999',
29
28
  },
30
29
  });
31
30
  }
32
31
  }
33
- export function getModal(): WalletConnectModal {
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
- const firstIndex = 0;
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 type { ConnectParams, CreateSessionParams, WCInstance } from './types';
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 type {
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
- 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
- });
80
+ getModal().openModal({ uri, standaloneChains });
93
81
  }
94
82
 
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;
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
- * 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
- */
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],
@@ -1,20 +1,20 @@
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';
1
+ import { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
+ import { SessionTypes } from '@walletconnect/types';
10
3
  import { AccountId, ChainId } from 'caip';
11
- import { formatDirectSignDoc, stringifySignDocValues } from 'cosmos-wallet';
12
- import { SignerError, SignerErrorCode } from 'rango-types';
13
-
4
+ import type { GenericSigner } from 'rango-types';
5
+ import { SignerError, CosmosTransaction, SignerErrorCode } from 'rango-types';
14
6
  import { CosmosRPCMethods, NAMESPACES } from '../constants';
15
-
7
+ import { getsignedTx, manipulateMsg } from '@rango-dev/signer-cosmos';
8
+ import {
9
+ AminoSignResponse,
10
+ BroadcastMode,
11
+ makeSignDoc,
12
+ } from '@cosmjs/launchpad';
16
13
  import { sendTx } from './helper';
17
14
  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,25 +60,22 @@ 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
- ...m,
63
+ ...manipulateMsg(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
- }
70
- if (!account_number) {
69
+ if (!account_number)
71
70
  throw SignerError.AssertionFailed(
72
71
  'account_number is undefined from server'
73
72
  );
74
- }
75
- if (!sequence) {
73
+ if (!sequence)
76
74
  throw SignerError.AssertionFailed('sequence is undefined from server');
77
- }
78
75
 
79
76
  if (signType === 'AMINO') {
80
77
  const signDoc = makeSignDoc(
81
- msgsWithoutType,
78
+ msgsWithoutType as any,
82
79
  fee as any,
83
80
  chainId,
84
81
  memo || undefined,
@@ -188,17 +185,15 @@ class COSMOSSigner implements GenericSigner<CosmosTransaction> {
188
185
  console.log({ result });
189
186
 
190
187
  return { hash: uint8ArrayToHex(result) };
191
- }
192
- throw new SignerError(
193
- SignerErrorCode.OPERATION_UNSUPPORTED,
194
- `Sign type for cosmos not supported, type: ${signType}`
195
- );
196
- } catch (err) {
197
- if (SignerError.isSignerError(err)) {
198
- throw err;
199
188
  } else {
200
- throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, err);
189
+ throw new SignerError(
190
+ SignerErrorCode.OPERATION_UNSUPPORTED,
191
+ `Sign type for cosmos not supported, type: ${signType}`
192
+ );
201
193
  }
194
+ } catch (err) {
195
+ if (SignerError.isSignerError(err)) throw err;
196
+ else throw new SignerError(SignerErrorCode.SEND_TX_ERROR, undefined, err);
202
197
  }
203
198
  }
204
199