@rango-dev/widget-embedded 0.58.1-next.6 → 0.58.1-next.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.58.1-next.6",
3
+ "version": "0.58.1-next.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -25,23 +25,23 @@
25
25
  "@lingui/core": "4.2.1",
26
26
  "@lingui/react": "4.2.1",
27
27
  "@rango-dev/logging-core": "^0.12.1",
28
- "@rango-dev/provider-all": "^0.60.1-next.4",
28
+ "@rango-dev/provider-all": "^0.60.1-next.5",
29
29
  "@rango-dev/queue-manager-core": "^0.33.0",
30
- "@rango-dev/queue-manager-rango-preset": "^0.60.1-next.2",
30
+ "@rango-dev/queue-manager-rango-preset": "^0.60.1-next.5",
31
31
  "@rango-dev/queue-manager-react": "^0.33.0",
32
32
  "@rango-dev/signer-solana": "^0.46.2-next.0",
33
- "@rango-dev/ui": "^0.61.1-next.3",
34
- "@rango-dev/wallets-core": "^0.57.1-next.0",
35
- "@rango-dev/wallets-react": "^0.44.1-next.2",
36
- "@rango-dev/wallets-shared": "^0.58.1-next.2",
33
+ "@rango-dev/ui": "^0.61.1-next.4",
34
+ "@rango-dev/wallets-core": "^0.57.1-next.1",
35
+ "@rango-dev/wallets-react": "^0.44.1-next.3",
36
+ "@rango-dev/wallets-shared": "^0.58.1-next.3",
37
37
  "bignumber.js": "^9.1.1",
38
38
  "copy-to-clipboard": "^3.3.3",
39
39
  "dayjs": "^1.11.7",
40
40
  "ethers": "^6.13.2",
41
41
  "immer": "^9.0.19",
42
42
  "mitt": "^3.0.0",
43
- "rango-sdk": "^0.1.72",
44
- "rango-types": "^0.1.93",
43
+ "rango-sdk": "^0.1.74",
44
+ "rango-types": "^0.1.95",
45
45
  "react-i18next": "^12.2.0",
46
46
  "react-router-dom": "^6.8.0",
47
47
  "values.js": "2.1.1",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -1,6 +1,5 @@
1
1
  import { UI_ID } from '@rango-dev/ui';
2
2
 
3
- export const RANGO_PUBLIC_API_KEY = 'c6381a79-2817-4602-83bf-6a641a409e32';
4
3
  export const DEFAULT_BASE_URL = 'https://api.rango.exchange';
5
4
  export const SCANNER_BASE_URL = 'https://explorer.rango.exchange';
6
5
 
@@ -4,11 +4,12 @@ import type { PropsWithChildren } from 'react';
4
4
  import { setSolanaSignerConfig } from '@rango-dev/signer-solana';
5
5
  import React, { useEffect, useMemo } from 'react';
6
6
 
7
- import { DEFAULT_BASE_URL, RANGO_PUBLIC_API_KEY } from '../../constants';
7
+ import { DEFAULT_BASE_URL } from '../../constants';
8
8
  import { useFetchApiConfig } from '../../hooks/useFetchApiConfig';
9
9
  import useFontLoader from '../../hooks/useFontLoader';
10
10
  import QueueManager from '../../QueueManager';
11
11
  import { initConfig } from '../../utils/configs';
12
+ import { getApiKeyFromEnvOrThrow } from '../../utils/env';
12
13
  import { WidgetWallets } from '../Wallets';
13
14
  import { WidgetInfo } from '../WidgetInfo';
14
15
 
@@ -32,7 +33,7 @@ export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
32
33
 
33
34
  useMemo(() => {
34
35
  initConfig({
35
- API_KEY: config?.apiKey || RANGO_PUBLIC_API_KEY,
36
+ API_KEY: config?.apiKey || getApiKeyFromEnvOrThrow(),
36
37
  BASE_URL: config?.apiUrl || DEFAULT_BASE_URL,
37
38
  });
38
39
  }, [config.apiKey, config.apiUrl]);
@@ -466,7 +466,7 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
466
466
  const { _balances, _aggregatedBalances } =
467
467
  computeNextStateAfterWalletBalanceRemoval(
468
468
  partialCurrentState,
469
- walletType,
469
+ [walletType],
470
470
  options
471
471
  );
472
472
 
@@ -611,8 +611,10 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
611
611
  if (accounts.length === 0 || !accounts[0]) {
612
612
  return;
613
613
  }
614
- // All the `accounts` have same `walletType` so we can pick the first one.
615
- const walletType = accounts[0].walletType;
614
+
615
+ const walletTypes = [
616
+ ...new Set(accounts.map((account) => account.walletType)),
617
+ ];
616
618
 
617
619
  get().setConnectedWalletAsRefetching(accounts);
618
620
 
@@ -630,7 +632,6 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
630
632
  return;
631
633
  }
632
634
  const walletsDetails = response.wallets;
