Skip to content

Commit 8e3715b

Browse files
committed
fix(transaction-detail): show Spark label for self-custodial Spark transactions
1 parent e1432fc commit 8e3715b

2 files changed

Lines changed: 51 additions & 3 deletions

File tree

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { typeDisplay } from "@app/screens/transaction-detail-screen/transaction-detail-screen"
2+
import { PaymentType } from "@app/types/transaction.types"
3+
4+
const settlement = <T extends string>(typename: T) => ({ __typename: typename }) as never
5+
6+
describe("typeDisplay", () => {
7+
it("returns 'Spark' when the self-custodial paymentType is Spark, even if settlementVia is Lightning", () => {
8+
expect(typeDisplay(settlement("SettlementViaLn"), PaymentType.Spark)).toBe("Spark")
9+
})
10+
11+
it("falls back to the settlementVia typename when no self-custodial paymentType is given", () => {
12+
expect(typeDisplay(settlement("SettlementViaOnChain"))).toBe("OnChain")
13+
expect(typeDisplay(settlement("SettlementViaLn"))).toBe("Lightning")
14+
expect(typeDisplay(settlement("SettlementViaIntraLedger"))).toBe("IntraLedger")
15+
})
16+
17+
it("keeps the settlementVia mapping for non-Spark self-custodial paymentTypes (Lightning, Onchain)", () => {
18+
expect(typeDisplay(settlement("SettlementViaLn"), PaymentType.Lightning)).toBe(
19+
"Lightning",
20+
)
21+
expect(typeDisplay(settlement("SettlementViaOnChain"), PaymentType.Onchain)).toBe(
22+
"OnChain",
23+
)
24+
})
25+
26+
it("returns 'Unknown' for missing or malformed settlementVia with no Spark hint", () => {
27+
expect(typeDisplay(undefined)).toBe("Unknown")
28+
expect(typeDisplay({} as never)).toBe("Unknown")
29+
})
30+
})

app/screens/transaction-detail-screen/transaction-detail-screen.tsx

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { useAppConfig, useClipboard, useTransactionSeenState } from "@app/hooks"
2323
import { useDisplayCurrency } from "@app/hooks/use-display-currency"
2424
import { useI18nContext } from "@app/i18n/i18n-react"
2525
import { toWalletAmount } from "@app/types/amounts"
26+
import { PaymentType } from "@app/types/transaction.types"
2627
import { RouteProp, useNavigation } from "@react-navigation/native"
2728
import { StackNavigationProp } from "@react-navigation/stack"
2829
import { makeStyles, Text, useTheme } from "@rn-vui/themed"
@@ -72,7 +73,12 @@ const Row = ({
7273
)
7374
}
7475

75-
const typeDisplay = (instance?: SettlementVia | DeepPartialObject<SettlementVia>) => {
76+
export const typeDisplay = (
77+
instance?: SettlementVia | DeepPartialObject<SettlementVia>,
78+
selfCustodialPaymentType?: PaymentType,
79+
) => {
80+
if (selfCustodialPaymentType === PaymentType.Spark) return "Spark"
81+
7682
if (!instance || !instance.__typename) {
7783
return "Unknown"
7884
}
@@ -130,10 +136,19 @@ export const TransactionDetailScreen: React.FC<Props> = ({ route }) => {
130136
const [timer, setTimer] = React.useState<number>(0)
131137

132138
const { LL, locale } = useI18nContext()
133-
const { isSelfCustodial } = useActiveWallet()
139+
const { isSelfCustodial, wallets } = useActiveWallet()
134140
const { copyToClipboard } = useClipboard()
135141
const { formatCurrency } = useDisplayCurrency()
136142

143+
const selfCustodialPaymentType = React.useMemo(() => {
144+
if (!isSelfCustodial) return undefined
145+
for (const wallet of wallets) {
146+
const match = wallet.transactions.find((t) => t.id === txid)
147+
if (match) return match.paymentType
148+
}
149+
return undefined
150+
}, [isSelfCustodial, wallets, txid])
151+
137152
const description = useDescriptionDisplay({
138153
tx,
139154
bankName: galoyInstance.name,
@@ -429,7 +444,10 @@ export const TransactionDetailScreen: React.FC<Props> = ({ route }) => {
429444
value={settlementVia.counterPartyUsername || galoyInstance.name}
430445
/>
431446
)}
432-
<Row entry={LL.common.type()} value={typeDisplay(settlementVia)} />
447+
<Row
448+
entry={LL.common.type()}
449+
value={typeDisplay(settlementVia, selfCustodialPaymentType)}
450+
/>
433451
{initiationVia?.__typename === "InitiationViaLn" &&
434452
initiationVia?.paymentHash && (
435453
<Row

0 commit comments

Comments
 (0)