From b7740721aea7ee7e0fde62ca9666cdc8bf691b75 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 18:46:54 -0700 Subject: [PATCH 1/4] test(manifold): add test for getExternalUrl --- packages/manifold/src/Manifold.test.ts | 34 ++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/manifold/src/Manifold.test.ts b/packages/manifold/src/Manifold.test.ts index eb58729b8..1073e026d 100644 --- a/packages/manifold/src/Manifold.test.ts +++ b/packages/manifold/src/Manifold.test.ts @@ -1,4 +1,4 @@ -import { getFees, getMintIntent, mint, simulateMint } from './Manifold' +import { getExternalUrl, getFees, getMintIntent, mint, simulateMint } from './Manifold' import { ERC721_CONTRACT, ERC1155_CONTRACT } from './constants' import { failingTestCases, passingTestCases } from './test-transactions' import { apply } from '@rabbitholegg/questdk' @@ -8,7 +8,7 @@ import { type MintIntentParams, } from '@rabbitholegg/questdk-plugin-utils' import axios from 'axios' -import { type Address, parseEther } from 'viem' +import { type Address, parseEther, getAddress } from 'viem' import { MockedFunction, beforeEach, describe, expect, test, vi } from 'vitest' vi.mock('axios', () => { @@ -218,3 +218,33 @@ describe('simulateMint function', () => { expect(request.value).toBe(value) }) }) + +describe('getExternalUrl function', () => { + beforeEach(() => { + vi.resetAllMocks() + }) + test('should return the correct url for a 721 mint', async () => { + const mint = { + chainId: Chains.OPTIMISM, + contractAddress: getAddress('0x6935cd348193bab133f3081f53eb99ee6f0d685b'), + } + ;(axios.get as MockedFunction).mockResolvedValue({ + status: 200, + data: { + slug: 'girls-man', + }, + }) + + const result = await getExternalUrl(mint) + expect(result).toBe('https://app.manifold.xyz/c/girls-man') + }) + + test('should return the fallback url for an unknown contract', async () => { + const mint = { + chainId: Chains.OPTIMISM, + contractAddress: getAddress('0x7935cd348193bab133f3081f53eb99ee6f0d685b'), + } + const result = await getExternalUrl(mint) + expect(result).toBe('https://app.manifold.xyz/') + }) +}) \ No newline at end of file From 2b83fa5a7acf7298164007cd5f63e28cc03c37d1 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 18:48:31 -0700 Subject: [PATCH 2/4] feat(manifold): implement getExternalUrl function --- packages/manifold/src/Manifold.ts | 31 +++++++++++++++++++++++++++++++ packages/manifold/src/index.ts | 3 +++ 2 files changed, 34 insertions(+) diff --git a/packages/manifold/src/Manifold.ts b/packages/manifold/src/Manifold.ts index a2a2f2ad0..7ecdb6403 100644 --- a/packages/manifold/src/Manifold.ts +++ b/packages/manifold/src/Manifold.ts @@ -214,6 +214,37 @@ export const getFees = async ( } } +export const getExternalUrl = async (mint: MintActionParams): Promise => { + const { chainId, contractAddress, tokenId } = mint + + const baseUrl = 'https://app.manifold.xyz/' + + try { + const instanceId = await getInstanceId( + chainId, + contractAddress, + tokenId ?? 1, + ) + + const { data } = await axios.get<{ slug?: string }>(`https://apps.api.manifoldxyz.dev/public/instance/data?id=${instanceId}`) + const slug = data.slug + + if (!slug) { + throw new Error('Slug not found in response') + } + + return `${baseUrl}c/${slug}` + } catch (err) { + if (err instanceof Error) { + console.error(err.message) + } else { + console.error(err) + } + // fallback to default manifold url + return baseUrl + } +} + export const getSupportedTokenAddresses = async ( _chainId: number, ): Promise => { diff --git a/packages/manifold/src/index.ts b/packages/manifold/src/index.ts index a52019b62..65b95935f 100644 --- a/packages/manifold/src/index.ts +++ b/packages/manifold/src/index.ts @@ -5,6 +5,7 @@ import type { } from '@rabbitholegg/questdk' import { + getExternalUrl, getFees, getMintIntent, getProjectFees, @@ -23,6 +24,8 @@ export const Manifold: IActionPlugin = { getProjectFees(params as unknown as MintActionParams), getFees: async (params: ActionParams) => getFees(params as unknown as MintActionParams), + getExternalUrl: async (params: ActionParams) => + getExternalUrl(params as unknown as MintActionParams), getMintIntent, simulateMint, } From af0777ecbc6f04681aebaef89bdae1f6f50ee538 Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 18:49:07 -0700 Subject: [PATCH 3/4] chore: generate changeset --- .changeset/lovely-pans-approve.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/lovely-pans-approve.md diff --git a/.changeset/lovely-pans-approve.md b/.changeset/lovely-pans-approve.md new file mode 100644 index 000000000..e74d039f7 --- /dev/null +++ b/.changeset/lovely-pans-approve.md @@ -0,0 +1,5 @@ +--- +"@rabbitholegg/questdk-plugin-manifold": minor +--- + +implement getExternalUrl function From bd70f6471858a92b8ee3f44c71f5cfc707c0aa5c Mon Sep 17 00:00:00 2001 From: mmackz Date: Mon, 15 Jul 2024 18:49:50 -0700 Subject: [PATCH 4/4] chore: format --- packages/manifold/src/Manifold.test.ts | 10 ++++++++-- packages/manifold/src/Manifold.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/manifold/src/Manifold.test.ts b/packages/manifold/src/Manifold.test.ts index 1073e026d..22628feaf 100644 --- a/packages/manifold/src/Manifold.test.ts +++ b/packages/manifold/src/Manifold.test.ts @@ -1,4 +1,10 @@ -import { getExternalUrl, getFees, getMintIntent, mint, simulateMint } from './Manifold' +import { + getExternalUrl, + getFees, + getMintIntent, + mint, + simulateMint, +} from './Manifold' import { ERC721_CONTRACT, ERC1155_CONTRACT } from './constants' import { failingTestCases, passingTestCases } from './test-transactions' import { apply } from '@rabbitholegg/questdk' @@ -247,4 +253,4 @@ describe('getExternalUrl function', () => { const result = await getExternalUrl(mint) expect(result).toBe('https://app.manifold.xyz/') }) -}) \ No newline at end of file +}) diff --git a/packages/manifold/src/Manifold.ts b/packages/manifold/src/Manifold.ts index 7ecdb6403..305e64c85 100644 --- a/packages/manifold/src/Manifold.ts +++ b/packages/manifold/src/Manifold.ts @@ -214,7 +214,9 @@ export const getFees = async ( } } -export const getExternalUrl = async (mint: MintActionParams): Promise => { +export const getExternalUrl = async ( + mint: MintActionParams, +): Promise => { const { chainId, contractAddress, tokenId } = mint const baseUrl = 'https://app.manifold.xyz/' @@ -225,10 +227,12 @@ export const getExternalUrl = async (mint: MintActionParams): Promise => contractAddress, tokenId ?? 1, ) - - const { data } = await axios.get<{ slug?: string }>(`https://apps.api.manifoldxyz.dev/public/instance/data?id=${instanceId}`) + + const { data } = await axios.get<{ slug?: string }>( + `https://apps.api.manifoldxyz.dev/public/instance/data?id=${instanceId}`, + ) const slug = data.slug - + if (!slug) { throw new Error('Slug not found in response') }