From e6ebc53fc2dbce1c55ecadcebbe38223fbdcae47 Mon Sep 17 00:00:00 2001 From: ValantineSuh Date: Wed, 27 Mar 2024 12:35:46 +0100 Subject: [PATCH] feat: Implemented the send money fake API --- power-pay-frontend/src/components/okpage.tsx | 38 ++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/power-pay-frontend/src/components/okpage.tsx b/power-pay-frontend/src/components/okpage.tsx index 594033ba..3c3fb8d3 100644 --- a/power-pay-frontend/src/components/okpage.tsx +++ b/power-pay-frontend/src/components/okpage.tsx @@ -1,4 +1,42 @@ +//faking the API +import React, { useEffect, useState } from 'react'; +import axios from 'axios'; +const OKpage: React.FC = () => { + const baseURL = 'http://localhost:5000'; // specifying the base URL with the desired port + const api = axios.create({ + baseURL, + timeout: 5000, + }); + + // Mock function to simulate a succesful API call + const mockSend_MoneyAPI = async ( + senderPhoneNumber: string, + recipientPhoneNumber: string, + amount: number + ) => { + try { + const response = await api.post('/send_money', { + senderPhoneNumber, + recipientPhoneNumber, + amount }); + return response.data; + } catch (error) { + throw error; + } + } + + // Handle API call when component mounts + useEffect(() => { + mockSend_MoneyAPI('12347656', '1234567890', 100) + .then((response) => { + console.log("Mock API Response", response); + }) + .catch((error) => { + console.error("Mock API Error", error); + }); + }, []); +} //building the ok page for successful transfer const OKPage = () => {