Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions examples/iframe/modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
position: fixed;
top: 0;
left: 0;
content: '';
content: "";
}
.modal {
position: fixed;
Expand Down Expand Up @@ -83,21 +83,21 @@
<div class="modal">
<div id="rango-widget-container"></div>
</div>
<script src="../../widget/iframe/dist/index.js"></script>
<script src="https://api.rango.exchange/widget/iframe.bundle.min.js"></script>
<script defer type="text/javascript">
const config = {
from: {
blockchain: 'ETH',
blockchain: "ETH",
},
amount: 1,
// This API key is only for test purpose. Don't use it in production.
apiKey: 'c6381a79-2817-4602-83bf-6a641a409e32',
apiKey: "c6381a79-2817-4602-83bf-6a641a409e32",
// This project id is only for test purpose. Don't use it in production.
// Get your Wallet Connect project id from https://cloud.walletconnect.com/
walletConnectProjectId: 'e24844c5deb5193c1c14840a7af6a40b',
walletConnectProjectId: "e24844c5deb5193c1c14840a7af6a40b",
};

rangoWidget.init(config, { widgetUrl: 'http://localhost:3002' });
rangoWidget.init(config);
</script>
</body>
</html>
18 changes: 6 additions & 12 deletions examples/iframe/modal_dynamic.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
position: fixed;
top: 0;
left: 0;
content: '';
content: "";
}
.modal {
position: fixed;
Expand Down Expand Up @@ -82,27 +82,21 @@
<div class="modal">
<div id="rango-widget-container"></div>
</div>
<script src="../../widget/iframe/dist/index.js"></script>
<script src="https://api.rango.exchange/widget/iframe.bundle.min.js"></script>
<script defer type="text/javascript">
const config = {
from: {
blockchain: 'ETH',
blockchain: "ETH",
},
amount: 1,
// This API key is only for test purpose. Don't use it in production.
apiKey: 'c6381a79-2817-4602-83bf-6a641a409e32',
apiKey: "c6381a79-2817-4602-83bf-6a641a409e32",
// This project id is only for test purpose. Don't use it in production.
// Get your Wallet Connect project id from https://cloud.walletconnect.com/
walletConnectProjectId: 'e24844c5deb5193c1c14840a7af6a40b',
walletConnectProjectId: "e24844c5deb5193c1c14840a7af6a40b",
};

rangoWidget
.init(config, {
clientUrl: 'http://localhost:5500',
widgetUrl: 'http://localhost:3002',
rootId: 'rango-widget-container',
})
.activate('dynamicHeight');
rangoWidget.init(config);
</script>
</body>
</html>
4 changes: 1 addition & 3 deletions widget/app/public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

html {
box-sizing: border-box;
height: 100%;
}

body {
padding: 0;
margin: 0;
background-color: transparent;
height: 100%;
}

#app {
height: 100%;
min-height: 100vh;
display: flex;
justify-content: center;
}
8 changes: 3 additions & 5 deletions widget/embedded/src/components/Layout/Layout.constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
export const WIDGET_MAX_HEIGHT = '700px';
export const WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS = '425px';
export const WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS = '550px';
export const COMPACT_TOKEN_SELECTOR_THRESHOLD = '640px';
export const LARGE_SCREEN_MIN_HEIGHT = '800px';
export const WIDGET_MAX_HEIGHT = 700;
export const WIDGET_MIN_HEIGHT = 425;
export const COMPACT_TOKEN_SELECTOR_THRESHOLD = 640;
17 changes: 5 additions & 12 deletions widget/embedded/src/components/Layout/Layout.styles.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import { css, styled } from '@rango-dev/ui';

import {
LARGE_SCREEN_MIN_HEIGHT,
WIDGET_MAX_HEIGHT,
WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS,
WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS,
} from './Layout.constants';
import { WIDGET_MAX_HEIGHT, WIDGET_MIN_HEIGHT } from './Layout.constants';

