From ea31fef63146f984535bda05ea1274f01d0df27e Mon Sep 17 00:00:00 2001 From: solimander Date: Mon, 27 May 2024 09:06:07 +0200 Subject: [PATCH] Override default IPFS gateway --- packages/prop-house-webapp/src/App.tsx | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/prop-house-webapp/src/App.tsx b/packages/prop-house-webapp/src/App.tsx index 585b63023..f49ad4eb4 100644 --- a/packages/prop-house-webapp/src/App.tsx +++ b/packages/prop-house-webapp/src/App.tsx @@ -22,7 +22,7 @@ import { lightTheme, RainbowKitProvider, } from '@rainbow-me/rainbowkit'; -import { PropHouseProvider } from '@prophouse/sdk-react'; +import { PropHouseProvider, ipfs } from '@prophouse/sdk-react'; import '@rainbow-me/rainbowkit/styles.css'; import CreateRound from './pages/CreateRound'; import MainApp from './pages/MainApp'; @@ -37,6 +37,24 @@ import { useAppSelector } from './hooks'; import mixpanel from 'mixpanel-browser'; import Banner from './components/Banner'; +// Override default IPFS gateway +(ipfs.getUrl as Function) = (uri: string, gateway = 'ipfs.nftstorage.link') => { + const ipfsGateway = `https://${gateway}`; + if (!uri) return null; + if ( + !uri.startsWith('ipfs://') && + !uri.startsWith('ipns://') && + !uri.startsWith('https://') && + !uri.startsWith('http://') + ) + return `${ipfsGateway}/ipfs/${uri}`; + + const uriScheme = uri.split('://')[0]; + if (uriScheme === 'ipfs') return uri.replace('ipfs://', `${ipfsGateway}/ipfs/`); + if (uriScheme === 'ipns') return uri.replace('ipns://', `${ipfsGateway}/ipns/`); + return uri; +}; + const { chains, publicClient } = configureChains([mainnet], [publicProvider()]); const { wallets } = getDefaultWallets({