From 8aa81ecba0dfcad2ae13f8c4c06ff70d8012805a Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 11:55:05 -0700 Subject: [PATCH 1/7] feat(utils): add optional actionType param to getExternalUrl --- packages/utils/src/types/actions.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/types/actions.ts b/packages/utils/src/types/actions.ts index e4cbac8dd..d4963318a 100644 --- a/packages/utils/src/types/actions.ts +++ b/packages/utils/src/types/actions.ts @@ -539,7 +539,7 @@ export interface IActionPlugin { getFees?: ( params: ActionParams, ) => Promise<{ actionFee: bigint; projectFee: bigint }> - getExternalUrl?: (params: ActionParams) => Promise + getExternalUrl?: (params: ActionParams, actionType?: ActionType) => Promise validate?: ( validationPayload: PluginActionValidation, ) => From f1ad8d0ea6809602d0d16ec41c4cac99d586a77f Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 11:55:33 -0700 Subject: [PATCH 2/7] feat(zora): derive different url based on actiontype --- packages/zora/src/Zora.test.ts | 16 ++++++++++---- packages/zora/src/Zora.ts | 38 ++++++++++++++++++++-------------- packages/zora/src/index.ts | 3 +-- 3 files changed, 36 insertions(+), 21 deletions(-) diff --git a/packages/zora/src/Zora.test.ts b/packages/zora/src/Zora.test.ts index ff50b52d1..69fdd0ac4 100644 --- a/packages/zora/src/Zora.test.ts +++ b/packages/zora/src/Zora.test.ts @@ -528,7 +528,7 @@ describe('getExternalUrl function', () => { tokenId: 1, referral: getAddress('0x1234567890123456789012345678901234567890'), } - const result = await getExternalUrl(params) + const result = await getExternalUrl(params, ActionType.Mint) expect(result).toBe( 'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3/1?referrer=0x1234567890123456789012345678901234567890', ) @@ -540,7 +540,7 @@ describe('getExternalUrl function', () => { contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), tokenId: 1, } - const result = await getExternalUrl(params) + const result = await getExternalUrl(params, ActionType.Mint) expect(result).toBe( `https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3/1?referrer=${ZORA_DEPLOYER_ADDRESS}`, ) @@ -552,7 +552,7 @@ describe('getExternalUrl function', () => { contractAddress: getAddress('0x393c46fe7887697124a73f6028f39751aa1961a3'), referral: getAddress('0x1234567890123456789012345678901234567890'), } - const result = await getExternalUrl(params) + const result = await getExternalUrl(params, ActionType.Mint) expect(result).toBe( 'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3?referrer=0x1234567890123456789012345678901234567890', ) @@ -565,9 +565,17 @@ describe('getExternalUrl function', () => { tokenId: 39, referral: getAddress('0xe3bBA2A4F8E0F5C32EF5097F988a4d88075C8B48'), } - const result = await getExternalUrl(params) + const result = await getExternalUrl(params, ActionType.Mint) expect(result).toBe( 'https://testnet.zora.co/collect/bsep:0x627a509D76498DDD7D80a28eF4cD887B5b6df2Cd/39?referrer=0xe3bBA2A4F8E0F5C32EF5097F988a4d88075C8B48', ) }) + + test('should return correct url for create', async () => { + const params = { + chainId: Chains.ZORA, + } + const result = await getExternalUrl(params, ActionType.Create) + expect(result).toBe('https://zora.co/create') + }) }) diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 259c9ceba..3ab8533d4 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -19,7 +19,7 @@ import { type TransactionFilter, compressJson, } from '@rabbitholegg/questdk' -import { formatAmountToFilterOperator } from '@rabbitholegg/questdk-plugin-utils' +import { ActionParams, formatAmountToFilterOperator } from '@rabbitholegg/questdk-plugin-utils' import { ActionType, Chains, @@ -443,21 +443,29 @@ export const getDynamicNameParams = async ( } export const getExternalUrl = async ( - params: MintActionParams, + params: ActionParams, + actionType?: ActionType, ): Promise => { - const { chainId, contractAddress, tokenId, referral } = params - const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId] - const isTestnet = - chainId === Chains.BASE_SEPOLIA || chainId === Chains.SEPOLIA - - if (chainSlug) { - const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}` - const domain = isTestnet ? 'testnet.zora.co' : 'zora.co' - const baseUrl = `https://${domain}/collect/${chainSlug}:${contractAddress}` - - return tokenId != null - ? `${baseUrl}/${tokenId}${referralParams}` - : `${baseUrl}${referralParams}` + + if (actionType === ActionType.Mint) { + const { chainId, contractAddress, tokenId, referral } = params as MintActionParams + const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId] + const isTestnet = + chainId === Chains.BASE_SEPOLIA || chainId === Chains.SEPOLIA + + if (chainSlug) { + const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}` + const domain = isTestnet ? 'testnet.zora.co' : 'zora.co' + const baseUrl = `https://${domain}/collect/${chainSlug}:${contractAddress}` + + return tokenId != null + ? `${baseUrl}/${tokenId}${referralParams}` + : `${baseUrl}${referralParams}` + } + } + + if (actionType === ActionType.Create) { + return 'https://zora.co/create' } // fallback to default zora url diff --git a/packages/zora/src/index.ts b/packages/zora/src/index.ts index e03944aa7..b3aeb651e 100644 --- a/packages/zora/src/index.ts +++ b/packages/zora/src/index.ts @@ -29,8 +29,7 @@ export const Zora: IActionPlugin = { swap: async () => new PluginActionNotImplementedError(), mint, getDynamicNameParams, - getExternalUrl: async (params: ActionParams) => - getExternalUrl(params as unknown as MintActionParams), + getExternalUrl, getProjectFees: async (params: ActionParams) => getProjectFees(params as unknown as MintActionParams), getFees: async (params: ActionParams) => From d256dcc4331376498df934ca4d23a6e74783cc86 Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 11:55:40 -0700 Subject: [PATCH 3/7] feat(titles): derive different url based on actiontype --- packages/titles/src/Titles.test.ts | 16 +++++++++++++--- packages/titles/src/Titles.ts | 23 +++++++++++++++++------ packages/titles/src/index.ts | 3 +-- 3 files changed, 31 insertions(+), 11 deletions(-) diff --git a/packages/titles/src/Titles.test.ts b/packages/titles/src/Titles.test.ts index c6644bc45..00180f1de 100644 --- a/packages/titles/src/Titles.test.ts +++ b/packages/titles/src/Titles.test.ts @@ -14,6 +14,7 @@ import { } from './test-transactions' import { apply } from '@rabbitholegg/questdk' import { + ActionType, Chains, type MintIntentParams, } from '@rabbitholegg/questdk-plugin-utils' @@ -184,16 +185,25 @@ describe('simulateMint function', () => { }) describe('getExternalUrl function', () => { - test('should return the correct URL for a V2 mint', () => { - const url = getExternalUrl({ + test('should return the correct URL for a V2 mint', async () => { + const url = await getExternalUrl({ chainId: Chains.BASE, contractAddress: '0x432f4ccc39ab8dd8015f590a56244becb8d16933', tokenId: 1, - }) + }, ActionType.Mint) expect(url).toEqual( 'https://titles.xyz/collect/base/0x432f4ccc39ab8dd8015f590a56244becb8d16933/1', ) }) + + test('should return the correct URL for a create action', async () => { + const url = await getExternalUrl({ + chainId: Chains.BASE, + }, ActionType.Create) + expect(url).toEqual( + 'https://titles.xyz/create', + ) + }) }) describe('getMintIntent function', () => { diff --git a/packages/titles/src/Titles.ts b/packages/titles/src/Titles.ts index 1e033b4fb..217a5e7e1 100644 --- a/packages/titles/src/Titles.ts +++ b/packages/titles/src/Titles.ts @@ -12,6 +12,8 @@ import { compressJson, } from '@rabbitholegg/questdk' import { + ActionParams, + ActionType, Chains, DEFAULT_ACCOUNT, DEFAULT_REFERRAL, @@ -164,14 +166,23 @@ export const simulateMint = async ( return result } -export function getExternalUrl(params: MintActionParams): string { - const { chainId, contractAddress, tokenId } = params - const slug = CHAIN_ID_TO_SLUG[chainId] +export async function getExternalUrl(params: ActionParams, actionType?: ActionType) { - if (!slug || !contractAddress || !tokenId) { - return 'https://titles.xyz' + if (actionType === ActionType.Mint) { + const { chainId, contractAddress, tokenId } = params as MintActionParams + const slug = CHAIN_ID_TO_SLUG[chainId] + + if (!slug || !contractAddress || !tokenId) { + return 'https://titles.xyz' + } + return `https://titles.xyz/collect/${slug}/${contractAddress}/${tokenId}` + } + + if (actionType === ActionType.Create) { + return 'https://titles.xyz/create' } - return `https://titles.xyz/collect/${slug}/${contractAddress}/${tokenId}` + + return 'https://titles.xyz' } export const getSupportedTokenAddresses = async ( diff --git a/packages/titles/src/index.ts b/packages/titles/src/index.ts index 61e2397db..079f15845 100644 --- a/packages/titles/src/index.ts +++ b/packages/titles/src/index.ts @@ -24,8 +24,7 @@ export const Titles: IActionPlugin = { getMintIntent, mint, simulateMint, - getExternalUrl: async (params: ActionParams) => - getExternalUrl(params as unknown as MintActionParams), + getExternalUrl, getProjectFees: async (params: ActionParams) => getProjectFees(params as unknown as MintActionParams), getFees: async (params: ActionParams) => From c3416d8b85e7095c92b6fd87f601035981339328 Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 11:56:10 -0700 Subject: [PATCH 4/7] chore: format --- packages/titles/src/Titles.test.ts | 24 ++++++++++++++---------- packages/titles/src/Titles.ts | 8 +++++--- packages/utils/src/types/actions.ts | 5 ++++- packages/zora/src/Zora.ts | 13 ++++++++----- 4 files changed, 31 insertions(+), 19 deletions(-) diff --git a/packages/titles/src/Titles.test.ts b/packages/titles/src/Titles.test.ts index 00180f1de..e181275d4 100644 --- a/packages/titles/src/Titles.test.ts +++ b/packages/titles/src/Titles.test.ts @@ -186,23 +186,27 @@ describe('simulateMint function', () => { describe('getExternalUrl function', () => { test('should return the correct URL for a V2 mint', async () => { - const url = await getExternalUrl({ - chainId: Chains.BASE, - contractAddress: '0x432f4ccc39ab8dd8015f590a56244becb8d16933', - tokenId: 1, - }, ActionType.Mint) + const url = await getExternalUrl( + { + chainId: Chains.BASE, + contractAddress: '0x432f4ccc39ab8dd8015f590a56244becb8d16933', + tokenId: 1, + }, + ActionType.Mint, + ) expect(url).toEqual( 'https://titles.xyz/collect/base/0x432f4ccc39ab8dd8015f590a56244becb8d16933/1', ) }) test('should return the correct URL for a create action', async () => { - const url = await getExternalUrl({ - chainId: Chains.BASE, - }, ActionType.Create) - expect(url).toEqual( - 'https://titles.xyz/create', + const url = await getExternalUrl( + { + chainId: Chains.BASE, + }, + ActionType.Create, ) + expect(url).toEqual('https://titles.xyz/create') }) }) diff --git a/packages/titles/src/Titles.ts b/packages/titles/src/Titles.ts index 217a5e7e1..fe76f177c 100644 --- a/packages/titles/src/Titles.ts +++ b/packages/titles/src/Titles.ts @@ -166,12 +166,14 @@ export const simulateMint = async ( return result } -export async function getExternalUrl(params: ActionParams, actionType?: ActionType) { - +export async function getExternalUrl( + params: ActionParams, + actionType?: ActionType, +) { if (actionType === ActionType.Mint) { const { chainId, contractAddress, tokenId } = params as MintActionParams const slug = CHAIN_ID_TO_SLUG[chainId] - + if (!slug || !contractAddress || !tokenId) { return 'https://titles.xyz' } diff --git a/packages/utils/src/types/actions.ts b/packages/utils/src/types/actions.ts index d4963318a..6e8a0a8cc 100644 --- a/packages/utils/src/types/actions.ts +++ b/packages/utils/src/types/actions.ts @@ -539,7 +539,10 @@ export interface IActionPlugin { getFees?: ( params: ActionParams, ) => Promise<{ actionFee: bigint; projectFee: bigint }> - getExternalUrl?: (params: ActionParams, actionType?: ActionType) => Promise + getExternalUrl?: ( + params: ActionParams, + actionType?: ActionType, + ) => Promise validate?: ( validationPayload: PluginActionValidation, ) => diff --git a/packages/zora/src/Zora.ts b/packages/zora/src/Zora.ts index 3ab8533d4..7c4f4518d 100644 --- a/packages/zora/src/Zora.ts +++ b/packages/zora/src/Zora.ts @@ -19,7 +19,10 @@ import { type TransactionFilter, compressJson, } from '@rabbitholegg/questdk' -import { ActionParams, formatAmountToFilterOperator } from '@rabbitholegg/questdk-plugin-utils' +import { + ActionParams, + formatAmountToFilterOperator, +} from '@rabbitholegg/questdk-plugin-utils' import { ActionType, Chains, @@ -446,18 +449,18 @@ export const getExternalUrl = async ( params: ActionParams, actionType?: ActionType, ): Promise => { - if (actionType === ActionType.Mint) { - const { chainId, contractAddress, tokenId, referral } = params as MintActionParams + const { chainId, contractAddress, tokenId, referral } = + params as MintActionParams const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId] const isTestnet = chainId === Chains.BASE_SEPOLIA || chainId === Chains.SEPOLIA - + if (chainSlug) { const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}` const domain = isTestnet ? 'testnet.zora.co' : 'zora.co' const baseUrl = `https://${domain}/collect/${chainSlug}:${contractAddress}` - + return tokenId != null ? `${baseUrl}/${tokenId}${referralParams}` : `${baseUrl}${referralParams}` From 7284c9f7aee7ed78463be945610a7d2cfb27d82d Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 11:56:51 -0700 Subject: [PATCH 5/7] chore: generate changeset --- .changeset/beige-rats-reflect.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .changeset/beige-rats-reflect.md diff --git a/.changeset/beige-rats-reflect.md b/.changeset/beige-rats-reflect.md new file mode 100644 index 000000000..5e1e88c05 --- /dev/null +++ b/.changeset/beige-rats-reflect.md @@ -0,0 +1,7 @@ +--- +"@rabbitholegg/questdk-plugin-titles": minor +"@rabbitholegg/questdk-plugin-utils": minor +"@rabbitholegg/questdk-plugin-zora": minor +--- + +add optional actionType to getExternalUrl From 2f188572e17fd3c9941d952749a718316aec0aff Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 12:38:54 -0700 Subject: [PATCH 6/7] feat: add actionType to getExternalUrl export in registry --- packages/registry/src/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/registry/src/index.ts b/packages/registry/src/index.ts index 384627eae..811b45dea 100644 --- a/packages/registry/src/index.ts +++ b/packages/registry/src/index.ts @@ -209,9 +209,13 @@ export const getFees = ( } } -export const getExternalUrl = (plugin: IActionPlugin, params: ActionParams) => { +export const getExternalUrl = ( + plugin: IActionPlugin, + params: ActionParams, + actionType?: ActionType, +) => { if (typeof plugin.getExternalUrl === 'function') { - return plugin.getExternalUrl(params) + return plugin.getExternalUrl(params, actionType) } else { throw new PluginActionNotImplementedError() } From a9f45e420fd74589132545ee4a661031699e06b9 Mon Sep 17 00:00:00 2001 From: mmackz Date: Wed, 31 Jul 2024 12:39:58 -0700 Subject: [PATCH 7/7] chore: add registry to changeset --- .changeset/beige-rats-reflect.md | 1 + 1 file changed, 1 insertion(+) diff --git a/.changeset/beige-rats-reflect.md b/.changeset/beige-rats-reflect.md index 5e1e88c05..231b58e75 100644 --- a/.changeset/beige-rats-reflect.md +++ b/.changeset/beige-rats-reflect.md @@ -1,4 +1,5 @@ --- +"@rabbitholegg/questdk-plugin-registry": minor "@rabbitholegg/questdk-plugin-titles": minor "@rabbitholegg/questdk-plugin-utils": minor "@rabbitholegg/questdk-plugin-zora": minor