Skip to content

Commit

Permalink
Merge pull request #493 from rabbitholegg/mmackz/zora-externalurl-bas…
Browse files Browse the repository at this point in the history
…e-sepolia

feat(zora): add support for testnet url generation
  • Loading branch information
Quazia authored Jul 23, 2024
2 parents 69e9aa2 + f6b75d5 commit 7afba95
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/quick-ladybugs-repair.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rabbitholegg/questdk-plugin-utils": minor
"@rabbitholegg/questdk-plugin-zora": minor
---

add support for testnet url generation
1 change: 1 addition & 0 deletions packages/utils/src/constants/chain-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ export enum Chains {
SCROLL = 534352,
ZORA = 7777777,
SEPOLIA = 11155111,
BASE_SEPOLIA = 84532,
}
13 changes: 13 additions & 0 deletions packages/zora/src/Zora.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -557,4 +557,17 @@ describe('getExternalUrl function', () => {
'https://zora.co/collect/zora:0x393c46fe7887697124A73f6028f39751aA1961a3?referrer=0x1234567890123456789012345678901234567890',
)
})

test('should return correct url for testnet mint', async () => {
const params = {
chainId: Chains.BASE_SEPOLIA,
contractAddress: getAddress('0x627a509d76498ddd7d80a28ef4cd887b5b6df2cd'),
tokenId: 39,
referral: getAddress('0xe3bBA2A4F8E0F5C32EF5097F988a4d88075C8B48'),
}
const result = await getExternalUrl(params)
expect(result).toBe(
'https://testnet.zora.co/collect/bsep:0x627a509D76498DDD7D80a28eF4cD887B5b6df2Cd/39?referrer=0xe3bBA2A4F8E0F5C32EF5097F988a4d88075C8B48',
)
})
})
20 changes: 15 additions & 5 deletions packages/zora/src/Zora.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
import { formatAmount } from '@rabbitholegg/questdk-plugin-utils'
import {
ActionType,
Chains,
DEFAULT_ACCOUNT,
DEFAULT_REFERRAL as ZORA_DEPLOYER_ADDRESS,
type DisctriminatedActionParams,
Expand Down Expand Up @@ -445,10 +446,19 @@ export const getExternalUrl = async (
): Promise<string> => {
const { chainId, contractAddress, tokenId, referral } = params
const chainSlug = CHAIN_ID_TO_ZORA_SLUG[chainId]
const referralParams = `?referrer=${referral ?? ZORA_DEPLOYER_ADDRESS}`
const baseUrl = `https://zora.co/collect/${chainSlug}:${contractAddress}`
const isTestnet =
chainId === Chains.BASE_SEPOLIA || chainId === Chains.SEPOLIA

return tokenId != null
? `${baseUrl}/${tokenId}${referralParams}`
: `${baseUrl}${referralParams}`
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}`
}

// fallback to default zora url
return 'https://zora.co'
}
2 changes: 2 additions & 0 deletions packages/zora/src/chain-ids.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ export const CHAIN_ID_ARRAY = [
export const CHAIN_ID_TO_ZORA_SLUG: Record<number, string> = {
[Chains.ARBITRUM_ONE]: 'arb',
[Chains.BASE]: 'base',
[Chains.BASE_SEPOLIA]: 'bsep',
[Chains.BLAST]: 'blast',
[Chains.ETHEREUM]: 'eth',
[Chains.OPTIMISM]: 'oeth',
[Chains.ZORA]: 'zora',
[Chains.SEPOLIA]: 'sep',
}

0 comments on commit 7afba95

Please sign in to comment.