Skip to content

Commit

Permalink
Fix claim links regex
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbogle committed Feb 5, 2022
1 parent 29ce12d commit 8da650b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cardinal/token-manager",
"version": "0.0.6",
"version": "0.0.8",
"description": "Cardinal token manager SDK",
"keywords": [
"solana",
Expand Down
18 changes: 10 additions & 8 deletions src/claimLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/programs/timeInvalidator/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<AccountData<TimeInvalidatorData>> => {
Expand Down
2 changes: 1 addition & 1 deletion src/programs/tokenManager/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const getTokenManager = async (
export const getTokenManagers = async (
connection: Connection,
tokenManagerIds: PublicKey[]
): Promise<AccountData<TokenManagerData[]>> => {
): Promise<AccountData<TokenManagerData>[]> => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const provider = new Provider(connection, null, {});
Expand Down

0 comments on commit 8da650b

Please sign in to comment.