-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor CouponsContainer and UserProfileContainer components
- Loading branch information
Izabela
committed
Feb 18, 2024
1 parent
9efa473
commit 8bc5014
Showing
2 changed files
with
75 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,87 @@ | ||
import './CouponsContainer.css'; | ||
import React, { useEffect, useState } from 'react'; | ||
import "./CouponsContainer.css"; | ||
import React, { useEffect, useState } from "react"; | ||
import { | ||
IonButton, | ||
IonCard, | ||
IonCardContent, | ||
IonCardHeader, | ||
IonCardSubtitle, | ||
IonCardTitle, | ||
IonInput, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonThumbnail, | ||
} from '@ionic/react'; | ||
import { signCoupon } from '../helpers/signCoupon'; | ||
import { getData, setData } from '../data/helpers/localStorageService'; | ||
import { DataKey } from '../data/const/localStorageConst'; | ||
IonButton, | ||
IonCard, | ||
IonCardContent, | ||
IonCardHeader, | ||
IonCardSubtitle, | ||
IonCardTitle, | ||
IonInput, | ||
IonItem, | ||
IonLabel, | ||
IonList, | ||
IonThumbnail, | ||
} from "@ionic/react"; | ||
import { signCoupon } from "../helpers/signCoupon"; | ||
import { getData, setData } from "../data/helpers/localStorageService"; | ||
import { DataKey } from "../data/const/localStorageConst"; | ||
import { getShares } from "../services/loyaltyService"; | ||
|
||
interface UserProfileProps { | ||
|
||
} | ||
interface UserProfileProps {} | ||
|
||
const changeName = (newName: string | number | null | undefined) => { | ||
if (!!newName) { | ||
setData(DataKey.Name, `${newName}`); | ||
} | ||
} | ||
if (!!newName) { | ||
setData(DataKey.Name, `${newName}`); | ||
} | ||
}; | ||
|
||
const UserProfileContainer: React.FC<UserProfileProps> = () => { | ||
const [shares, setShares] = useState<any>(0); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
const [shares, setShares] = useState<number>(0); | ||
const [error, setError] = useState<string | null>(null); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
try { | ||
setShares(84); | ||
} catch (error) { | ||
console.error('Error fetching data:', error); | ||
setError('Error fetching data. Please try again.'); // You might want to handle the error more gracefully | ||
} | ||
}; | ||
useEffect(() => { | ||
const fetchData = async () => { | ||
console.log(shares); | ||
try { | ||
const data = await getShares(); // Call the getShares function | ||
setShares(data); // Assuming that the returned data has a 'shares' property | ||
console.log("Shares data:", data); | ||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
setError("Error fetching data. Please try again."); | ||
} | ||
}; | ||
|
||
fetchData(); | ||
}, []); | ||
fetchData(); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardSubtitle>My name:</IonCardSubtitle> | ||
<IonCardTitle> | ||
<IonInput clearOnEdit={true} value={getData(DataKey.Name)} onIonBlur={(e) => changeName(e.target.value)}></IonInput> | ||
</IonCardTitle> | ||
</IonCardHeader> | ||
</IonCard> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardSubtitle>My shares:</IonCardSubtitle> | ||
<IonCardTitle>{shares}</IonCardTitle> | ||
</IonCardHeader> | ||
</IonCard> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardTitle>0x932890843298943298</IonCardTitle> | ||
<IonInput label="Private key:" type='password' value='132123123132123123'></IonInput> | ||
</IonCardHeader> | ||
</IonCard> | ||
</> | ||
); | ||
return ( | ||
<> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardSubtitle>My name:</IonCardSubtitle> | ||
<IonCardTitle> | ||
<IonInput | ||
clearOnEdit={true} | ||
value={getData(DataKey.Name)} | ||
onIonBlur={(e) => changeName(e.target.value)} | ||
></IonInput> | ||
</IonCardTitle> | ||
</IonCardHeader> | ||
</IonCard> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardSubtitle>My shares:</IonCardSubtitle> | ||
<IonCardTitle> | ||
{shares.numberOfShares !== null | ||
? shares.numberOfShares | ||
: "Loading..."} | ||
</IonCardTitle> | ||
</IonCardHeader> | ||
</IonCard> | ||
<IonCard> | ||
<IonCardHeader> | ||
<IonCardTitle>0x932890843298943298</IonCardTitle> | ||
<IonInput | ||
label="Private key:" | ||
type="password" | ||
value="132123123132123123" | ||
></IonInput> | ||
</IonCardHeader> | ||
</IonCard> | ||
</> | ||
); | ||
}; | ||
|
||
export default UserProfileContainer; |