@rango-dev/widget-embedded 0.28.1-next.1 → 0.28.1-next.2
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/fonts.d.ts +5 -0
- package/dist/constants/fonts.d.ts.map +1 -1
- package/dist/containers/WidgetProvider/WidgetProvider.d.ts.map +1 -1
- package/dist/globalStyles.d.ts.map +1 -1
- package/dist/hooks/useFontLoader.d.ts +5 -0
- package/dist/hooks/useFontLoader.d.ts.map +1 -0
- package/dist/hooks/useTheme.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/types/config.d.ts +1 -1
- package/dist/utils/common.d.ts +1 -0
- package/dist/utils/common.d.ts.map +1 -1
- package/dist/utils/configs.d.ts +0 -1
- package/dist/utils/configs.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/constants/fonts.ts +84 -0
- package/src/containers/WidgetProvider/WidgetProvider.tsx +12 -1
- package/src/globalStyles.ts +1 -3
- package/src/hooks/useBootstrap/useBootstrap.ts +1 -1
- package/src/hooks/useFontLoader.ts +40 -0
- package/src/hooks/useTheme.ts +1 -1
- package/src/index.ts +2 -0
- package/src/types/config.ts +1 -1
- package/src/utils/common.ts +6 -0
- package/src/utils/configs.ts +0 -1
package/dist/types/config.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type WidgetColors = {
|
|
|
25
25
|
* radius, width, and height.
|
|
26
26
|
* @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
|
|
27
27
|
* the widget.
|
|
28
|
-
* @property {string} fontFamily - The font family to be used in the widget.
|
|
28
|
+
* @property {string} fontFamily - The font family to be used in the widget. If you want to do this, include the font of your choice in your HTML file.
|
|
29
29
|
* @property {{ light?: WidgetColors; dark?: WidgetColors }} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
|
|
30
30
|
* defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
|
|
31
31
|
* contains specific color values for various parts of the widget (e.g. background color, text color,
|
package/dist/utils/common.d.ts
CHANGED
|
@@ -10,4 +10,5 @@ export declare const getContainer: () => HTMLElement;
|
|
|
10
10
|
export declare const getExpanded: () => HTMLElement;
|
|
11
11
|
export declare function compareWithSearchFor(tokenA: Token, tokenB: Token, searchFor?: string): number;
|
|
12
12
|
export declare const isBlockchainTypeInCategory: (blockchainType: TransactionType, category: string) => boolean;
|
|
13
|
+
export declare const getFontUrlByName: (fontName: string) => string | undefined;
|
|
13
14
|
//# sourceMappingURL=common.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/utils/common.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAGvC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAY5C,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,EAAE,CAEtD;AAED,wBAAgB,QAAQ,CACtB,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EAC3B,MAAM,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,WAK5B;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,aAGvB,GAAG,UAS9B;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAGtE;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAEnE;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAEvE;AAED,eAAO,MAAM,YAAY,mBACyC,CAAC;AAEnE,eAAO,MAAM,WAAW,mBAC8C,CAAC;AAsDvE,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,KAAK,EACb,MAAM,EAAE,KAAK,EACb,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CA0GR;AAED,eAAO,MAAM,0BAA0B,mBACrB,eAAe,YACrB,MAAM,KACf,OAeF,CAAC;AAEF,eAAO,MAAM,gBAAgB,aAAc,MAAM,uBAGhD,CAAC"}
|
package/dist/utils/configs.d.ts
CHANGED
|
@@ -15,7 +15,6 @@ export declare function setConfig(name: keyof Configs, value: any): any;
|
|
|
15
15
|
export declare function initConfig(nextConfigs: Configs): Configs;
|
|
16
16
|
export declare const DEFAULT_PRIMARY_RADIUS = 20;
|
|
17
17
|
export declare const DEFAULT_SECONDARY_RADIUS = 25;
|
|
18
|
-
export declare const DEFAULT_FONT_FAMILY = "Roboto";
|
|
19
18
|
export declare const THEME_CLASS_NAME_PREFIX = "theme-widget";
|
|
20
19
|
export declare const isTokenExcludedInConfig: (token: Token | null, tokensConfig?: TokensConfig) => boolean;
|
|
21
20
|
export declare const isBlockchainExcludedInConfig: (blockchain: BlockchainMeta | null, blockchainsConfig?: string[]) => boolean | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../src/utils/configs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACtD,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AAM9D,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;C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B,cAAc,GAAG,IAAI,sBACb,MAAM,EAAE,+BAO7B,CAAC;AAEF,eAAO,MAAM,mBAAmB,kBACf,OAAO,sBACF,OAAO,YACjB,aAAa,YAMxB,CAAC"}
|
package/package.json
CHANGED
package/src/constants/fonts.ts
CHANGED
|
@@ -1 +1,85 @@
|
|
|
1
1
|
export const DEFAULT_FONT_FAMILY = 'Roboto';
|
|
2
|
+
|
|
3
|
+
export const SUPPORTED_FONTS = [
|
|
4
|
+
{
|
|
5
|
+
name: 'Roboto',
|
|
6
|
+
value: 'Roboto',
|
|
7
|
+
url: '',
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
name: 'Times New Roman',
|
|
11
|
+
value: 'Times New Roman',
|
|
12
|
+
url: 'https://fonts.cdnfonts.com/css/times-new-roman',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'Arial',
|
|
16
|
+
value: 'Arial',
|
|
17
|
+
url: '',
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
name: 'Open Sans',
|
|
21
|
+
value: 'Open Sans',
|
|
22
|
+
url: 'https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&display=swap',
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: 'Noto Sans',
|
|
26
|
+
value: 'Noto Sans',
|
|
27
|
+
url: 'https://fonts.googleapis.com/css2?family=Noto+Sans:ital,wght@0,100..900;1,100..900&display=swap',
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
name: 'Montserrat',
|
|
31
|
+
value: 'Montserrat',
|
|
32
|
+
url: 'https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100..900;1,100..900&display=swap',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'Poppins',
|
|
36
|
+
value: 'Poppins',
|
|
37
|
+
url: 'https://fonts.googleapis.com/css2?family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: 'Roboto Condensed',
|
|
41
|
+
value: 'Roboto Condensed',
|
|
42
|
+
url: 'https://fonts.googleapis.com/css2?family=Roboto+Condensed:ital,wght@0,100..900;1,100..900&display=swap',
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
{
|
|
46
|
+
name: 'Roboto Mono',
|
|
47
|
+
value: 'Roboto Mono',
|
|
48
|
+
url: 'https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap',
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: 'Oswald',
|
|
52
|
+
value: 'Oswald',
|
|
53
|
+
url: 'https://fonts.googleapis.com/css2?family=Oswald:wght@200..700&display=swap',
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
name: 'Raleway',
|
|
57
|
+
value: 'Raleway',
|
|
58
|
+
url: 'https://fonts.googleapis.com/css2?family=Raleway:ital,wght@0,100..900;1,100..900&display=swap',
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: 'Sedan',
|
|
62
|
+
value: 'Sedan',
|
|
63
|
+
url: 'https://fonts.googleapis.com/css2?family=Sedan:ital@0;1&display=swap',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'Inter',
|
|
67
|
+
value: 'Inter',
|
|
68
|
+
url: 'https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap',
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: 'Rubik',
|
|
72
|
+
value: 'Rubik',
|
|
73
|
+
url: 'https://fonts.googleapis.com/css2?family=Rubik:ital,wght@0,300..900;1,300..900&display=swap',
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: 'Lora',
|
|
77
|
+
value: 'Lora',
|
|
78
|
+
url: 'https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400..700;1,400..700&display=swap',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'Barlow Condensed',
|
|
82
|
+
value: 'Barlow Condensed',
|
|
83
|
+
url: 'https://fonts.googleapis.com/css2?family=Barlow+Condensed:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap',
|
|
84
|
+
},
|
|
85
|
+
];
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { PropTypes } from './WidgetProvider.types';
|
|
2
2
|
import type { PropsWithChildren } from 'react';
|
|
3
3
|
|
|
4
|
-
import React, { useMemo } from 'react';
|
|
4
|
+
import React, { useEffect, useMemo } from 'react';
|
|
5
5
|
|
|
6
6
|
import { DEFAULT_BASE_URL, RANGO_PUBLIC_API_KEY } from '../../constants';
|
|
7
|
+
import useFontLoader from '../../hooks/useFontLoader';
|
|
7
8
|
import QueueManager from '../../QueueManager';
|
|
8
9
|
import { initConfig } from '../../utils/configs';
|
|
9
10
|
import { WidgetWallets } from '../Wallets';
|
|
@@ -19,6 +20,16 @@ export function WidgetProvider(props: PropsWithChildren<PropTypes>) {
|
|
|
19
20
|
});
|
|
20
21
|
}, [config.apiKey, config.apiUrl]);
|
|
21
22
|
|
|
23
|
+
const fontFamily = props.config?.theme?.fontFamily;
|
|
24
|
+
|
|
25
|
+
const { handleLoadCustomFont } = useFontLoader();
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (fontFamily) {
|
|
29
|
+
handleLoadCustomFont(fontFamily);
|
|
30
|
+
}
|
|
31
|
+
}, [fontFamily]);
|
|
32
|
+
|
|
22
33
|
return (
|
|
23
34
|
<WidgetWallets config={config} onUpdateState={onUpdateState}>
|
|
24
35
|
<QueueManager apiKey={config.apiKey}>
|
package/src/globalStyles.ts
CHANGED
|
@@ -2,8 +2,6 @@ import { globalCss } from '@rango-dev/ui';
|
|
|
2
2
|
|
|
3
3
|
export const globalFont = () =>
|
|
4
4
|
globalCss({
|
|
5
|
-
'@import':
|
|
5
|
+
'@import':
|
|
6
6
|
"url('https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap')",
|
|
7
|
-
"url('https://fonts.cdnfonts.com/css/times-new-roman')",
|
|
8
|
-
],
|
|
9
7
|
})();
|
|
@@ -16,8 +16,8 @@ import { useForceAutoConnect } from '../useForceAutoConnect';
|
|
|
16
16
|
import { useSubscribeToWidgetEvents } from '../useSubscribeToWidgetEvents';
|
|
17
17
|
|
|
18
18
|
export function useBootstrap() {
|
|
19
|
-
globalFont();
|
|
20
19
|
useForceAutoConnect();
|
|
20
|
+
globalFont();
|
|
21
21
|
useSubscribeToWidgetEvents();
|
|
22
22
|
const blockchains = useAppStore().blockchains();
|
|
23
23
|
const { canSwitchNetworkTo } = useWallets();
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { getFontUrlByName } from '../utils/common';
|
|
4
|
+
/*
|
|
5
|
+
*TODO:
|
|
6
|
+
* Loading fonts from JS has a downside and it is the bundle needs to be downloaded and executed first which means after sometime font will be added to <head /> and it causes a layoutshift each time.
|
|
7
|
+
* We've added Roboto into <head /> since it's the default font. the downside here is it will load roboto anyway even dApp has set fontFamily other than Roboto which causes an unneccerary downloand (Roboto).
|
|
8
|
+
* We decided to go with the second one and it can be solved in future by split these types of configs into a separate js file and let it to be loaded with a more priority than the main bundle. it should be also cached which imrpove user experience after first load.
|
|
9
|
+
*/
|
|
10
|
+
const useFontLoader = () => {
|
|
11
|
+
const [fontLink, setFontLink] = useState<HTMLLinkElement | null>(null);
|
|
12
|
+
|
|
13
|
+
const loadFont = (fontUrl: string) => {
|
|
14
|
+
const link = document.createElement('link');
|
|
15
|
+
link.href = fontUrl;
|
|
16
|
+
link.rel = 'stylesheet';
|
|
17
|
+
document.head.appendChild(link);
|
|
18
|
+
return link;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const unloadFont = () => {
|
|
22
|
+
if (fontLink) {
|
|
23
|
+
document.head.removeChild(fontLink);
|
|
24
|
+
setFontLink(null);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const handleLoadCustomFont = (fontName: string) => {
|
|
29
|
+
unloadFont(); // Remove previous font
|
|
30
|
+
const fontUrl = getFontUrlByName(fontName);
|
|
31
|
+
if (fontUrl) {
|
|
32
|
+
const newFontLink = loadFont(fontUrl);
|
|
33
|
+
setFontLink(newFontLink);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return { handleLoadCustomFont };
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export default useFontLoader;
|
package/src/hooks/useTheme.ts
CHANGED
|
@@ -6,10 +6,10 @@ import {
|
|
|
6
6
|
} from '@rango-dev/ui';
|
|
7
7
|
import { useEffect, useState } from 'react';
|
|
8
8
|
|
|
9
|
+
import { DEFAULT_FONT_FAMILY } from '../constants/fonts';
|
|
9
10
|
import { useAppStore } from '../store/AppStore';
|
|
10
11
|
import { type WidgetTheme } from '../types';
|
|
11
12
|
import {
|
|
12
|
-
DEFAULT_FONT_FAMILY,
|
|
13
13
|
DEFAULT_PRIMARY_RADIUS,
|
|
14
14
|
DEFAULT_SECONDARY_RADIUS,
|
|
15
15
|
} from '../utils/configs';
|
package/src/index.ts
CHANGED
|
@@ -59,6 +59,7 @@ import { Networks, WalletTypes } from '@rango-dev/wallets-shared';
|
|
|
59
59
|
import { PendingSwapNetworkStatus } from 'rango-types';
|
|
60
60
|
|
|
61
61
|
import { WIDGET_UI_ID as UI_ID } from './constants';
|
|
62
|
+
import { SUPPORTED_FONTS } from './constants/fonts';
|
|
62
63
|
import { WidgetWallets } from './containers/Wallets';
|
|
63
64
|
import { Widget } from './containers/Widget';
|
|
64
65
|
import { useWidget } from './containers/WidgetInfo';
|
|
@@ -113,6 +114,7 @@ export {
|
|
|
113
114
|
StepExecutionEventStatus,
|
|
114
115
|
StepExecutionBlockedEventStatus,
|
|
115
116
|
UI_ID,
|
|
117
|
+
SUPPORTED_FONTS,
|
|
116
118
|
};
|
|
117
119
|
|
|
118
120
|
// Internal type exports for Rango
|
package/src/types/config.ts
CHANGED
|
@@ -28,7 +28,7 @@ export type WidgetColors = {
|
|
|
28
28
|
* radius, width, and height.
|
|
29
29
|
* @property {'auto' | 'light' | 'dark'} mode - The mode property is used to specify the default theme for
|
|
30
30
|
* the widget.
|
|
31
|
-
* @property {string} fontFamily - The font family to be used in the widget.
|
|
31
|
+
* @property {string} fontFamily - The font family to be used in the widget. If you want to do this, include the font of your choice in your HTML file.
|
|
32
32
|
* @property {{ light?: WidgetColors; dark?: WidgetColors }} colors - The `colors` property is a sub-property of the `WidgetTheme` object that
|
|
33
33
|
* defines the color scheme for the widget. It is of type `Colors`, which is likely another object that
|
|
34
34
|
* contains specific color values for various parts of the widget (e.g. background color, text color,
|
package/src/utils/common.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { BlockchainCategories } from '@rango-dev/ui';
|
|
|
4
4
|
import { TransactionType } from 'rango-sdk';
|
|
5
5
|
|
|
6
6
|
import { WIDGET_UI_ID } from '../constants';
|
|
7
|
+
import { SUPPORTED_FONTS } from '../constants/fonts';
|
|
7
8
|
import {
|
|
8
9
|
MIN_LENGTH_SYMBOL_CONTAINS,
|
|
9
10
|
MIN_LENGTH_SYMBOL_START_WITH,
|
|
@@ -241,3 +242,8 @@ export const isBlockchainTypeInCategory = (
|
|
|
241
242
|
return blockchainType === category;
|
|
242
243
|
}
|
|
243
244
|
};
|
|
245
|
+
|
|
246
|
+
export const getFontUrlByName = (fontName: string) => {
|
|
247
|
+
const font = SUPPORTED_FONTS.find((font) => font.value === fontName);
|
|
248
|
+
return font?.url;
|
|
249
|
+
};
|
package/src/utils/configs.ts
CHANGED