From 154e60073dc59e871b1085a1424a5e3c27501a19 Mon Sep 17 00:00:00 2001 From: spacehaz Date: Thu, 6 Jun 2024 14:51:31 +0300 Subject: [PATCH 1/5] added updates for apikey --- CHANGELOG.md | 3 +++ package.json | 2 +- src/api/batch/index.ts | 12 ++++++++---- src/api/batch/types.ts | 4 ++++ src/api/campaign/index.ts | 3 ++- src/api/campaign/types.ts | 1 + src/api/link/index.ts | 6 ++++-- src/api/link/types.ts | 2 ++ src/helpers/define-request-key-header.ts | 16 ++++++++++++++-- src/modules/batch/index.ts | 6 +++++- src/modules/campaign/index.ts | 13 +++++++++++-- src/modules/linkdrop-sdk/index.ts | 12 +++++++++++- 12 files changed, 66 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d9d457..a7ad7fc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Linkdrop SDK +## 2.1.0 +- added apiKey as param for LinkdropSDK + ## 2.0.9 - added src param to link (src=d) diff --git a/package.json b/package.json index f322463..e9b5e38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkdrop-sdk", - "version": "2.0.9", + "version": "2.1.0", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/api/batch/index.ts b/src/api/batch/index.ts index 6b4cce0..44724c1 100644 --- a/src/api/batch/index.ts +++ b/src/api/batch/index.ts @@ -5,33 +5,36 @@ import { defineRequestKeyHeader } from '../../helpers' const requests: TRequests = { getBatches: ( apiHost, + apiKey, campaignSig, campaignId ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches`, { headers, }) }, getBatch: ( apiHost, + apiKey, campaignSig, campaignId, batchId ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches/${batchId}`, { headers, }) }, createBatch: ( apiHost, + apiKey, campaignSig, campaignId, claimLinks, batchDescription ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/save-batch`, { claim_links: claimLinks, batch_description: batchDescription @@ -41,12 +44,13 @@ const requests: TRequests = { }, addLinks: ( apiHost, + apiKey, campaignSig, campaignId, batchId, claimLinks, ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}/batches/${batchId}/add-links `, { claim_links: claimLinks }, { diff --git a/src/api/batch/types.ts b/src/api/batch/types.ts index aa92bca..6c734ab 100644 --- a/src/api/batch/types.ts +++ b/src/api/batch/types.ts @@ -29,6 +29,7 @@ type TAddLinksResponse = { export type TGetBatches = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string ) => Promise< @@ -39,6 +40,7 @@ export type TGetBatches = ( export type TGetBatch = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, batchId: string @@ -50,6 +52,7 @@ export type TGetBatch = ( export type TCreateBatch = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, claimLinks: TLinkItem[], @@ -62,6 +65,7 @@ export type TCreateBatch = ( export type TAddLinks = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, batchId: string, diff --git a/src/api/campaign/index.ts b/src/api/campaign/index.ts index f94d708..d246fdb 100644 --- a/src/api/campaign/index.ts +++ b/src/api/campaign/index.ts @@ -5,10 +5,11 @@ import { defineRequestKeyHeader } from '../../helpers' const requests: TRequests = { getCampaign: ( apiHost, + apiKey, campaignSig, campaignId ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.get(`${apiHost}/api/v2/dashboard/linkdrop/campaigns/${campaignId}`, { headers }) diff --git a/src/api/campaign/types.ts b/src/api/campaign/types.ts index 51b0a6b..c2f851b 100644 --- a/src/api/campaign/types.ts +++ b/src/api/campaign/types.ts @@ -8,6 +8,7 @@ type TGetCampaignResponse = { export type TGetCampaign = ( apiHost: string, + apiKey: string, campaignSig: string, campaignId: string, ) => Promise< diff --git a/src/api/link/index.ts b/src/api/link/index.ts index 066fb50..43ffda6 100644 --- a/src/api/link/index.ts +++ b/src/api/link/index.ts @@ -17,20 +17,22 @@ const requests: TRequests = { }, deactivateLink: ( apiHost, + apiKey, campaignSig, linkId ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/claim-links/${linkId}/deactivate`, {}, { headers }) }, reactivateLink: ( apiHost, + apiKey, campaignSig, linkId ) => { - const headers = defineRequestKeyHeader(campaignSig) + const headers = defineRequestKeyHeader(campaignSig, apiKey) return axios.post(`${apiHost}/api/v2/dashboard/linkdrop/claim-links/${linkId}/reactivate`, {}, { headers }) diff --git a/src/api/link/types.ts b/src/api/link/types.ts index ec5fabb..11031be 100644 --- a/src/api/link/types.ts +++ b/src/api/link/types.ts @@ -48,6 +48,7 @@ export type TGetLinkStatus = ( export type TDeactivateLink = ( apiHost: string, + apiKey: string, campaignSig: string, linkId: string ) => Promise< @@ -69,6 +70,7 @@ export type TRedeemLink = ( export type TReactivateLink = ( apiHost: string, + apiKey: string, campaignSig: string, linkId: string ) => Promise< diff --git a/src/helpers/define-request-key-header.ts b/src/helpers/define-request-key-header.ts index 882a665..cbd3f21 100644 --- a/src/helpers/define-request-key-header.ts +++ b/src/helpers/define-request-key-header.ts @@ -1,9 +1,21 @@ -type TDefineRequestKeyHeader = (campaignSig: string) => Record -const defineRequestKeyHeader: TDefineRequestKeyHeader = (campaignSig) => { +type TDefineRequestKeyHeader = ( + campaignSig: string, + apiKey: string +) => Record + +const defineRequestKeyHeader: TDefineRequestKeyHeader = ( + campaignSig, + apiKey +) => { const headers = {} headers[ 'X-CAMPAIGN-KEY' ] = campaignSig + + if (apiKey) { + headers['authorization'] = `Bearer ${apiKey}` + } + return headers } diff --git a/src/modules/batch/index.ts b/src/modules/batch/index.ts index 5d20717..a7f9ab1 100644 --- a/src/modules/batch/index.ts +++ b/src/modules/batch/index.ts @@ -15,6 +15,7 @@ class Batch implements IBatch { claimHostUrl: string campaignData: TCampaignItem signerKey: string + apiKey: string constructor ( batchId: string, @@ -25,7 +26,8 @@ class Batch implements IBatch { campaignData: TCampaignItem, signerKey: string, campaignSig: string, - apiHost: string + apiHost: string, + apiKey: string ) { this.batchId = batchId this.data = data @@ -36,6 +38,7 @@ class Batch implements IBatch { this.claimHostUrl = claimHostUrl this.campaignData = campaignData this.signerKey = signerKey + this.apiKey = apiKey } addLinks: TAddLinks = async ( @@ -66,6 +69,7 @@ class Batch implements IBatch { if (!transformedAssets) { return alert('Error with assets') } return await batchesApi.addLinks( this.apiHost, + this.apiKey, this.campaignSig, this.campaignData.campaign_id, this.batchId, diff --git a/src/modules/campaign/index.ts b/src/modules/campaign/index.ts index 2bb040b..fdd5401 100644 --- a/src/modules/campaign/index.ts +++ b/src/modules/campaign/index.ts @@ -19,6 +19,7 @@ class Campaign implements ICampaign { apiHost: string claimHostUrl: string campaignSig: string + apiKey: string constructor ( campaignId: string, @@ -27,7 +28,8 @@ class Campaign implements ICampaign { data: TCampaignItem, claimHostUrl: string, campaignSig: string, - apiHost: string + apiHost: string, + apiKey: string ) { this.campaignId = campaignId this.signerKey = signerKey @@ -36,11 +38,13 @@ class Campaign implements ICampaign { this.claimHostUrl = claimHostUrl this.apiHost = apiHost this.campaignSig = campaignSig + this.apiKey = apiKey } getBatches: TGetBatches = async () => { const campaignData = await batchesApi.getBatches( this.apiHost, + this.apiKey, this.campaignSig, this.campaignId ) @@ -59,6 +63,7 @@ class Campaign implements ICampaign { ) => { const campaignData = await batchesApi.getBatch( this.apiHost, + this.apiKey, this.campaignSig, this.campaignId, batchId @@ -75,7 +80,8 @@ class Campaign implements ICampaign { this.data, this.signerKey, this.campaignSig, - this.apiHost + this.apiHost, + this.apiKey ) } } @@ -110,6 +116,7 @@ class Campaign implements ICampaign { if (!transformedAssets) { return alert('Error with assets') } const response = await batchesApi.createBatch( this.apiHost, + this.apiKey, this.campaignSig, this.data.campaign_id, transformedAssets, @@ -139,6 +146,7 @@ class Campaign implements ICampaign { const linkData = await linkApi.reactivateLink( this.apiHost, + this.apiKey, this.campaignSig, wallet.address ) @@ -157,6 +165,7 @@ class Campaign implements ICampaign { const linkData = await linkApi.deactivateLink( this.apiHost, + this.apiKey, this.campaignSig, wallet.address ) diff --git a/src/modules/linkdrop-sdk/index.ts b/src/modules/linkdrop-sdk/index.ts index f774372..bb73ea1 100644 --- a/src/modules/linkdrop-sdk/index.ts +++ b/src/modules/linkdrop-sdk/index.ts @@ -14,6 +14,7 @@ class LinkdropSDK implements ILinkdropSDK { chain: TNetworkName apiHost: string claimHostUrl: string + apiKey: string utils = { createLink, computeProxyAddress, @@ -21,15 +22,22 @@ class LinkdropSDK implements ILinkdropSDK { } constructor ({ + apiKey, apiHost, mode, claimHostUrl }: { + apiKey?: string, apiHost?: string, mode?: 'testnets', claimHostUrl?: string } = {}) { this.claimHostUrl = claimHostUrl || '' + if (!apiKey) { + throw new Error('ApiKey required') + } else { + this.apiKey = apiKey + } if (apiHost) { this.apiHost = apiHost } else { @@ -58,6 +66,7 @@ class LinkdropSDK implements ILinkdropSDK { ) const campaignData = await campaignsApi.getCampaign( this.apiHost, + this.apiKey, campaignSig, campaignId ) @@ -71,7 +80,8 @@ class LinkdropSDK implements ILinkdropSDK { campaign, this.claimHostUrl, campaignSig, - this.apiHost + this.apiHost, + this.apiKey ) } } From 5f8b5cc4102f3afba0c304841af7d2e5e9966df8 Mon Sep 17 00:00:00 2001 From: spacehaz Date: Thu, 6 Jun 2024 15:04:37 +0300 Subject: [PATCH 2/5] added updates for README --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b63d9b3..11f568c 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,14 @@ import LinkdropSDK from 'linkdrop-sdk' To use SDK on a tesnet: ```ts // initializing Linkdrop SDK on a testnet (Goerli or Mumbai) -const sdk = new LinkdropSDK({ mode: 'testnets' }); +const apiKey = /* to request an API key, please contact us at hi@linkdrop.io */ +const sdk = new LinkdropSDK({ mode: 'testnets', apiKey }); ``` To use SDK on a production network (Ethereum Mainnet or Polygon): ```ts // initializing Linkdrop SDK on a production network -const sdk = new LinkdropSDK(); +const apiKey = /* to request an API key, please contact us at hi@linkdrop.io */ +const sdk = new LinkdropSDK({ apiKey }); ``` ## Claim methods (Can be used on Front-end & Back-end) From a2be1d56d588437dae0821272a3001eb537fa174 Mon Sep 17 00:00:00 2001 From: spacehaz Date: Fri, 7 Jun 2024 10:45:15 +0300 Subject: [PATCH 3/5] added new release --- CHANGELOG.md | 4 ++++ package.json | 2 +- src/configs/index.ts | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a7ad7fc..29ab5cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Linkdrop SDK + +## 2.1.1 +- added testnets apiUrl + ## 2.1.0 - added apiKey as param for LinkdropSDK diff --git a/package.json b/package.json index e9b5e38..6aded5a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkdrop-sdk", - "version": "2.1.0", + "version": "2.1.1", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/configs/index.ts b/src/configs/index.ts index 461b20e..d487344 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -1,5 +1,5 @@ export const apiUrl = 'https://dashboard-api.linkdrop.io' -export const testnetsApiUrl = 'https://testnets.dashboard-api.linkdrop.io' +export const testnetsApiUrl = 'https://linkdrop-api-testnets-b0fceb9.zuplo.app' export const polygonJSONRPCUrl = 'https://rpc-mainnet.maticvigil.com/v1/ad4cd2ea018ddb1ccd0418ffa43c27b3d99fbd55' export const mainnetJSONRPCUrl = 'https://mainnet.infura.io/v3/620c738fbe1843a18f47ada0e60e738a' From c8d082fb42c7f30606d6fc839d4795f4e0c01847 Mon Sep 17 00:00:00 2001 From: spacehaz Date: Mon, 10 Jun 2024 17:33:43 +0300 Subject: [PATCH 4/5] 2.1.2 release --- CHANGELOG.md | 3 +++ package.json | 2 +- src/configs/index.ts | 3 +++ src/helpers/define-claim-host-url.ts | 23 ++++++++++++++++++++++ src/helpers/index.ts | 2 ++ src/modules/batch/index.ts | 17 +++++++++++++--- src/modules/campaign/index.ts | 3 ++- src/modules/linkdrop-sdk/index.ts | 10 ++++++++-- src/types/modules/batch/get-links/index.ts | 4 +++- 9 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 src/helpers/define-claim-host-url.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 29ab5cf..5bd493e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Linkdrop SDK +## 2.1.2 +- updates for claimHostUrl param (getLinks method of batch) + ## 2.1.1 - added testnets apiUrl diff --git a/package.json b/package.json index 6aded5a..7845a78 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkdrop-sdk", - "version": "2.1.1", + "version": "2.1.2", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/configs/index.ts b/src/configs/index.ts index d487344..173d707 100644 --- a/src/configs/index.ts +++ b/src/configs/index.ts @@ -1,6 +1,9 @@ export const apiUrl = 'https://dashboard-api.linkdrop.io' export const testnetsApiUrl = 'https://linkdrop-api-testnets-b0fceb9.zuplo.app' +export const claimHostUrl = 'https://claim.linkdrop.io' +export const testnetsClaimHostUrl = 'https://testnets.claim.linkdrop.io' + export const polygonJSONRPCUrl = 'https://rpc-mainnet.maticvigil.com/v1/ad4cd2ea018ddb1ccd0418ffa43c27b3d99fbd55' export const mainnetJSONRPCUrl = 'https://mainnet.infura.io/v3/620c738fbe1843a18f47ada0e60e738a' export const goerliJSONRPCUrl = 'https://goeli.infura.io/v3/620c738fbe1843a18f47ada0e60e738a' diff --git a/src/helpers/define-claim-host-url.ts b/src/helpers/define-claim-host-url.ts new file mode 100644 index 0000000..186c03a --- /dev/null +++ b/src/helpers/define-claim-host-url.ts @@ -0,0 +1,23 @@ +import { claimHostUrl, testnetsClaimHostUrl } from '../configs' + +type TDefineClaimHostUrl = ( + chainId: number +) => string + +const defineClaimHostUrl: TDefineClaimHostUrl = ( + chainId +) => { + switch (chainId) { + case 80001: + case 84531: + case 5: + return testnetsClaimHostUrl + case 137: + case 1: + case 8453: + default: + return claimHostUrl + } +} + +export default defineClaimHostUrl diff --git a/src/helpers/index.ts b/src/helpers/index.ts index b116f64..7964f95 100644 --- a/src/helpers/index.ts +++ b/src/helpers/index.ts @@ -10,9 +10,11 @@ import redeemLink from './redeem-link' import getBignumberInterval from './get-bignumber-interval' import defineCampaignSig from './define-campaign-sig' import prepareAsset from './prepare-asset' +import defineClaimHostUrl from './define-claim-host-url' export { parseLinkParams, + defineClaimHostUrl, defineCampaignSig, getBignumberInterval, getLinkParams, diff --git a/src/modules/batch/index.ts b/src/modules/batch/index.ts index a7f9ab1..ee40e8d 100644 --- a/src/modules/batch/index.ts +++ b/src/modules/batch/index.ts @@ -16,6 +16,7 @@ class Batch implements IBatch { campaignData: TCampaignItem signerKey: string apiKey: string + chainId: number constructor ( batchId: string, @@ -27,7 +28,8 @@ class Batch implements IBatch { signerKey: string, campaignSig: string, apiHost: string, - apiKey: string + apiKey: string, + chainId: number ) { this.batchId = batchId this.data = data @@ -39,6 +41,7 @@ class Batch implements IBatch { this.campaignData = campaignData this.signerKey = signerKey this.apiKey = apiKey + this.chainId = chainId } addLinks: TAddLinks = async ( @@ -77,17 +80,25 @@ class Batch implements IBatch { ) } - getLinks: TGetLinks = () => { + getLinks: TGetLinks = ( + linkPattern + ) => { if (!this.claimLinks) { return [] } return this.claimLinks.map(link => { const encryptedClaimCode = link.encrypted_claim_code const claimCode = crypto.decrypt(encryptedClaimCode, this.encryptionKey) + + let finalLink = `${this.claimHostUrl}/#/redeem/${claimCode}?src=d` + if (linkPattern) { + finalLink = linkPattern.replace('', claimCode) + .replace('', String(this.chainId)) + } return { linkId: link.link_id, claimCode, - claimLink: `${this.claimHostUrl}/#/redeem/${claimCode}?src=d` + claimLink: finalLink } }) } diff --git a/src/modules/campaign/index.ts b/src/modules/campaign/index.ts index fdd5401..2036cfe 100644 --- a/src/modules/campaign/index.ts +++ b/src/modules/campaign/index.ts @@ -81,7 +81,8 @@ class Campaign implements ICampaign { this.signerKey, this.campaignSig, this.apiHost, - this.apiKey + this.apiKey, + this.data.chain_id ) } } diff --git a/src/modules/linkdrop-sdk/index.ts b/src/modules/linkdrop-sdk/index.ts index bb73ea1..da9da0b 100644 --- a/src/modules/linkdrop-sdk/index.ts +++ b/src/modules/linkdrop-sdk/index.ts @@ -1,6 +1,12 @@ import { ILinkdropSDK, TNetworkName } from '../../types' import Campaign from '../campaign' -import { defineCampaignSig, getLinkParams, getLinkStatus, redeemLink } from '../../helpers' +import { + defineCampaignSig, + getLinkParams, + getLinkStatus, + redeemLink, + defineClaimHostUrl +} from '../../helpers' import { campaignsApi } from '../../api' import { testnetsApiUrl, @@ -78,7 +84,7 @@ class LinkdropSDK implements ILinkdropSDK { signerKey, encryptionKey, campaign, - this.claimHostUrl, + this.claimHostUrl ? this.claimHostUrl : defineClaimHostUrl(campaign.chain_id), campaignSig, this.apiHost, this.apiKey diff --git a/src/types/modules/batch/get-links/index.ts b/src/types/modules/batch/get-links/index.ts index b946e20..eccf655 100644 --- a/src/types/modules/batch/get-links/index.ts +++ b/src/types/modules/batch/get-links/index.ts @@ -1,4 +1,6 @@ import { TLinkParsed } from '../../../' -type TGetLinks = () => TLinkParsed[] +type TGetLinks = ( + linkPattern?: string +) => TLinkParsed[] export default TGetLinks \ No newline at end of file From 2df82a43a6c3bb7dc20fb2d6267905b9ebcfa49b Mon Sep 17 00:00:00 2001 From: spacehaz Date: Mon, 10 Jun 2024 18:03:01 +0300 Subject: [PATCH 5/5] 2.1.3 release --- CHANGELOG.md | 3 +++ README.md | 10 ++++++++++ package.json | 2 +- src/helpers/define-claim-host-url.ts | 11 ++++------- src/modules/batch/index.ts | 5 +++-- src/modules/linkdrop-sdk/index.ts | 17 +++++++++++++---- src/types/index.ts | 2 ++ src/types/mode/index.ts | 3 +++ 8 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/types/mode/index.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bd493e..3c2f539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Linkdrop SDK +## 2.1.3 +- updates for src=d param (getLinks method of batch) + ## 2.1.2 - updates for claimHostUrl param (getLinks method of batch) diff --git a/README.md b/README.md index 11f568c..31274d2 100644 --- a/README.md +++ b/README.md @@ -250,6 +250,16 @@ To fetch all links created for that batch, use the `batch.getLinks` method: const links = await batch.getLinks() ``` +Response data includes claim links in format `https://claim.linkdrop.io/#/...` +If you need links in custom format please provide optional parameter to `getLinks` method +```ts +const links = await batch.getLinks('https://wallet.coinbase.com/claim?tk=code&k=&c=&v=3') +``` + +As a result you will get claim links with actual claim code (``) and chain id (``) + + + ### Deactivating / reactivating links #### Deactivate Link diff --git a/package.json b/package.json index 7845a78..f582269 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "linkdrop-sdk", - "version": "2.1.2", + "version": "2.1.3", "main": "dist/index.js", "types": "dist/index.d.ts", "files": [ diff --git a/src/helpers/define-claim-host-url.ts b/src/helpers/define-claim-host-url.ts index 186c03a..e82137d 100644 --- a/src/helpers/define-claim-host-url.ts +++ b/src/helpers/define-claim-host-url.ts @@ -1,20 +1,17 @@ import { claimHostUrl, testnetsClaimHostUrl } from '../configs' +import { TMode } from '../types' type TDefineClaimHostUrl = ( - chainId: number + mode: TMode ) => string const defineClaimHostUrl: TDefineClaimHostUrl = ( chainId ) => { switch (chainId) { - case 80001: - case 84531: - case 5: + case 'testnets': return testnetsClaimHostUrl - case 137: - case 1: - case 8453: + case 'mainnets': default: return claimHostUrl } diff --git a/src/modules/batch/index.ts b/src/modules/batch/index.ts index ee40e8d..ed211c3 100644 --- a/src/modules/batch/index.ts +++ b/src/modules/batch/index.ts @@ -90,15 +90,16 @@ class Batch implements IBatch { const encryptedClaimCode = link.encrypted_claim_code const claimCode = crypto.decrypt(encryptedClaimCode, this.encryptionKey) - let finalLink = `${this.claimHostUrl}/#/redeem/${claimCode}?src=d` + let finalLink = `${this.claimHostUrl}/#/redeem/${claimCode}` if (linkPattern) { finalLink = linkPattern.replace('', claimCode) .replace('', String(this.chainId)) } + const sourceParam = finalLink.includes('?') ? `&src=d` : '?src=d' return { linkId: link.link_id, claimCode, - claimLink: finalLink + claimLink: `${finalLink}${sourceParam}` } }) } diff --git a/src/modules/linkdrop-sdk/index.ts b/src/modules/linkdrop-sdk/index.ts index da9da0b..4203092 100644 --- a/src/modules/linkdrop-sdk/index.ts +++ b/src/modules/linkdrop-sdk/index.ts @@ -1,4 +1,8 @@ -import { ILinkdropSDK, TNetworkName } from '../../types' +import { + ILinkdropSDK, + TNetworkName, + TMode +} from '../../types' import Campaign from '../campaign' import { defineCampaignSig, @@ -21,6 +25,8 @@ class LinkdropSDK implements ILinkdropSDK { apiHost: string claimHostUrl: string apiKey: string + mode: TMode + utils = { createLink, computeProxyAddress, @@ -35,10 +41,13 @@ class LinkdropSDK implements ILinkdropSDK { }: { apiKey?: string, apiHost?: string, - mode?: 'testnets', + mode?: TMode, claimHostUrl?: string } = {}) { this.claimHostUrl = claimHostUrl || '' + + this.mode = mode || 'mainnets' + if (!apiKey) { throw new Error('ApiKey required') } else { @@ -47,7 +56,7 @@ class LinkdropSDK implements ILinkdropSDK { if (apiHost) { this.apiHost = apiHost } else { - this.apiHost = mode === 'testnets' ? testnetsApiUrl : apiUrl + this.apiHost = this.mode === 'testnets' ? testnetsApiUrl : apiUrl } } @@ -84,7 +93,7 @@ class LinkdropSDK implements ILinkdropSDK { signerKey, encryptionKey, campaign, - this.claimHostUrl ? this.claimHostUrl : defineClaimHostUrl(campaign.chain_id), + this.claimHostUrl ? this.claimHostUrl : defineClaimHostUrl(this.mode), campaignSig, this.apiHost, this.apiKey diff --git a/src/types/index.ts b/src/types/index.ts index 1a7a5ac..5618acc 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -13,10 +13,12 @@ import TAsset from './asset' import TCreateLinkResult from './create-link-result' import TLinkParsed from './parsed-link' import { TLinkStatusResult } from './link-status-result' +import TMode from './mode' export { ILinkdropSDK, TLinkStatusResult, + TMode, TLinkParsed, TLinkItem, TCampaignItem, diff --git a/src/types/mode/index.ts b/src/types/mode/index.ts new file mode 100644 index 0000000..6389e9a --- /dev/null +++ b/src/types/mode/index.ts @@ -0,0 +1,3 @@ +type TMode = 'testnets' | 'mainnets' + +export default TMode \ No newline at end of file