BlueWallet/screen/wallets/paymentCodesList.tsx

73 lines
2.2 KiB
TypeScript
Raw Normal View History

2023-03-15 20:42:25 +00:00
import React, { useContext, useEffect, useState } from 'react';
import { SectionList, StyleSheet, Text, View } from 'react-native';
2024-05-11 12:50:06 -04:00
import { useRoute } from '@react-navigation/native';
import { NativeStackScreenProps } from '@react-navigation/native-stack';
2023-03-15 20:42:25 +00:00
import { BlueStorageContext } from '../../blue_modules/storage-context';
import loc from '../../loc';
import CopyTextToClipboard from '../../components/CopyTextToClipboard';
2024-04-29 23:43:04 +01:00
import { AbstractHDElectrumWallet } from '../../class/wallets/abstract-hd-electrum-wallet';
2024-05-11 12:50:06 -04:00
import { PaymentCodeStackParamList } from '../../navigation/PaymentCodeStack';
2023-03-15 20:42:25 +00:00
interface DataSection {
title: string;
data: string[];
}
2024-02-24 06:27:17 -05:00
type Props = NativeStackScreenProps<PaymentCodeStackParamList, 'PaymentCodesList'>;
2024-05-11 12:50:06 -04:00
export default function PaymentCodesList() {
const route = useRoute();
const { walletID } = route.params as Props['route']['params'];
2023-03-15 20:42:25 +00:00
const { wallets } = useContext(BlueStorageContext);
const [data, setData] = useState<DataSection[]>([]);
useEffect(() => {
if (!walletID) return;
2024-04-29 23:43:04 +01:00
const foundWallet = wallets.find(w => w.getID() === walletID) as unknown as AbstractHDElectrumWallet;
2023-03-15 20:42:25 +00:00
if (!foundWallet) return;
const newData: DataSection[] = [
{
title: loc.bip47.who_can_pay_me,
data: foundWallet.getBIP47SenderPaymentCodes(),
},
2024-04-29 23:43:04 +01:00
{
title: loc.bip47.whom_can_i_pay,
data: foundWallet.getBIP47ReceiverPaymentCodes(),
},
2023-03-15 20:42:25 +00:00
];
setData(newData);
}, [walletID, wallets]);
return (
<View style={styles.container}>
{!walletID ? (
<Text>Internal error</Text>
) : (
<View>
<SectionList
sections={data}
keyExtractor={(item, index) => item + index}
renderItem={({ item }) => (
<View>
<CopyTextToClipboard truncated text={item} />
2023-03-15 20:42:25 +00:00
</View>
)}
renderSectionHeader={({ section: { title } }) => <Text style={styles.titleText}>{title}</Text>}
/>
</View>
)}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
titleText: { fontSize: 20 },
});