Skip to content

Commit

Permalink
Merge pull request #37 from LinkdropHQ/2.1.3_branch
Browse files Browse the repository at this point in the history
2.1.3 branch
  • Loading branch information
spacehaz authored Jun 10, 2024
2 parents 5d1662c + 2df82a4 commit 45d969b
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 14 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# 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)

## 2.1.1
- added testnets apiUrl

## 2.1.0
- added apiKey as param for LinkdropSDK

Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] */
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 [email protected] */
const sdk = new LinkdropSDK({ apiKey });
```

## Claim methods (Can be used on Front-end & Back-end)
Expand Down Expand Up @@ -248,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=<CODE>&c=<CHAIN_ID>&v=3')
```

As a result you will get claim links with actual claim code (`<CODE>`) and chain id (`<CHAIN_ID>`)



### Deactivating / reactivating links

#### Deactivate Link
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "linkdrop-sdk",
"version": "2.1.0",
"version": "2.1.3",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
Expand Down
5 changes: 4 additions & 1 deletion src/configs/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
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 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'
Expand Down
20 changes: 20 additions & 0 deletions src/helpers/define-claim-host-url.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { claimHostUrl, testnetsClaimHostUrl } from '../configs'
import { TMode } from '../types'

type TDefineClaimHostUrl = (
mode: TMode
) => string

const defineClaimHostUrl: TDefineClaimHostUrl = (
chainId
) => {
switch (chainId) {
case 'testnets':
return testnetsClaimHostUrl
case 'mainnets':
default:
return claimHostUrl
}
}

export default defineClaimHostUrl
2 changes: 2 additions & 0 deletions src/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 15 additions & 3 deletions src/modules/batch/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Batch implements IBatch {
campaignData: TCampaignItem
signerKey: string
apiKey: string
chainId: number

constructor (
batchId: string,
Expand All @@ -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
Expand All @@ -39,6 +41,7 @@ class Batch implements IBatch {
this.campaignData = campaignData
this.signerKey = signerKey
this.apiKey = apiKey
this.chainId = chainId
}

addLinks: TAddLinks = async (
Expand Down Expand Up @@ -77,17 +80,26 @@ 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}`
if (linkPattern) {
finalLink = linkPattern.replace('<CODE>', claimCode)
.replace('<CHAIN_ID>', String(this.chainId))
}
const sourceParam = finalLink.includes('?') ? `&src=d` : '?src=d'
return {
linkId: link.link_id,
claimCode,
claimLink: `${this.claimHostUrl}/#/redeem/${claimCode}?src=d`
claimLink: `${finalLink}${sourceParam}`
}
})
}
Expand Down
3 changes: 2 additions & 1 deletion src/modules/campaign/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ class Campaign implements ICampaign {
this.signerKey,
this.campaignSig,
this.apiHost,
this.apiKey
this.apiKey,
this.data.chain_id
)
}
}
Expand Down
25 changes: 20 additions & 5 deletions src/modules/linkdrop-sdk/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { ILinkdropSDK, TNetworkName } from '../../types'
import {
ILinkdropSDK,
TNetworkName,
TMode
} 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,
Expand All @@ -15,6 +25,8 @@ class LinkdropSDK implements ILinkdropSDK {
apiHost: string
claimHostUrl: string
apiKey: string
mode: TMode

utils = {
createLink,
computeProxyAddress,
Expand All @@ -29,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 {
Expand All @@ -41,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
}
}

Expand Down Expand Up @@ -78,7 +93,7 @@ class LinkdropSDK implements ILinkdropSDK {
signerKey,
encryptionKey,
campaign,
this.claimHostUrl,
this.claimHostUrl ? this.claimHostUrl : defineClaimHostUrl(this.mode),
campaignSig,
this.apiHost,
this.apiKey
Expand Down
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions src/types/mode/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type TMode = 'testnets' | 'mainnets'

export default TMode
4 changes: 3 additions & 1 deletion src/types/modules/batch/get-links/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { TLinkParsed } from '../../../'
type TGetLinks = () => TLinkParsed[]
type TGetLinks = (
linkPattern?: string
) => TLinkParsed[]

export default TGetLinks

0 comments on commit 45d969b

Please sign in to comment.