Skip to content

Commit

Permalink
attempting to fix unrelated issue with nullish operator
Browse files Browse the repository at this point in the history
  • Loading branch information
scermat committed Sep 13, 2024
1 parent fcb2f8e commit 7b85655
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions web-portal/frontend/components/swap/Redeem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ export default function Redeem() {
(c) => Number(c.id) === Number(selectedChainId),
);

const { writeContractAsync, isSuccess: isSubmitted } = useWriteContract();
const { writeContractAsync, isSuccess: isSubmitted } = useWriteContract();

const [hash, setHash] = useState();

const { data , isLoading} = useWaitForTransactionReceipt({hash})
const { data, isLoading } = useWaitForTransactionReceipt({ hash })

const setNotificationData = useSetAtom(notificationAtom)

Expand Down Expand Up @@ -86,51 +86,51 @@ export default function Redeem() {

const hexAccountId = accountId
? toHex(accountId, {
size: 32,
})
size: 32,
})
: zeroAddress;
const bigNumberRedeem = BigInt(
redeemValue * 10 ** portrTokenData?.decimals ?? 0,
redeemValue * 10 ** portrTokenData?.decimals,
);

const handleRedeem = async () => {
console.log("Attempting to redeem...");
const txHash = await writeContractAsync({
const txHash = await writeContractAsync({
abi,
chainId: selectedChainId,
address: portrTokenData?.address,
functionName: "applyToAccount",
args: [hexAccountId, bigNumberRedeem],
});
if(txHash){
setHash(txHash as any)
}
console.log("Redeem Attempt was made: hash" , {txHash} );
if (txHash) {
setHash(txHash as any)
}
console.log("Redeem Attempt was made: hash", { txHash });
};


useEffect(() => {
if(isSubmitted){
setNotificationData({
title: 'Your tx to top-up was submitted',
content: 'Please wait for it to be completed onchain!'
})
}


if(data?.status == 'success'){
setNotificationData({
title: 'Your tx was successful',
content: 'Please wait for UI to reflect changes. and update your balance!'
})
}

if(data?.status == 'reverted'){
setNotificationData({
title: 'Your tx was not successful',
content: 'Please check on block explorer or contact porters support!'
})
}
if (isSubmitted) {
setNotificationData({
title: 'Your tx to top-up was submitted',
content: 'Please wait for it to be completed onchain!'
})
}


if (data?.status == 'success') {
setNotificationData({
title: 'Your tx was successful',
content: 'Please wait for UI to reflect changes. and update your balance!'
})
}

if (data?.status == 'reverted') {
setNotificationData({
title: 'Your tx was not successful',
content: 'Please check on block explorer or contact porters support!'
})
}

}, [isSubmitted, data])

Expand Down Expand Up @@ -180,7 +180,7 @@ export default function Redeem() {
}}
error={
redeemValue >
Number(_.get(selectedTokenBalance, "formatted", 0))
Number(_.get(selectedTokenBalance, "formatted", 0))
? "Not enough balance"
: undefined
}
Expand All @@ -205,11 +205,11 @@ export default function Redeem() {
</Stack>
</Flex>
<Flex justify="space-between" dir="row" mx={10}>
<Text
size="sm"
style={{ fontWeight: 600 }}
c='blue'
>
<Text
size="sm"
style={{ fontWeight: 600 }}
c='blue'
>
Number of Relays ≈ {redeemValue * 1000}
</Text>
<Flex align={"center"} gap={4}>
Expand Down Expand Up @@ -274,21 +274,21 @@ export default function Redeem() {
>
<TextInput
label={
redeemValue ? "New Balance" : "Current Balance"}
redeemValue ? "New Balance" : "Current Balance"}
styles={{
...commonStyles,
input: { ...commonStyles.input, fill: "#fff" },
}}
value={
Number(balance/1000) + Number(redeemValue * 10 ** 3)}
Number(balance / 1000) + Number(redeemValue * 10 ** 3)}
readOnly
/>
</Flex>

<Button
size="lg"
style={{
backgroundColor: 'carrot'
backgroundColor: 'carrot'
}}
disabled={shouldDisable && !needToSwitchChain}
onClick={needToSwitchChain ? handleSwitchNetwork : handleRedeem}
Expand Down

0 comments on commit 7b85655

Please sign in to comment.