@rango-dev/widget-embedded 0.58.1-next.6 → 0.58.1-next.7
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/constants/index.d.ts +0 -1
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/utils/configs.d.ts.map +1 -1
- package/dist/utils/env.d.ts +12 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/widget-embedded.build.json +1 -1
- package/package.json +9 -9
- package/src/constants/index.ts +0 -1
- package/src/containers/WidgetProvider/WidgetProvider.tsx +3 -2
- package/src/utils/configs.ts +2 -3
- package/src/utils/env.ts +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rango-dev/widget-embedded",
|
|
3
|
-
"version": "0.58.1-next.
|
|
3
|
+
"version": "0.58.1-next.7",
|
|
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.
|
|
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.
|
|
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.
|
|
34
|
-
"@rango-dev/wallets-core": "^0.57.1-next.
|
|
35
|
-
"@rango-dev/wallets-react": "^0.44.1-next.
|
|
36
|
-
"@rango-dev/wallets-shared": "^0.58.1-next.
|
|
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.
|
|
44
|
-
"rango-types": "^0.1.
|
|
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",
|
package/src/constants/index.ts
CHANGED
|
@@ -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
|
|
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 ||
|
|
36
|
+
API_KEY: config?.apiKey || getApiKeyFromEnvOrThrow(),
|
|
36
37
|
BASE_URL: config?.apiUrl || DEFAULT_BASE_URL,
|
|
37
38
|
});
|
|
38
39
|
}, [config.apiKey, config.apiUrl]);
|
package/src/utils/configs.ts
CHANGED
|
@@ -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 {
|
|
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:
|
|
19
|
+
API_KEY: getApiKeyFromEnvOrNotSet(),
|
|
21
20
|
};
|
|
22
21
|
|
|
23
22
|
export function getConfig(name: keyof Configs) {
|
package/src/utils/env.ts
ADDED
|
@@ -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
|
+
}
|