diff --git a/.env.development b/.env.development index a9ee309..608d56f 100644 --- a/.env.development +++ b/.env.development @@ -1,8 +1,8 @@ REACT_APP_BASE_URL=http://localhost:9002 -# REACT_APP_BASE_URL=https://11561ba2d27f.ngrok.app +REACT_APP_WALLET_BASE_URL=http://localhost:9003 # New wallet base URL REACT_APP_ASSETS_BUCKET=http://localhost -REACT_APP_DEMO_MODE=true +REACT_APP_DEMO_MODE=false -# more info https://create-react-app.dev/docs/advanced-configuration +# More info https://create-react-app.dev/docs/advanced-configuration ESLINT_NO_DEV_ERRORS=true TSC_COMPILE_ON_ERROR=true diff --git a/src/api/activity.api.ts b/src/api/activity.api.ts index 5a7aa3c..11e9dcb 100644 --- a/src/api/activity.api.ts +++ b/src/api/activity.api.ts @@ -1,7 +1,9 @@ // eslint-disable-next-line @typescript-eslint/no-unused-vars import { ActivityStatusType } from '@app/interfaces/interfaces'; +import { readToken } from '@app/services/localStorage.service'; import config from '@app/config/config'; +import { message } from 'antd'; export interface WalletTransaction { id: number; @@ -11,33 +13,46 @@ export interface WalletTransaction { value: string; } -export const getUserActivities = (): Promise => { - return fetch(`${config.baseURL}/transactions/latest`) - .then((response) => { - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }) - .then((data) => { - if (Array.isArray(data) && data.length === 0) { - // Handle the case where the response is an empty array - return []; - } - // Assuming your backend response matches the WalletTransaction interface - // eslint-disable-next-line - return data.map((item: any) => ({ - id: item.ID, - witness_tx_id: item.WitnessTxId, - date: new Date(item.Date).getTime(), - output: item.Output, - value: item.Value, - })); - }) - .catch((error) => { - console.error('Error fetching user activities:', error); +export const getUserActivities = (handleLogout: () => void): Promise => { + const token = readToken(); // Read the JWT token from local storage + + if (!token) { + handleLogout(); // Call handleLogout if no token + return Promise.reject('No token found'); + } + + return fetch(`${config.baseURL}/api/transactions/latest`, { + method: 'GET', + headers: { + 'Authorization': `Bearer ${token}`, + 'Content-Type': 'application/json', + }, + }) + .then((response) => { + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }) + .then((data) => { + if (Array.isArray(data) && data.length === 0) { + // Handle the case where the response is an empty array return []; - }); + } + // Assuming your backend response matches the WalletTransaction interface + // eslint-disable-next-line + return data.map((item: any) => ({ + id: item.ID, + witness_tx_id: item.WitnessTxId, + date: new Date(item.Date).getTime(), + output: item.Output, + value: item.Value, + })); + }) + .catch((error) => { + console.error('Error fetching user activities:', error); + return []; + }); }; export interface Activity { diff --git a/src/api/earnings.api.ts b/src/api/earnings.api.ts index 91ea08a..e3a27d4 100644 --- a/src/api/earnings.api.ts +++ b/src/api/earnings.api.ts @@ -75,7 +75,7 @@ export const getTotalEarning = (id: number, currency: CurrencyTypeEnum): Promise export const getBitcoinRatesForLast30Days = (): Promise => { console.log('Fetching bitcoin rate data.'); - return fetch('http://localhost:5000/bitcoin-rates/last-30-days') + return fetch('http://localhost:5000/api/bitcoin-rates/last-30-days') .then((response) => response.json()) .then((data) => { console.log('Received data:', data); // Add log statement to see the data diff --git a/src/components/auth/LoginForm/LoginForm.tsx b/src/components/auth/LoginForm/LoginForm.tsx index 74eecfa..be4949d 100644 --- a/src/components/auth/LoginForm/LoginForm.tsx +++ b/src/components/auth/LoginForm/LoginForm.tsx @@ -45,7 +45,6 @@ export const LoginForm: React.FC = () => { const dispatch = useDispatch(); const [form] = Form.useForm(); - const [event, setEvent] = useState(null); useEffect(() => { const fetchPublicKey = async () => { @@ -60,37 +59,44 @@ export const LoginForm: React.FC = () => { console.error('Failed to get public key:', error); } }; - - fetchPublicKey(); - - const isFirstLoad = localStorage.getItem('isFirstLoad'); - if (!isFirstLoad) { - window.location.reload(); - localStorage.setItem('isFirstLoad', 'true'); - } + + const intervalId = setInterval(() => { + if (window.nostr) { + fetchPublicKey(); + clearInterval(intervalId); + } + }, 1000); // Retry every 1 second + + return () => clearInterval(intervalId); // Clear the interval on component unmount }, [form]); + + + const [event, setEvent] = useState(null); const handleSubmit = async (values: LoginFormData) => { try { + if (!window.nostr) { + notificationController.error({ message: 'Nostr extension is not available' }); + return; + } + const { success, event } = await login(values); if (success && event) { setEvent(event); - // Automatically proceed to verification const signedEvent = await window.nostr.signEvent(event); console.log('Signed event:', signedEvent); - + const response = await verifyChallenge({ challenge: signedEvent.content, signature: signedEvent.sig, messageHash: signedEvent.id, event: signedEvent, }); - + if (response.success) { if (response.token && response.user) { persistToken(response.token); dispatch(setUser(response.user)); - // Set the token in the API instance notificationController.success({ message: 'Login successful', description: 'You have successfully logged in!', @@ -105,6 +111,7 @@ export const LoginForm: React.FC = () => { notificationController.error({ message: error.message }); } }; + return ( diff --git a/src/components/common/CopyToClipboard/CopyToClipboard.tsx b/src/components/common/CopyToClipboard/CopyToClipboard.tsx new file mode 100644 index 0000000..c7fb76c --- /dev/null +++ b/src/components/common/CopyToClipboard/CopyToClipboard.tsx @@ -0,0 +1,24 @@ +import React, { useState } from 'react'; +import { CopyOutlined } from '@ant-design/icons'; +import CopyToClipboard from 'react-copy-to-clipboard'; +import { Button, message } from 'antd'; +interface CopyToClipboardProps { + textToCopy: string; +} + +const ClipboardCopy: React.FC = ({ textToCopy }) => { + const copied = () => { + message.success('Copied to clipboard'); + }; + const onCopy = () => { + //display Copied to clipboard + copied(); + }; + return ( + +