export const LayoutContainer = css({
borderRadius: '$primary',
Expand All @@ -21,18 +16,16 @@ export const Container = styled('div', {
minWidth: '300px',
maxWidth: '390px',
backgroundColor: '$background',
maxHeight: WIDGET_MAX_HEIGHT,
variants: {
height: {
auto: {
height: 'auto',
maxHeight: WIDGET_MAX_HEIGHT,
},
fixed: {
height: '100%',
minHeight: WIDGET_MIN_HEIGHT_FOR_SMALL_SCREENS,
[`@media screen and (min-height: ${LARGE_SCREEN_MIN_HEIGHT})`]: {
minHeight: WIDGET_MIN_HEIGHT_FOR_LARGE_SCREENS,
},
minHeight: WIDGET_MIN_HEIGHT,
maxHeight: WIDGET_MAX_HEIGHT,
height: WIDGET_MAX_HEIGHT,
},
},
showBanner: {
Expand Down
50 changes: 32 additions & 18 deletions widget/embedded/src/components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { WIDGET_UI_ID } from '../../constants';
import { useIframe } from '../../hooks/useIframe';
import { isAppLoadedIntoIframe } from '../../hooks/useIframe/useIframe.helpers';
import { useNavigateBack } from '../../hooks/useNavigateBack';
import useScreenDetect from '../../hooks/useScreenDetect';
import { useTheme } from '../../hooks/useTheme';
import { useAppStore } from '../../store/AppStore';
import { tabManager, useUiStore } from '../../store/ui';
Expand All @@ -21,7 +22,10 @@ import { ActivateTabModal } from '../common/ActivateTabModal';
import { BackButton, CancelButton, WalletButton } from '../HeaderButtons';
import { RefreshModal } from '../RefreshModal';

import { COMPACT_TOKEN_SELECTOR_THRESHOLD } from './Layout.constants';
import {
COMPACT_TOKEN_SELECTOR_THRESHOLD,
WIDGET_MAX_HEIGHT,
} from './Layout.constants';
import { onScrollContentAttachStatusToContainer } from './Layout.helpers';
import {
BannerContainer,
Expand All @@ -43,7 +47,7 @@ function Layout(props: PropsWithChildren<PropTypes>) {
const {
config: { features, theme },
} = useAppStore();
const { watermark } = useUiStore();
const { watermark, setShowCompactTokenSelector } = useUiStore();

const hasWatermark = watermark === 'FULL';
const { activeTheme } = useTheme(theme || {});
Expand All @@ -60,10 +64,10 @@ function Layout(props: PropsWithChildren<PropTypes>) {
showActivateTabModal,
setShowActivateTabModal,
activateCurrentTab,
setShowCompactTokenSelector,
} = useUiStore();
const navigateBack = useNavigateBack();
const { manager } = useManager();
const { isTablet, isMobile } = useScreenDetect();
const pendingSwaps: PendingSwap[] = getPendingSwaps(manager).map(
({ swap }) => swap
);
Expand Down Expand Up @@ -130,25 +134,35 @@ function Layout(props: PropsWithChildren<PropTypes>) {
}, [fetchStatus]);

useLayoutEffect(() => {
if (!containerRef.current) {
return;
}
const isFixedHeight =
height === 'auto' || !containerRef.current || isAppLoadedIntoIframe();
const isSmallScreen = isMobile || isTablet;

const observer = new ResizeObserver((entries) => {
for (const entry of entries) {
if (entry.contentRect) {
setShowCompactTokenSelector(
entry.contentRect.height <
parseInt(COMPACT_TOKEN_SELECTOR_THRESHOLD)
);
}
const handler = () => {
if (isFixedHeight) {
return;
}
});

observer.observe(containerRef.current);
if (isSmallScreen) {
containerRef.current.style.height = `${
window.innerHeight - containerRef.current.offsetTop
}px`;
} else {
containerRef.current.style.height = `${WIDGET_MAX_HEIGHT}px`;
}

return () => observer.disconnect();
}, []);
setShowCompactTokenSelector(
parseFloat(containerRef.current.style.height) <
COMPACT_TOKEN_SELECTOR_THRESHOLD
);
};

handler();

window.addEventListener('resize', handler);

return () => window.removeEventListener('resize', handler);
}, [height, isMobile, isTablet]);

return (
<Container
Expand Down
1 change: 0 additions & 1 deletion widget/embedded/src/containers/App/App.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ export const MainContainer = styled('div', {
fontFamily: '$widget',
boxSizing: 'border-box',
textAlign: 'left',
height: '100%',
'& *, *::before, *::after': {
boxSizing: 'inherit',
},
Expand Down
8 changes: 1 addition & 7 deletions widget/embedded/src/hooks/useScreenDetect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,7 @@ const useScreenDetect = () => {
return () => window.removeEventListener('resize', handleResize);
}, []);

return {
isMobile,
isTablet,
isNotebook,
isLargeScreen,
isExtraLargeScreen,
};
return { isMobile, isTablet, isNotebook, isLargeScreen, isExtraLargeScreen };
};

export default useScreenDetect;
1 change: 0 additions & 1 deletion widget/iframe/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ interface Features {
* esm supports for `exports` in package json which will be useful for this use case.
* The bellow type should come from `widget/embedded/src/hooks/useIframe/useIframe.types.ts`.
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type Messages = any;

export class RangoWidget {
Expand Down
Loading