vipQrPageComponent.tsx 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { View, Text, ScrollView, Pressable, Image, useWindowDimensions, ActivityIndicator } from 'react-native';
  2. import React, { useContext, useEffect, useState } from 'react';
  3. import { SafeAreaView } from 'react-native-safe-area-context';
  4. import { router } from 'expo-router';
  5. import { CrossLogoSvg, RightArrowIconSvg } from '../global/SVG';
  6. import { walletService } from '../../service/walletService';
  7. import { useTranslation } from '../../util/hooks/useTranslation';
  8. const VipQrPageComponent = () => {
  9. const { t } = useTranslation(); // 使用翻译钩子
  10. const { width } = useWindowDimensions();
  11. const qrCodeSize = width * 0.8; // 80% of screen width
  12. const [loading, setLoading] = useState(true);
  13. const [transactions, setTransactions] = useState<any[]>([]);
  14. useEffect(() => {
  15. const fetchTransactionRecords = async () => {
  16. try {
  17. setLoading(true);
  18. const response = await walletService.getTransactionRecord();
  19. if (response && Array.isArray(response)) {
  20. setTransactions(response);
  21. } else {
  22. setTransactions([]);
  23. }
  24. } catch (error) {
  25. console.error(t('vipQr.error_fetching_transactions'), error);
  26. setTransactions([]);
  27. } finally {
  28. setLoading(false);
  29. }
  30. };
  31. fetchTransactionRecords();
  32. }, []);
  33. return (
  34. <SafeAreaView className="flex-1 bg-white" edges={['top', 'right', 'left']}>
  35. <ScrollView className="flex-1 mx-[5%]" showsVerticalScrollIndicator={false}>
  36. <View style={{ marginTop: 25 }}>
  37. <Pressable
  38. onPress={() => {
  39. router.replace('/mainPage');
  40. }}
  41. >
  42. <CrossLogoSvg />
  43. </Pressable>
  44. <Text style={{ fontSize: 45, marginVertical: 25 }}>{t('vipQr.title')}</Text>
  45. </View>
  46. {loading ? (
  47. <View className="items-center justify-center mt-10">
  48. <ActivityIndicator size="large" color="#02677D" />
  49. <Text className="text-center mt-4">{t('vipQr.loading')}</Text>
  50. </View>
  51. ) : transactions.length > 0 ? (
  52. <View className="items-center">
  53. <Text className="text-lg self-start mb-4">{t('vipQr.scan_instructions')}</Text>
  54. <Image
  55. source={require('../../assets/vipqrcode.png')}
  56. className=""
  57. style={{ width: qrCodeSize, height: qrCodeSize }}
  58. />
  59. </View>
  60. ) : (
  61. <View className="items-center mt-10">
  62. <Text className="text-xl text-center">{t('vipQr.no_transactions_message')}</Text>
  63. </View>
  64. )}
  65. </ScrollView>
  66. </SafeAreaView>
  67. );
  68. };
  69. export default VipQrPageComponent;