Skip to content

Commit

Permalink
Merge pull request #501 from rabbitholegg/matthew/boost-4345-update-e…
Browse files Browse the repository at this point in the history
…xternalurl-actiontype

feat: add actionType to getExternalUrl
  • Loading branch information
mmackz authored Aug 8, 2024
2 parents 9e81e1f + a9f45e4 commit 72f923d
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 38 deletions.
8 changes: 8 additions & 0 deletions .changeset/beige-rats-reflect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@rabbitholegg/questdk-plugin-registry": minor
"@rabbitholegg/questdk-plugin-titles": minor
"@rabbitholegg/questdk-plugin-utils": minor
"@rabbitholegg/questdk-plugin-zora": minor
---

add optional actionType to getExternalUrl
8 changes: 6 additions & 2 deletions packages/registry/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
26 changes: 20 additions & 6 deletions packages/titles/src/Titles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from './test-transactions'
import { apply } from '@rabbitholegg/questdk'
import {
ActionType,
Chains,
type MintIntentParams,
} from '@rabbitholegg/questdk-plugin-utils'
Expand Down Expand Up @@ -184,16 +185,29 @@ describe('simulateMint function', () => {
})

describe('getExternalUrl function', () => {
test('should return the correct URL for a V2 mint', () => {
const url = getExternalUrl({
chainId: Chains.BASE,
contractAddress: '0x432f4ccc39ab8dd8015f590a56244becb8d16933',
tokenId: 1,
})
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', () => {
Expand Down
25 changes: 19 additions & 6 deletions packages/titles/src/Titles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {
compressJson,
} from '@rabbitholegg/questdk'
import {
ActionParams,
ActionType,
Chains,
DEFAULT_ACCOUNT,
DEFAULT_REFERRAL,
Expand Down Expand Up @@ -164,14 +166,25 @@ 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 (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'
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 (
Expand Down
3 changes: 1 addition & 2 deletions packages/titles/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
5 changes: 4 additions & 1 deletion packages/utils/src/types/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ export interface IActionPlugin {
getFees?: (
params: ActionParams,
) => Promise<{ actionFee: bigint; projectFee: bigint }>
getExternalUrl?: (params: ActionParams) => Promise<string>
getExternalUrl?: (
params: ActionParams,
actionType?: ActionType,
) => Promise<string>
validate?: (
validationPayload: PluginActionValidation,
) =>
Expand Down
16 changes: 12 additions & 4 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
)
Expand All @@ -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}`,
)
Expand All @@ -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',
)
Expand All @@ -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')
})
})
41 changes: 26 additions & 15 deletions packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ 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,
Expand Down Expand Up @@ -443,21 +446,29 @@ export const getDynamicNameParams = async (
}

export const getExternalUrl = async (
params: MintActionParams,
params: ActionParams,
actionType?: ActionType,
): Promise<string> => {
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
Expand Down
3 changes: 1 addition & 2 deletions packages/zora/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit 72f923d

Please sign in to comment.