Skip to content

Commit

Permalink
fix: don't throw error if no custom key/values exist
Browse files Browse the repository at this point in the history
  • Loading branch information
im-adithya committed Mar 28, 2024
1 parent c157322 commit a0de979
Showing 1 changed file with 7 additions and 16 deletions.
23 changes: 7 additions & 16 deletions src/utils/keysend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,22 @@ const TAG_KEYSEND = "keysend";
export type KeySendRawData = {
tag: string;
status: string;
customData: { customKey: string; customValue: string }[];
customData?: { customKey?: string; customValue?: string }[];
pubkey: string;
};

export const parseKeysendResponse = (data: KeySendRawData): KeysendResponse => {
if (data.tag !== TAG_KEYSEND) throw new Error("Invalid keysend params");
if (data.status !== "OK") throw new Error("Keysend status not OK");

if (
!("customKey" in data.customData[0]) ||
data.customData[0]["customKey"] != "696969"
)
throw new Error("Unable to find customKey");

if (
!("customValue" in data.customData[0]) ||
!data.customData[0]["customValue"]
)
throw new Error("Unable to find customValue");

if (!data.pubkey) throw new Error("Pubkey does not exist");

const destination = data.pubkey;
const customKey = data.customData[0]["customKey"];
const customValue = data.customData[0]["customValue"];
let customKey, customValue;

if (data.customData && data.customData[0]) {
customKey = data.customData[0].customKey;
customValue = data.customData[0].customValue;
}

return {
destination,
Expand Down

0 comments on commit a0de979

Please sign in to comment.