ソースを参照

perf: 钱包充值金额改为接口取数据

kuns 1 ヶ月 前
コミット
a85a639c46

+ 13 - 12
component/accountPages/walletPageComponent.tsx

@@ -18,25 +18,28 @@ import {
 import { SafeAreaView } from 'react-native-safe-area-context';
 import { router } from 'expo-router';
 import { CrossLogoSvg } from '../global/SVG';
-import { useEffect, useRef, useState } from 'react';
+import { use, useEffect, useRef, useState } from 'react';
 import { walletService } from '../../service/walletService';
 import NormalButton from '../global/normal_button';
 import sha256 from 'crypto-js/sha256';
 import { useChargingStore } from '../../providers/scan_qr_payload_store';
+import { PaymentBonusList } from '../../service/type/walletServiceType';
 interface AmountInputModalProps {
     visible: boolean;
     onClose: () => void;
     onConfirm: (amount: number) => void;
 }
 const AmountInputModal = ({ visible, onClose, onConfirm }: AmountInputModalProps) => {
-    const amounts = [
-        // { amount: 1, percentage: 0 },
-        { amount: 200, percentage: 0 },
-        { amount: 500, percentage: 25 },
-        { amount: 1000, percentage: 100 },
-        { amount: 2000, percentage: 300 }
-    ];
-
+    const [amounts, setAmounts] = useState<Array<{amount: number, percentage: number}>>([]);
+    useEffect(() => {
+        const fetchData = async () => {
+            const res: PaymentBonusList[] = await walletService.getPaymentBonusList()
+            setAmounts(res.map(item => ({amount: item.base_amount, percentage: item.gift_amount})))
+        }
+        if (visible){
+            fetchData()
+        }
+    }, [visible])
     const getFontSize = () => {
         const { width } = Dimensions.get('window');
         if (width < 320) return 8;
@@ -137,7 +140,7 @@ export const IndividualCouponComponent = ({
                 onPress={setOpacity ? () => {} : () => onCouponClick(redeem_code as string, title)}
             >
                 {/* price column on the left */}
-                <View className="flex-row items-center w-[31%] items-center justify-center">
+                <View className="flex-row items-center w-[31%] justify-center">
                     <Text className="pl-1 lg:pl-2 text-[#02677D] text-base md:text-lg lg:text-xl">$</Text>
                     <Text className="text-3xl lg:text-4xl text-[#02677D] font-[600]">{price}</Text>
                 </View>
@@ -186,11 +189,9 @@ export const IndividualCouponComponent = ({
 const WalletPageComponent = () => {
     const [walletBalance, setWalletBalance] = useState<string | null>(null);
     const [loading, setLoading] = useState<boolean>(false);
-    const [modalVisible, setModalVisible] = useState(false);
     const [coupons, setCoupons] = useState([]);
     const [paymentType, setPaymentType] = useState({});
     const [userID, setUserID] = useState('');
-    const [selectedPaymentType, setSelectedPaymentType] = useState<string | null>(null);
     const [amount, setAmount] = useState<number>(0);
     const [amountModalVisible, setAmountModalVisible] = useState(false);
     const [outTradeNo, setOutTradeNo] = useState('');

+ 8 - 0
service/type/walletServiceType.ts

@@ -0,0 +1,8 @@
+export interface PaymentBonusList {
+     bonus_id: number;
+     base_amount: number;
+     gift_amount: number;
+     is_active: boolean;
+     createdAt: Date;
+     updatedAt: Date;
+};

+ 20 - 1
service/walletService.tsx

@@ -1,7 +1,7 @@
 import axios, { isAxiosError } from 'axios';
 import * as SecureStore from 'expo-secure-store';
 import {apiClient} from './requets'
-
+import {PaymentBonusList} from './type/walletServiceType';
 class WalletService {
     async getCouponForSpecificUser(userID: string) {
         try {
@@ -251,5 +251,24 @@ class WalletService {
             return false;
         }
     }
+    async getPaymentBonusList() {
+         try {
+            const response = await apiClient.instance.get(`/clients/promotion/paymentBonus`);
+            if (response.status === 200 || response.status === 201) {
+                const list = response.data;
+                return list as PaymentBonusList[];
+            } else {
+                console.error('get customer info failed:', response.status);
+                return [] as PaymentBonusList[];
+            }
+        } catch (error) {
+            if (isAxiosError(error)) {
+                console.error('get customer info error:', error.response?.data?.message || error.message);
+            } else {
+                console.error('An unexpected error occurred:', error);
+            }
+            return [] as PaymentBonusList[];;
+        }
+    }
 }
 export const walletService = new WalletService();