@rango-dev/widget-embedded 0.51.1-next.7 → 0.51.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.51.1-next.7",
3
+ "version": "0.51.1-next.8",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -54,4 +54,4 @@
54
54
  "publishConfig": {
55
55
  "access": "public"
56
56
  }
57
- }
57
+ }
@@ -1,3 +1,5 @@
1
- export const WIDGET_MAX_HEIGHT = 700;
2
- export const WIDGET_MIN_HEIGHT = 425;
3
- export const COMPACT_TOKEN_SELECTOR_THRESHOLD = 640;
1
+ export const WIDGET_MAX_HEIGHT = '700px';
2
+ export const WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS = '425px';
3
+ export const WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS = '550px';
4
+ export const COMPACT_TOKEN_SELECTOR_THRESHOLD = '640px';
5
+ export const LARGE_SCREEN_MIN_HEIGHT = '800px';
@@ -1,6 +1,11 @@
1
1
  import { css, styled } from '@rango-dev/ui';
2
2
 
3
- import { WIDGET_MAX_HEIGHT, WIDGET_MIN_HEIGHT } from './Layout.constants';
3
+ import {
4
+ LARGE_SCREEN_MIN_HEIGHT,
5
+ WIDGET_MAX_HEIGHT,
6
+ WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS,
7
+ WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS,
8
+ } from './Layout.constants';
4
9
 
5
10
  export const LayoutContainer = css({
6
11
  borderRadius: '$primary',
@@ -16,16 +21,18 @@ export const Container = styled('div', {
16
21
  minWidth: '300px',
17
22
  maxWidth: '390px',
18
23
  backgroundColor: '$background',
24
+ maxHeight: WIDGET_MAX_HEIGHT,
19
25
  variants: {
20
26
  height: {
21
27
  auto: {
22
28
  height: 'auto',
23
- maxHeight: WIDGET_MAX_HEIGHT,
24
29
  },
25
30
  fixed: {
26
- minHeight: WIDGET_MIN_HEIGHT,
27
- maxHeight: WIDGET_MAX_HEIGHT,
28
- height: WIDGET_MAX_HEIGHT,
31
+ height: '100%',
32
+ minHeight: WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS,
33
+ [`@media screen and (min-height: ${LARGE_SCREEN_MIN_HEIGHT})`]: {
34
+ minHeight: WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS,
35
+ },
29
36
  },
30
37
  },
31
38
  showBanner: {
@@ -10,7 +10,6 @@ import { WIDGET_UI_ID } from '../../constants';
10
10
  import { useIframe } from '../../hooks/useIframe';
11
11
  import { isAppLoadedIntoIframe } from '../../hooks/useIframe/useIframe.helpers';
12
12
  import { useNavigateBack } from '../../hooks/useNavigateBack';
13
- import useScreenDetect from '../../hooks/useScreenDetect';
14
13
  import { useTheme } from '../../hooks/useTheme';
15
14
  import { useAppStore } from '../../store/AppStore';
16
15
  import { tabManager, useUiStore } from '../../store/ui';
@@ -22,10 +21,7 @@ import { ActivateTabModal } from '../common/ActivateTabModal';
22
21
  import { BackButton, CancelButton, WalletButton } from '../HeaderButtons';
23
22
  import { RefreshModal } from '../RefreshModal';
24
23
 
25
- import {
26
- COMPACT_TOKEN_SELECTOR_THRESHOLD,
27
- WIDGET_MAX_HEIGHT,
28
- } from './Layout.constants';
24
+ import { COMPACT_TOKEN_SELECTOR_THRESHOLD } from './Layout.constants';
29
25
  import { onScrollContentAttachStatusToContainer } from './Layout.helpers';
30
26
  import {
31
27
  BannerContainer,
@@ -47,7 +43,7 @@ function Layout(props: PropsWithChildren<PropTypes>) {
47
43
  const {
48
44
  config: { features, theme },
49
45
  } = useAppStore();
50
- const { watermark, setShowCompactTokenSelector } = useUiStore();
46
+ const { watermark } = useUiStore();
51
47
 
52
48
  const hasWatermark = watermark === 'FULL';
53
49
  const { activeTheme } = useTheme(theme || {});
@@ -64,10 +60,10 @@ function Layout(props: PropsWithChildren<PropTypes>) {
64
60
  showActivateTabModal,
65
61
  setShowActivateTabModal,
66
62
  activateCurrentTab,
63
+ setShowCompactTokenSelector,
67
64
  } = useUiStore();
68
65
  const navigateBack = useNavigateBack();
69
66
  const { manager } = useManager();
70
- const { isTablet, isMobile } = useScreenDetect();
71
67
  const pendingSwaps: PendingSwap[] = getPendingSwaps(manager).map(
72
68
  ({ swap }) => swap
73
69
  );
@@ -134,35 +130,25 @@ function Layout(props: PropsWithChildren<PropTypes>) {
134
130
  }, [fetchStatus]);
135
131
 
136
132
  useLayoutEffect(() => {
137
- const isFixedHeight =
138
- height === 'auto' || !containerRef.current || isAppLoadedIntoIframe();
139
- const isSmallScreen = isMobile || isTablet;
140
-
141
- const handler = () => {
142
- if (isFixedHeight) {
143
- return;
144
- }
133
+ if (!containerRef.current) {
134
+ return;
135
+ }
145
136
 
146
- if (isSmallScreen) {
147
- containerRef.current.style.height = `${
148
- window.innerHeight - containerRef.current.offsetTop
149
- }px`;
150
- } else {
151
- containerRef.current.style.height = `${WIDGET_MAX_HEIGHT}px`;
137
+ const observer = new ResizeObserver((entries) => {
138
+ for (const entry of entries) {
139
+ if (entry.contentRect) {
140
+ setShowCompactTokenSelector(
141
+ entry.contentRect.height <
142
+ parseInt(COMPACT_TOKEN_SELECTOR_THRESHOLD)
143
+ );
144
+ }
152
145
  }
146
+ });
153
147
 
154
- setShowCompactTokenSelector(
155
- parseFloat(containerRef.current.style.height) <
156
- COMPACT_TOKEN_SELECTOR_THRESHOLD
157
- );
158
- };
159
-
160
- handler();
148
+ observer.observe(containerRef.current);
161
149
 
162
- window.addEventListener('resize', handler);
163
-
164
- return () => window.removeEventListener('resize', handler);
165
- }, [height, isMobile, isTablet]);
150
+ return () => observer.disconnect();
151
+ }, []);
166
152
 
167
153
  return (
168
154
  <Container
@@ -4,6 +4,7 @@ export const MainContainer = styled('div', {
4
4
  fontFamily: '$widget',
5
5
  boxSizing: 'border-box',
6
6
  textAlign: 'left',
7
+ height: '100%',
7
8
  '& *, *::before, *::after': {
8
9
  boxSizing: 'inherit',
9
10
  },
@@ -43,7 +43,13 @@ const useScreenDetect = () => {
43
43
  return () => window.removeEventListener('resize', handleResize);
44
44
  }, []);
45
45
 
46
- return { isMobile, isTablet, isNotebook, isLargeScreen, isExtraLargeScreen };
46
+ return {
47
+ isMobile,
48
+ isTablet,
49
+ isNotebook,
50
+ isLargeScreen,
51
+ isExtraLargeScreen,
52
+ };
47
53
  };
48
54
 
49
55
  export default useScreenDetect;