2024-02-24 06:27:17 -05:00
|
|
|
import { NativeStackScreenProps } from '@react-navigation/native-stack';
|
2023-03-15 20:42:25 +00:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
|
|
|
import { SectionList, StyleSheet, Text, View } from 'react-native';
|
2024-02-24 06:27:17 -05:00
|
|
|
import { PaymentCodeStackParamList } from '../../Navigation';
|
2023-03-15 20:42:25 +00:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
|
|
|
import loc from '../../loc';
|
2024-03-27 00:37:43 -04:00
|
|
|
import CopyTextToClipboard from '../../components/CopyTextToClipboard';
|
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'>;
|
|
|
|
|
|
|
|
export default function PaymentCodesList({ route }: Props) {
|
2023-03-15 20:42:25 +00:00
|
|
|
const { walletID } = route.params;
|
|
|
|
const { wallets } = useContext(BlueStorageContext);
|
|
|
|
const [data, setData] = useState<DataSection[]>([]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (!walletID) return;
|
|
|
|
|
2024-03-15 23:05:15 +03:00
|
|
|
const foundWallet = wallets.find(w => w.getID() === walletID);
|
2023-03-15 20:42:25 +00:00
|
|
|
if (!foundWallet) return;
|
|
|
|
|
|
|
|
const newData: DataSection[] = [
|
|
|
|
{
|
|
|
|
title: loc.bip47.who_can_pay_me,
|
2024-03-15 23:05:15 +03:00
|
|
|
// @ts-ignore remove later
|
2023-03-15 20:42:25 +00:00
|
|
|
data: foundWallet.getBIP47SenderPaymentCodes(),
|
|
|
|
},
|
|
|
|
];
|
|
|
|
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>
|
2024-03-27 00:37:43 -04:00
|
|
|
<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 },
|
|
|
|
});
|