@rango-dev/provider-walletconnect-2 0.1.1-next.1 → 0.1.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 +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;AAWzE,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,iBA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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.1.1-next.1",
3
+ "version": "0.1.1-next.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -21,8 +21,8 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@keplr-wallet/simple-fetch": "^0.12.14",
24
- "@rango-dev/signer-evm": "^0.8.1-next.3",
25
- "@rango-dev/wallets-shared": "^0.8.1-next.4",
24
+ "@rango-dev/signer-evm": "^0.8.1-next.4",
25
+ "@rango-dev/wallets-shared": "^0.8.1-next.7",
26
26
  "@walletconnect/encoding": "^1.0.2",
27
27
  "@walletconnect/sign-client": "^2.8.1",
28
28
  "@walletconnect/utils": "^2.9.1",
package/src/constants.ts CHANGED
@@ -79,5 +79,4 @@ export const DEFAULT_APP_METADATA = {
79
79
  icons: ['https://avatars.githubusercontent.com/u/37784886'],
80
80
  };
81
81
 
82
- export const PROJECT_ID = 'f5196d081862c6f2b81c04520ea9301c';
83
82
  export const RELAY_URL = 'wss://relay.walletconnect.com';
package/src/helpers.ts CHANGED
@@ -3,6 +3,7 @@ import { Networks } from '@rango-dev/wallets-shared';
3
3
  import { ProposalTypes } from '@walletconnect/types';
4
4
  import { ChainId } from 'caip';
5
5
  import { BlockchainMeta, cosmosBlockchains, evmBlockchains } from 'rango-types';
6
+ import { Web3Modal } from '@web3modal/standalone';
6
7
 
7
8
  import {
8
9
  DEFAULT_COSMOS_METHODS,
@@ -15,6 +16,20 @@ import {
15
16
  import { getLastSession } from './session';
16
17
  import { CosmosMeta } from './types';
17
18
 
19
+ let web3Modal: Web3Modal;
20
+ export function createModalInstance(projectId: string) {
21
+ if (!web3Modal) {
22
+ web3Modal = new Web3Modal({
23
+ projectId,
24
+ themeMode: 'light',
25
+ walletConnectVersion: 2,
26
+ });
27
+ }
28
+ }
29
+ export function getModal(): Web3Modal {
30
+ return web3Modal;
31
+ }
32
+
18
33
  type FinalNamespaces = {
19
34
  [key in NAMESPACES]?: ProposalTypes.BaseRequiredNamespace;
20
35
  };
package/src/index.ts CHANGED
@@ -26,14 +26,24 @@ import {
26
26
  DEFAULT_APP_METADATA,
27
27
  DEFAULT_NETWORK,
28
28
  EthereumEvents,
29
- PROJECT_ID,
30
29
  RELAY_URL,
31
30
  } from './constants';
32
- import { simulateRequest } from './helpers';
31
+ import { createModalInstance, simulateRequest } from './helpers';
33
32
  import type { WCInstance } from './types';
34
33
 
35
34
  const WALLET = WalletTypes.WALLET_CONNECT_2;
36
35
 
36
+ // TODO: In version 2, It will be moved to constructor.
37
+ type Enviroments = Record<string, string>;
38
+ let envs: Enviroments = {
39
+ WC_PROJECT_ID: '',
40
+ };
41
+ export const init = (enviroments: Enviroments) => {
42
+ envs = enviroments;
43
+
44
+ createModalInstance(envs.WC_PROJECT_ID);
45
+ };
46
+
37
47
  export const config: WalletConfig = {
38
48
  type: WALLET,
39
49
  checkInstallation: false,
@@ -50,9 +60,15 @@ export const getInstance: GetInstance = async (options) => {
50
60
  */
51
61
  let provider: ISignClient;
52
62
  if (!currentProvider) {
63
+ if (!envs.WC_PROJECT_ID) {
64
+ throw new Error(
65
+ 'You need to set `WC_PROJECT_ID` in Wallet Connect provider.'
66
+ );
67
+ }
68
+
53
69
  provider = await Client.init({
54
70
  relayUrl: RELAY_URL,
55
- projectId: PROJECT_ID,
71
+ projectId: envs.WC_PROJECT_ID,
56
72
  metadata: DEFAULT_APP_METADATA,
57
73
  });
58
74
  } else {
package/src/session.ts CHANGED
@@ -6,27 +6,18 @@ import {
6
6
  SessionTypes,
7
7
  SignClientTypes,
8
8
  } from '@walletconnect/types';
9
- import { Web3Modal } from '@web3modal/standalone';
10
9
  import { getSdkError } from '@walletconnect/utils';
11
10
 
12
11
  import {
13
12
  generateOptionalNamespace,
14
13
  generateRequiredNamespace,
15
14
  getChainIdByNetworkName,
15
+ getModal,
16
16
  solanaChainIdToNetworkName,
17
17
  } from './helpers';
18
- import { PING_TIMEOUT, PROJECT_ID } from './constants';
18
+ import { PING_TIMEOUT } from './constants';
19
19
  import { ConnectParams, CreateSessionParams, WCInstance } from './types';
20
20
 
21
- /**
22
- * Create a Web3Modal instance
23
- */
24
- const web3Modal = new Web3Modal({
25
- projectId: PROJECT_ID,
26
- themeMode: 'light',
27
- walletConnectVersion: 2,
28
- });
29
-
30
21
  export function getLastSession(client: SignClient) {
31
22
  return client.session.values[client.session.values.length - 1];
32
23
  }
@@ -86,7 +77,7 @@ export async function createSession(
86
77
  .map((namespace) => namespace.chains)
87
78
  .flat() as string[];
88
79
 
89
- web3Modal.openModal({ uri, standaloneChains });
80
+ getModal().openModal({ uri, standaloneChains });
90
81
  }
91
82
 
92
83
  const session = await approval();
@@ -95,7 +86,7 @@ export async function createSession(
95
86
  console.error(e);
96
87
  throw e;
97
88
  } finally {
98
- web3Modal.closeModal();
89
+ getModal().closeModal();
99
90
  }
100
91
  }
101
92