Commit 6354b5db authored by Max Alekseenko's avatar Max Alekseenko

pass custom app url to iframe

parent c75cac05
...@@ -2,7 +2,7 @@ import { Box, Center, useColorMode, Flex } from '@chakra-ui/react'; ...@@ -2,7 +2,7 @@ import { Box, Center, useColorMode, Flex } from '@chakra-ui/react';
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { DappscoutIframeProvider, useDappscoutIframe } from 'dappscout-iframe'; import { DappscoutIframeProvider, useDappscoutIframe } from 'dappscout-iframe';
import { useRouter } from 'next/router'; import { useRouter } from 'next/router';
import React, { useCallback, useEffect, useState } from 'react'; import React, { useCallback, useEffect, useState, useMemo } from 'react';
import type { MarketplaceAppOverview } from 'types/client/marketplace'; import type { MarketplaceAppOverview } from 'types/client/marketplace';
...@@ -16,6 +16,7 @@ import throwOnResourceLoadError from 'lib/errors/throwOnResourceLoadError'; ...@@ -16,6 +16,7 @@ import throwOnResourceLoadError from 'lib/errors/throwOnResourceLoadError';
import useFetch from 'lib/hooks/useFetch'; import useFetch from 'lib/hooks/useFetch';
import * as metadata from 'lib/metadata'; import * as metadata from 'lib/metadata';
import getQueryParamString from 'lib/router/getQueryParamString'; import getQueryParamString from 'lib/router/getQueryParamString';
import removeQueryParam from 'lib/router/removeQueryParam';
import ContentLoader from 'ui/shared/ContentLoader'; import ContentLoader from 'ui/shared/ContentLoader';
import MarketplaceAppTopBar from '../marketplace/MarketplaceAppTopBar'; import MarketplaceAppTopBar from '../marketplace/MarketplaceAppTopBar';
...@@ -36,9 +37,10 @@ type Props = { ...@@ -36,9 +37,10 @@ type Props = {
address: string | undefined; address: string | undefined;
data: MarketplaceAppOverview | undefined; data: MarketplaceAppOverview | undefined;
isPending: boolean; isPending: boolean;
appUrl?: string;
}; };
const MarketplaceAppContent = ({ address, data, isPending }: Props) => { const MarketplaceAppContent = ({ address, data, isPending, appUrl }: Props) => {
const { iframeRef, isReady } = useDappscoutIframe(); const { iframeRef, isReady } = useDappscoutIframe();
const [ iframeKey, setIframeKey ] = useState(0); const [ iframeKey, setIframeKey ] = useState(0);
...@@ -89,7 +91,7 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => { ...@@ -89,7 +91,7 @@ const MarketplaceAppContent = ({ address, data, isPending }: Props) => {
h="100%" h="100%"
w="100%" w="100%"
display={ isFrameLoading ? 'none' : 'block' } display={ isFrameLoading ? 'none' : 'block' }
src={ data.url } src={ appUrl }
title={ data.title } title={ data.title }
onLoad={ handleIframeLoad } onLoad={ handleIframeLoad }
/> />
...@@ -132,6 +134,26 @@ const MarketplaceApp = () => { ...@@ -132,6 +134,26 @@ const MarketplaceApp = () => {
const { data, isPending } = query; const { data, isPending } = query;
const { setIsAutoConnectDisabled } = useMarketplaceContext(); const { setIsAutoConnectDisabled } = useMarketplaceContext();
const appUrl = useMemo(() => {
if (!data?.url) {
return;
}
try {
const customUrl = getQueryParamString(router.query.url);
const customOrigin = new URL(customUrl).origin;
const appOrigin = new URL(data.url).origin;
if (customOrigin === appOrigin) {
return customUrl;
} else {
removeQueryParam(router, 'url');
}
} catch (err) {}
return data.url;
}, [ data?.url, router ]);
useEffect(() => { useEffect(() => {
if (data) { if (data) {
metadata.update( metadata.update(
...@@ -153,13 +175,13 @@ const MarketplaceApp = () => { ...@@ -153,13 +175,13 @@ const MarketplaceApp = () => {
/> />
<DappscoutIframeProvider <DappscoutIframeProvider
address={ address } address={ address }
appUrl={ data?.url } appUrl={ appUrl }
rpcUrl={ config.chain.rpcUrl } rpcUrl={ config.chain.rpcUrl }
sendTransaction={ sendTransaction } sendTransaction={ sendTransaction }
signMessage={ signMessage } signMessage={ signMessage }
signTypedData={ signTypedData } signTypedData={ signTypedData }
> >
<MarketplaceAppContent address={ address } data={ data } isPending={ isPending }/> <MarketplaceAppContent address={ address } data={ data } isPending={ isPending } appUrl={ appUrl }/>
</DappscoutIframeProvider> </DappscoutIframeProvider>
</Flex> </Flex>
); );
......
import { Button, Image, Text, useColorModeValue } from '@chakra-ui/react'; import { Button, Image, Text, useColorModeValue } from '@chakra-ui/react';
import React from 'react'; import React from 'react';
import { route } from 'nextjs-routes';
import LinkExternal from './LinkExternal'; import LinkExternal from './LinkExternal';
type Props = { type Props = {
...@@ -15,8 +17,8 @@ type Props = { ...@@ -15,8 +17,8 @@ type Props = {
} }
const mockData = { const mockData = {
appId: '1', appId: 'uniswap',
actionUrl: 'https://github.com/', actionUrl: 'https://app.uniswap.org/swap?inputCurrency=ETH&outputCurrency=0x6B175474E89094C44Da98b954EedeAC495271d0F',
textColor: '#E2E8F0', textColor: '#E2E8F0',
bgColor: '#9747FF', bgColor: '#9747FF',
text: 'Mint NFT', text: 'Mint NFT',
...@@ -47,7 +49,7 @@ const ActionButton = ({ data = mockData }: Props) => { ...@@ -47,7 +49,7 @@ const ActionButton = ({ data = mockData }: Props) => {
return appId ? ( return appId ? (
<Button <Button
as="a" as="a"
href={ actionUrl } href={ route({ pathname: '/apps/[id]', query: { id: appId, action: 'connect', url: actionUrl } }) }
display="flex" display="flex"
size="sm" size="sm"
px={ 2 } px={ 2 }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment