Skip to content

Commit

Permalink
Override default IPFS gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
solimander committed May 27, 2024
1 parent 55ee7c1 commit ea31fef
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion packages/prop-house-webapp/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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({
Expand Down

0 comments on commit ea31fef

Please sign in to comment.