Skip to content

Commit

Permalink
chore: remove network prop in zora worker
Browse files Browse the repository at this point in the history
  • Loading branch information
bigint committed Sep 4, 2023
1 parent 1cd34f6 commit d2201d5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
3 changes: 1 addition & 2 deletions apps/web/src/components/Shared/OpenAction/Nft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ interface NftProps {
}

const Nft: FC<NftProps> = ({ nftMetadata }) => {
const { chain, address, token, network } = nftMetadata;
const { chain, address, token } = nftMetadata;
const [showMintModal, setShowMintModal] = useState(false);
const isZoraMintEnabled = isFeatureEnabled(FeatureFlag.ZoraMint);

Expand All @@ -73,7 +73,6 @@ const Nft: FC<NftProps> = ({ nftMetadata }) => {
chain,
address,
token: token,
network,
enabled: Boolean(chain && address)
});

Expand Down
6 changes: 2 additions & 4 deletions apps/web/src/hooks/zora/useZoraNft.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import { ZORA_WORKER_URL } from '@lenster/data/constants';
import type { ZoraNft, ZoraNftMetadata } from '@lenster/types/zora-nft';
import type { ZoraNft } from '@lenster/types/zora-nft';
import { useQuery } from '@tanstack/react-query';
import axios from 'axios';

interface UseZoraNftProps {
chain: string;
address: string;
token: string;
network: ZoraNftMetadata['network'];
enabled?: boolean;
}

const useZoraNft = ({
chain,
address,
token,
network,
enabled
}: UseZoraNftProps): {
data: ZoraNft;
Expand All @@ -24,7 +22,7 @@ const useZoraNft = ({
} => {
const loadNftDetails = async () => {
const response = await axios.get(`${ZORA_WORKER_URL}/nft`, {
params: { chain, address, token, network }
params: { chain, address, token }
});

return response.data?.nft;
Expand Down
4 changes: 1 addition & 3 deletions packages/lib/nft/getZoraNft.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { ZoraNftMetadata } from '@lenster/types/zora-nft';

const mainnetChains = ['eth', 'oeth', 'base', 'zora'];
export const regex =
/https:\/\/(?:testnet\.)?zora\.co\/collect\/(eth|oeth|base|zora|gor|ogor|basegor|zgor):(0x[\dA-Fa-f]{40})((?:\/(\d+))?|$)/;

Expand All @@ -15,9 +14,8 @@ const getZoraNFT = (url: string): ZoraNftMetadata | null => {
const chain = matches[1];
const address = matches[2];
const token = matches[4];
const network = mainnetChains.includes(chain) ? 'mainnet' : 'testnet';

return { chain, address, token, network };
return { chain, address, token };
}

return null;
Expand Down
1 change: 0 additions & 1 deletion packages/types/zora-nft.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ export interface ZoraNftMetadata {
chain: string;
address: string;
token: string;
network: 'testnet' | 'mainnet';
}

export interface ZoraNft {
Expand Down
13 changes: 7 additions & 6 deletions packages/workers/zora/src/handlers/getNft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@ export default async (request: WorkerRequest) => {
name: '@lenster/zora/getNft'
});

const { network, chain, address } = request.query;
const { chain, address } = request.query;

if (!network || !chain || !address) {
if (!chain || !address) {
return response({
success: false,
error: 'No network, chain and address provided'
error: 'No chain and address provided'
});
}

try {
const mainnetChains = ['eth', 'oeth', 'base', 'zora'];
const network = mainnetChains.includes(chain as string) ? '' : 'testnet.';

const zoraResponse = await fetch(
`https://${
network === 'testnet' ? 'testnet.' : ''
}zora.co/api/personalize/collection/${chain}:${address}`
`https://${network}zora.co/api/personalize/collection/${chain}:${address}`
);
const nft: { collection: any } = await zoraResponse.json();

Expand Down

0 comments on commit d2201d5

Please sign in to comment.