633
-
634
635
  if (walletsDetails) {
635
636
  let nextBalances: BalanceState = get()._balances;
636
637
  let nextAggregatedBalances: AggregatedBalanceState =
@@ -657,7 +658,7 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
657
658
  const { _balances, _aggregatedBalances } =
658
659
  computeNextStateAfterWalletBalanceRemoval(
659
660
  partialCurrentState,
660
- walletType,
661
+ walletTypes,
661
662
  {
662
663
  chains: [wallet.blockChain],
663
664
  }
@@ -672,7 +673,7 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
672
673
  if (
673
674
  !get().connectedWallets.find(
674
675
  (connectedWallet) =>
675
- connectedWallet.walletType === walletType &&
676
+ walletTypes.includes(connectedWallet.walletType) &&
676
677
  connectedWallet.address === wallet.address &&
677
678
  connectedWallet.chain === wallet.blockChain
678
679
  )
@@ -715,11 +716,23 @@ export const createWalletsSlice = keepLastUpdated<AppStoreState, WalletsSlice>(
715
716
  if (retryOnFailedBalances) {
716
717
  const failedWallets: Wallet[] = walletsDetails
717
718
  .filter((wallet) => wallet.failed)
718
- .map((wallet) => ({
719
- chain: wallet.blockChain,
720
- walletType: walletType,
721
- address: wallet.address,
722
- }));
719
+ .map((wallet) => {
720
+ const walletType = get().connectedWallets.find(
721
+ (connectedWallet) =>
722
+ connectedWallet.chain === wallet.blockChain &&
723
+ connectedWallet.address
724
+ )?.walletType;
725
+ // Return null if there is no related connected wallet.
726
+ if (!walletType) {
727
+ return null;
728
+ }
729
+ return {
730
+ chain: wallet.blockChain,
731
+ walletType: walletType,
732
+ address: wallet.address,
733
+ };
734
+ })
735
+ .filter((wallet) => !!wallet);
723
736
  if (failedWallets.length > 0) {
724
737
  await get().fetchMainTokensBalances(failedWallets, {
725
738
  retryOnFailedBalances: false,
@@ -164,14 +164,14 @@ export function computeNextStateAfterWalletBalanceRemoval(
164
164
  _aggregatedBalances: AggregatedBalanceState;
165
165
  connectedWallets: ConnectedWallet[];
166
166
  },
167
- walletType: string,
167
+ walletTypes: string[],
168
168
  options?: {
169
169
  chains?: string[];
170
170
  namespaces?: Namespace[];
171
171
  }
172
172
  ) {
173
173
  let walletsNeedsToBeRemoved = paritalCurrentState.connectedWallets.filter(
174
- (connectedWallet) => connectedWallet.walletType === walletType
174
+ (connectedWallet) => walletTypes.includes(connectedWallet.walletType)
175
175
  );
176
176
 
177
177
  /*
@@ -181,7 +181,7 @@ export function computeNextStateAfterWalletBalanceRemoval(
181
181
  * So we only delete balance when there is no connected wallet that has access to that specific chain and address.
182
182
  */
183
183
  paritalCurrentState.connectedWallets.forEach((connectedWallet) => {
184
- if (connectedWallet.walletType !== walletType) {
184
+ if (!walletTypes.includes(connectedWallet.walletType)) {
185
185
  walletsNeedsToBeRemoved = walletsNeedsToBeRemoved.filter((wallet) => {
186
186
  const isAnotherWalletHasSameAddressAndChain =
187
187
  wallet.chain === connectedWallet.chain &&
@@ -1,8 +1,7 @@
1
1
  import type { Tokens, WidgetVariant } from '../types';
2
2
  import type { Asset, BlockchainMeta, Token } from 'rango-sdk';
3
3
 
4
- import { RANGO_PUBLIC_API_KEY } from '../constants';
5
-
4
+ import { getApiKeyFromEnvOrNotSet } from './env';
6
5
  import { areTokensEqual } from './wallets';
7
6
 
8
7
  export interface Configs {
@@ -17,7 +16,7 @@ type TokensConfig =
17
16
  };
18
17
 
19
18
  let configs: Configs = {
20
- API_KEY: RANGO_PUBLIC_API_KEY,
19
+ API_KEY: getApiKeyFromEnvOrNotSet(),
21
20
  };
22
21
 
23
22
  export function getConfig(name: keyof Configs) {
@@ -0,0 +1,28 @@
1
+ export function getApiKeyFromEnv(): string | undefined {
2
+ // NOTE: parcel doesn't support for dynamic keys, so we have to do it statically.
3
+ return process.env.REACT_APP_RANGO_API_KEY;
4
+ }
5
+
6
+ /**
7
+ * This is useful when the api key is mandatory and nothing works corectly without api key.
8
+ * You need to first fallback to user's input (widget config), then you can use this to try to find from envs (e.g. widget/app or widget/playground)
9
+ * Then throw an runtime error to panic the program.
10
+ */
11
+ export function getApiKeyFromEnvOrThrow() {
12
+ // NOTE: parcel doesn't support for dynamic keys, so we have to do it statically.
13
+ const value = getApiKeyFromEnv();
14
+ if (value) {
15
+ return value;
16
+ }
17
+
18
+ throw new Error(
19
+ 'Ensure you have set REACT_APP_RANGO_API_KEY in your env variables.'
20
+ );
21
+ }
22
+
23
+ /**
24
+ * You can use this whenever you want to use the api key in initialize process, but mark the key explictly as not set to debug more easily since you should never reach there.
25
+ */
26
+ export function getApiKeyFromEnvOrNotSet(): string {
27
+ return getApiKeyFromEnv() || 'NOT_SET';
28
+ }