@rango-dev/provider-walletconnect-2 0.8.1-next.1 → 0.8.1-next.3

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.
@@ -1,7 +1,7 @@
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 { EvmTransaction } from 'rango-types/lib/api/main';
1
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
+ import type { SessionTypes } from '@walletconnect/types';
3
+ import type { EvmTransaction } from 'rango-types/lib/api/main';
4
+ import { type GenericSigner } from 'rango-types';
5
5
  declare class EVMSigner implements GenericSigner<EvmTransaction> {
6
6
  private client;
7
7
  private session;
@@ -1 +1 @@
1
- {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/signers/evm.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAM1D,cAAM,SAAU,YAAW,aAAa,CAAC,cAAc,CAAC;IACtD,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAsB;gBAEzB,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM;IAK/C,WAAW,CACtB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,CAAC;IA8BZ,aAAa,CACjB,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAoB5B,OAAO,CAAC,iCAAiC;CAsD1C;AAED,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"evm.d.ts","sourceRoot":"","sources":["../../src/signers/evm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,8CAA8C,CAAC;AAC/E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAK/D,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAMjD,cAAM,SAAU,YAAW,aAAa,CAAC,cAAc,CAAC;IACtD,OAAO,CAAC,MAAM,CAAa;IAC3B,OAAO,CAAC,OAAO,CAAsB;gBAEzB,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,YAAY,CAAC,MAAM;IAK/C,WAAW,CACtB,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,CAAC;IAqCZ,aAAa,CACjB,EAAE,EAAE,cAAc,EAClB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAsB5B,OAAO,CAAC,iCAAiC;CAwD1C;AAED,eAAe,SAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/provider-walletconnect-2",
3
- "version": "0.8.1-next.1",
3
+ "version": "0.8.1-next.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -24,7 +24,7 @@
24
24
  "@keplr-wallet/cosmos": "^0.9.12",
25
25
  "@keplr-wallet/simple-fetch": "^0.12.14",
26
26
  "@rango-dev/signer-cosmos": "^0.15.0",
27
- "@rango-dev/signer-evm": "^0.15.0",
27
+ "@rango-dev/signer-evm": "^0.15.1-next.0",
28
28
  "@rango-dev/signer-solana": "^0.15.0",
29
29
  "@rango-dev/wallets-shared": "^0.15.1-next.1",
30
30
  "@solana/web3.js": "^1.67.2",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import {
2
- WalletTypes,
1
+ import type { WCInstance } from './types';
2
+ import type {
3
3
  CanSwitchNetwork,
4
4
  Connect,
5
5
  Disconnect,
@@ -9,19 +9,13 @@ import {
9
9
  WalletConfig,
10
10
  WalletInfo,
11
11
  } from '@rango-dev/wallets-shared';
12
- import { SignerFactory, BlockchainMeta, evmBlockchains } from 'rango-types';
13
12
  import type { ISignClient } from '@walletconnect/types';
13
+ import type { BlockchainMeta, SignerFactory } from 'rango-types';
14
+
15
+ import { WalletTypes } from '@rango-dev/wallets-shared';
14
16
  import Client from '@walletconnect/sign-client';
17
+ import { evmBlockchains } from 'rango-types';
15
18
 
16
- import signer from './signer';
17
- import {
18
- disconnectSessions,
19
- cleanupSingleSession,
20
- getAccountsFromEvent,
21
- getAccountsFromSession,
22
- tryConnect,
23
- trySwitchByCreatingNewSession,
24
- } from './session';
25
19
  import {
26
20
  DEFAULT_APP_METADATA,
27
21
  DEFAULT_NETWORK,
@@ -29,7 +23,15 @@ import {
29
23
  RELAY_URL,
30
24
  } from './constants';
31
25
  import { createModalInstance, simulateRequest } from './helpers';
32
- import type { WCInstance } from './types';
26
+ import {
27
+ cleanupSingleSession,
28
+ disconnectSessions,
29
+ getAccountsFromEvent,
30
+ getAccountsFromSession,
31
+ tryConnect,
32
+ trySwitchByCreatingNewSession,
33
+ } from './session';
34
+ import signer from './signer';
33
35
 
34
36
  const WALLET = WalletTypes.WALLET_CONNECT_2;
35
37
 
@@ -55,9 +57,9 @@ export const getInstance: GetInstance = async (options) => {
55
57
  const { currentProvider, getState, meta } = options;
56
58
 
57
59
  /*
58
- Create a new pair, if exists use the pair,
59
- Or use the already created one.
60
- */
60
+ *Create a new pair, if exists use the pair,
61
+ *Or use the already created one.
62
+ */
61
63
  let provider: ISignClient;
62
64
  if (!currentProvider) {
63
65
  if (!envs.WC_PROJECT_ID) {
@@ -78,7 +80,8 @@ export const getInstance: GetInstance = async (options) => {
78
80
  return {
79
81
  client: provider,
80
82
  session: null,
81
- request: (params: any) => simulateRequest(params, provider, meta, getState),
83
+ request: async (params: any) =>
84
+ simulateRequest(params, provider, meta, getState),
82
85
  };
83
86
  };
84
87
 
@@ -137,7 +140,7 @@ export const subscribe: Subscribe = ({
137
140
 
138
141
  client.on('session_delete', async (event) => {
139
142
  console.log('[WC2] your wallet has requested to delete session.', event);
140
- cleanupSingleSession(client, event.topic);
143
+ void cleanupSingleSession(client, event.topic);
141
144
  disconnect();
142
145
  });
143
146
  };
@@ -172,7 +175,7 @@ export const disconnect: Disconnect = async ({ instance }) => {
172
175
  const { client } = instance as WCInstance;
173
176
 
174
177
  if (client) {
175
- disconnectSessions(client);
178
+ void disconnectSessions(client);
176
179
  }
177
180
  };
178
181
 
@@ -184,7 +187,7 @@ export const getWalletInfo: (allBlockChains: BlockchainMeta[]) => WalletInfo = (
184
187
  const evms = evmBlockchains(allBlockChains);
185
188
  return {
186
189
  name: 'WalletConnect',
187
- img: 'https://raw.githubusercontent.com/rango-exchange/rango-types/main/assets/icons/wallets/walletconnect.svg',
190
+ img: 'https://raw.githubusercontent.com/rango-exchange/rango-assets/main/wallets/walletconnect/icon.svg',
188
191
  installLink: '',
189
192
  color: '#b2dbff',
190
193
  supportedChains: evms,
@@ -1,9 +1,12 @@
1
- import { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
- import { SessionTypes } from '@walletconnect/types';
3
- import { AccountId, ChainId } from 'caip';
4
- import type { GenericSigner } from 'rango-types';
5
- import { EvmTransaction } from 'rango-types/lib/api/main';
1
+ import type { SignClient } from '@walletconnect/sign-client/dist/types/client';
2
+ import type { SessionTypes } from '@walletconnect/types';
3
+ import type { EvmTransaction } from 'rango-types/lib/api/main';
4
+
5
+ import { cleanEvmError } from '@rango-dev/signer-evm';
6
6
  import * as encoding from '@walletconnect/encoding';
7
+ import { AccountId, ChainId } from 'caip';
8
+ import { type GenericSigner } from 'rango-types';
9
+
7
10
  import { EthereumRPCMethods, NAMESPACES } from '../constants';
8
11
 
9
12
  const NAMESPACE_NAME = NAMESPACES.ETHEREUM;
@@ -35,18 +38,25 @@ class EVMSigner implements GenericSigner<EvmTransaction> {
35
38
 
36
39
  const params = [hexMsg, address];
37
40
 
38
- // Send message to wallet (using relayer)
39
- const signature: string = await this.client.request({
40
- topic: this.session.topic,
41
- chainId: caipChainId.toString(),
42
- request: {
43
- method: EthereumRPCMethods.PERSONAL_SIGN,
44
- params,
45
- },
46
- });
41
+ let signature: string;
42
+ try {
43
+ // Send message to wallet (using relayer)
44
+ signature = await this.client.request({
45
+ topic: this.session.topic,
46
+ chainId: caipChainId.toString(),
47
+ request: {
48
+ method: EthereumRPCMethods.PERSONAL_SIGN,
49
+ params,
50
+ },
51
+ });
52
+ } catch (error) {
53
+ throw cleanEvmError(error);
54
+ }
47
55
 
48
- // TODO: We can also verify the signature here
49
- // Check web-examples: dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx
56
+ /*
57
+ * TODO: We can also verify the signature here
58
+ * Check web-examples: dapps/react-dapp-v2/src/contexts/JsonRpcContext.tsx
59
+ */
50
60
 
51
61
  return signature;
52
62
  }
@@ -60,19 +70,21 @@ class EVMSigner implements GenericSigner<EvmTransaction> {
60
70
  address,
61
71
  chainId,
62
72
  });
63
-
64
- const signedTx: string = await this.client.request({
65
- topic: this.session.topic,
66
- chainId: requestedFor.caipChainId,
67
- request: {
68
- method: EthereumRPCMethods.SEND_TRANSACTION,
69
- params: [tx],
70
- },
71
- });
72
-
73
- return {
74
- hash: signedTx,
75
- };
73
+ try {
74
+ const hash: string = await this.client.request({
75
+ topic: this.session.topic,
76
+ chainId: requestedFor.caipChainId,
77
+ request: {
78
+ method: EthereumRPCMethods.SEND_TRANSACTION,
79
+ params: [tx],
80
+ },
81
+ });
82
+ return {
83
+ hash,
84
+ };
85
+ } catch (error) {
86
+ throw cleanEvmError(error);
87
+ }
76
88
  }
77
89
 
78
90
  private isNetworkAndAccountExistInSession(requestedFor: {
@@ -88,8 +100,10 @@ class EVMSigner implements GenericSigner<EvmTransaction> {
88
100
  );
89
101
  }
90
102
 
91
- // TODO: We need to make sure we are using a single format for chain ids, it should be hex or number.
92
- // This is a quick fix for evm.
103
+ /*
104
+ * TODO: We need to make sure we are using a single format for chain ids, it should be hex or number.
105
+ * This is a quick fix for evm.
106
+ */
93
107
  const chainIdNumber = chainId.startsWith('0x')
94
108
  ? String(parseInt(chainId))
95
109
  : chainId;