From 8da650b69caee2c3dddee0dcbb9543fe59ae768f Mon Sep 17 00:00:00 2001 From: jpbogle Date: Fri, 4 Feb 2022 16:31:01 -0800 Subject: [PATCH] Fix claim links regex --- package.json | 2 +- src/claimLinks.ts | 18 ++++++++++-------- src/programs/timeInvalidator/accounts.ts | 2 +- src/programs/tokenManager/accounts.ts | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index dcb9ea5ca..dbebdfd9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cardinal/token-manager", - "version": "0.0.6", + "version": "0.0.8", "description": "Cardinal token manager SDK", "keywords": [ "solana", diff --git a/src/claimLinks.ts b/src/claimLinks.ts index 61cadfc04..2c720fb3c 100644 --- a/src/claimLinks.ts +++ b/src/claimLinks.ts @@ -17,25 +17,27 @@ import { withFindOrInitAssociatedTokenAccount } from "./utils"; export const getLink = ( mintId: PublicKey, otp: Keypair, - baseUrl = "https://app.cardinal.so" + cluster = "mainnet", + baseUrl = "https://app.cardinal.so/claim" ): string => { return `${baseUrl}/${mintId.toString()}?otp=${utils.bytes.bs58.encode( otp.secretKey - )}`; + )}${cluster === "devnet" ? "&cluster=devnet" : ""}`; }; export const fromLink = ( link: string, - baseUrl = "https://app.cardinal.so" + baseUrl = "https://app.cardinal.so/claim" ): [PublicKey, Keypair] => { try { - const [_, mintId, otp] = + const regexMatches = // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - new RegExp(`${baseUrl}/(.*)\\?otp=(.*)`).exec(link)!; - console.log(mintId, otp); + new RegExp(`${baseUrl}/(.*)\\?otp=([^&]*)`).exec( + `${link}&cluster=devnet` + )!; return [ - new web3.PublicKey(mintId as string), - Keypair.fromSecretKey(utils.bytes.bs58.decode(otp as string)), + new web3.PublicKey(regexMatches[1] as string), + Keypair.fromSecretKey(utils.bytes.bs58.decode(regexMatches[2] as string)), ]; } catch (e) { console.log("Error decoding link: ", e, link); diff --git a/src/programs/timeInvalidator/accounts.ts b/src/programs/timeInvalidator/accounts.ts index 677d728ef..87c724195 100644 --- a/src/programs/timeInvalidator/accounts.ts +++ b/src/programs/timeInvalidator/accounts.ts @@ -9,7 +9,7 @@ import type { import { TIME_INVALIDATOR_ADDRESS, TIME_INVALIDATOR_IDL } from "./constants"; // TODO fix types -export const getUseInvalidator = async ( +export const getTimeInvalidator = async ( connection: Connection, timeInvalidatorId: PublicKey ): Promise> => { diff --git a/src/programs/tokenManager/accounts.ts b/src/programs/tokenManager/accounts.ts index 2da4c9d46..2021c0529 100644 --- a/src/programs/tokenManager/accounts.ts +++ b/src/programs/tokenManager/accounts.ts @@ -33,7 +33,7 @@ export const getTokenManager = async ( export const getTokenManagers = async ( connection: Connection, tokenManagerIds: PublicKey[] -): Promise> => { +): Promise[]> => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore const provider = new Provider(connection, null, {});