-
Notifications
You must be signed in to change notification settings - Fork 347
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use unified memo field and extract memo value from different coi…
…n transaction implementation/labels (#8392)
- Loading branch information
1 parent
be83cab
commit 72245a5
Showing
13 changed files
with
161 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ledger-live-desktop": minor | ||
--- | ||
|
||
use common MemoTagField for sol/xrp and extract memo related value from transaction coin/by/coin |
47 changes: 47 additions & 0 deletions
47
apps/ledger-live-desktop/src/newArch/features/MemoTag/__tests__/utils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { getMemoTagValueByTransactionFamily } from "../utils"; | ||
import { Transaction } from "@ledgerhq/live-common/generated/types"; | ||
import { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; | ||
import { Transaction as SolanaTransaction } from "@ledgerhq/live-common/families/solana/types"; | ||
|
||
describe("getMemoTagValueByTransactionFamily", () => { | ||
it("should return empty string if transaction family is not recognized", () => { | ||
const transaction: Transaction = { family: "unknown" } as Transaction; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBeUndefined(); | ||
}); | ||
|
||
it("should return tag for xrp family", () => { | ||
const transaction: Transaction = { family: "xrp", tag: 12345 } as Transaction; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBe(12345); | ||
}); | ||
|
||
it("should return comment text for ton family", () => { | ||
const transaction: Transaction = { | ||
family: "ton", | ||
comment: { text: "Test comment" }, | ||
} as Transaction; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBe("Test comment"); | ||
}); | ||
|
||
it("should return memoValue for stellar family", () => { | ||
const transaction: StellarTransaction = { | ||
family: "stellar", | ||
memoValue: "Stellar memo", | ||
} as StellarTransaction; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBe("Stellar memo"); | ||
}); | ||
|
||
it("should return memo for solana family", () => { | ||
const transaction: SolanaTransaction = { | ||
family: "solana", | ||
model: { uiState: { memo: "Solana memo" } }, | ||
} as SolanaTransaction; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBe("Solana memo"); | ||
}); | ||
|
||
it("should return memo for default case", () => { | ||
const transaction: Transaction = { family: "cosmos", memo: "Default memo" } as Transaction & { | ||
memo: string; | ||
}; | ||
expect(getMemoTagValueByTransactionFamily(transaction)).toBe("Default memo"); | ||
}); | ||
}); |
17 changes: 8 additions & 9 deletions
17
apps/ledger-live-desktop/src/newArch/features/MemoTag/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
export const MEMO_TAG_COINS: string[] = [ | ||
"ripple", | ||
"stellar", | ||
"algorand", | ||
"cardano", | ||
"casper", | ||
"cosmos", | ||
"hedera", | ||
"injective", | ||
"crypto_org", | ||
"crypto_org_croeseid", | ||
"hedera", | ||
"internet_computer", | ||
"solana", | ||
"stacks", | ||
"stellar", | ||
"ton", | ||
"eos", | ||
"bsc", | ||
"casper", | ||
"cardano", | ||
"xrp", | ||
]; |
33 changes: 33 additions & 0 deletions
33
apps/ledger-live-desktop/src/newArch/features/MemoTag/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Transaction } from "@ledgerhq/live-common/generated/types"; | ||
import { Transaction as StellarTransaction } from "@ledgerhq/live-common/families/stellar/types"; | ||
import { Transaction as SolanaTransaction } from "@ledgerhq/live-common/families/solana/types"; | ||
import { MEMO_TAG_COINS } from "./constants"; | ||
|
||
/** | ||
* Retrieves the memo tag value from a transaction based on its family type. | ||
* | ||
* @param {Transaction} transaction - The transaction object from which to extract the memo tag value. | ||
* @returns {string | undefined} The memo tag value if the transaction family is supported, otherwise undefined. | ||
*/ | ||
export const getMemoTagValueByTransactionFamily = (transaction: Transaction) => { | ||
if (!MEMO_TAG_COINS.includes(transaction?.family as string)) return undefined; | ||
const { family } = transaction; | ||
switch (family) { | ||
case "xrp": | ||
return transaction?.tag; | ||
case "ton": | ||
return transaction?.comment?.text; | ||
case "stellar": | ||
return (transaction as StellarTransaction)?.memoValue; | ||
case "solana": | ||
return ( | ||
transaction as SolanaTransaction & { | ||
model: { | ||
uiState: { memo: string }; | ||
}; | ||
} | ||
)?.model.uiState.memo; | ||
default: | ||
return (transaction as Transaction & { memo: string })?.memo; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters