Skip to content

Commit 44f90f4

Browse files
authored
Merge pull request #73 from input-output-hk/PLT-5543
PLT-5543 Show Amount to be paid with label change in Get Certificate btn
2 parents 0f8518c + b0fe6c1 commit 44f90f4

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

react-web/src/components/CreateCertificate/CreateCertificate.tsx

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState } from "react";
1+
import { useEffect, useState } from "react";
22
import { useAppSelector } from "store/store";
33

44
import Button from "components/Button/Button";
@@ -49,7 +49,22 @@ const CreateCertificate = () => {
4949
const [ showError, setShowError ] = useState("");
5050
const [ openModal, setOpenModal ] = useState(false);
5151
const [ disableCertify, setDisableCertify ] = useState(false);
52+
const [certificationPrice, setCertificationPrice] = useState(0);
53+
const [performTransaction, setPerformTransaction] = useState(true);
5254

55+
// to run only once initially
56+
useEffect(() => {
57+
fetchData.get('/profile/current/balance').then(response => {
58+
const availableProfileBalance: number = response.data
59+
fetchData.get('/run/' + uuid + '/details').then(res => {
60+
const runDetails: Run = res.data
61+
setCertificationPrice(runDetails.certificationPrice);
62+
setPerformTransaction((availableProfileBalance > 0 && (availableProfileBalance - runDetails.certificationPrice) < 0) ? true : false)
63+
})
64+
})
65+
// eslint-disable-next-line react-hooks/exhaustive-deps
66+
}, [])
67+
5368
const onCloseModal = () => { setOpenModal(false) }
5469

5570
const convertAdaToLovelace = (fee_ada: number) => {
@@ -112,17 +127,11 @@ const CreateCertificate = () => {
112127
const triggerGetCertificate = async () => {
113128
setCertifying(true);
114129
setShowError("")
115-
fetchData.get('/profile/current/balance').then(response => {
116-
const availableProfileBalance: number = response.data
117-
fetchData.get('/run/' + uuid + '/details').then(res => {
118-
const runDetails: Run = res.data
119-
if ((availableProfileBalance - runDetails.certificationPrice) < 0) {
120-
triggerTransactionFromWallet(runDetails.certificationPrice)
121-
} else {
122-
triggerSubmitCertificate()
123-
}
124-
})
125-
})
130+
if (performTransaction) {
131+
triggerTransactionFromWallet(certificationPrice)
132+
} else {
133+
triggerSubmitCertificate()
134+
}
126135
}
127136

128137
const triggerTransactionFromWallet = async (cert_fee_in_lovelaces: number) => {
@@ -197,7 +206,7 @@ const CreateCertificate = () => {
197206
{certified || disableCertify ? null : (<Button
198207
displayStyle="gradient"
199208
onClick={() => triggerGetCertificate()}
200-
buttonLabel="Get Certificate"
209+
buttonLabel={"Purchase a Certificate"+ (certificationPrice ? " (" + (certificationPrice/1000000).toString() + " ADA)" : "")}
201210
showLoader={certifying}
202211
/>)}
203212
{transactionId ? (

0 commit comments

Comments
 (0)