From 805b9a4ac1c75a81eb5ccdaaf873d0403e49b2bc Mon Sep 17 00:00:00 2001
From: guibescos <59208140+guibescos@users.noreply.github.com>
Date: Tue, 7 Jun 2022 17:55:51 -0500
Subject: [PATCH] Use new PythBalance functions (#188)
---
frontend/pages/staking.tsx | 68 +++++++++++++++++++-------------------
1 file changed, 34 insertions(+), 34 deletions(-)
diff --git a/frontend/pages/staking.tsx b/frontend/pages/staking.tsx
index b2c1ff63..f1aa0c44 100644
--- a/frontend/pages/staking.tsx
+++ b/frontend/pages/staking.tsx
@@ -68,33 +68,33 @@ const Staking: NextPage = () => {
const [mainStakeAccount, setMainStakeAccount] = useState()
const [balance, setBalance] = useState()
const [pythBalance, setPythBalance] = useState(
- new PythBalance(new BN(0))
+ PythBalance.zero()
)
const [lockedPythBalance, setLockedPythBalance] = useState(
- new PythBalance(new BN(0))
+ PythBalance.zero()
)
const [unlockedPythBalance, setUnlockedPythBalance] = useState(
- new PythBalance(new BN(0))
+ PythBalance.zero()
)
const [unvestedTotalPythBalance, setUnvestedTotalPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [unvestedLockingPythBalance, setUnvestedLockingPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [unvestedLockedPythBalance, setUnvestedLockedPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [unvestedPreUnlockingPythBalance, setUnvestedPreUnlockingPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [unvestedUnlockingPythBalance, setUnvestedUnlockingPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [unvestedUnlockedPythBalance, setUnvestedUnlockedPythBalance] =
- useState(new PythBalance(new BN(0)))
+ useState(PythBalance.zero())
const [lockingPythBalance, setLockingPythBalance] = useState()
const [unlockingPythBalance, setUnlockingPythBalance] =
useState()
const [amount, setAmount] = useState('')
const [currentTab, setCurrentTab] = useState(TabEnum.Lock)
const [nextVestingAmount, setNextVestingAmount] = useState(
- new PythBalance(new BN(0))
+ PythBalance.zero()
)
const [nextVestingDate, setNextVestingDate] = useState()
const [currentVestingAccountState, setCurrentVestingAccountState] =
@@ -196,18 +196,18 @@ const Staking: NextPage = () => {
])
const resetBalance = () => {
- setPythBalance(new PythBalance(new BN(0)))
- setLockingPythBalance(new PythBalance(new BN(0)))
- setLockedPythBalance(new PythBalance(new BN(0)))
- setUnlockingPythBalance(new PythBalance(new BN(0)))
- setUnvestedTotalPythBalance(new PythBalance(new BN(0)))
- setUnvestedLockingPythBalance(new PythBalance(new BN(0)))
- setUnvestedLockedPythBalance(new PythBalance(new BN(0)))
- setUnvestedPreUnlockingPythBalance(new PythBalance(new BN(0)))
- setUnvestedUnlockingPythBalance(new PythBalance(new BN(0)))
- setUnvestedUnlockedPythBalance(new PythBalance(new BN(0)))
- setUnlockedPythBalance(new PythBalance(new BN(0)))
- setNextVestingAmount(new PythBalance(new BN(0)))
+ setPythBalance(PythBalance.zero())
+ setLockingPythBalance(PythBalance.zero())
+ setLockedPythBalance(PythBalance.zero())
+ setUnlockingPythBalance(PythBalance.zero())
+ setUnvestedTotalPythBalance(PythBalance.zero())
+ setUnvestedLockingPythBalance(PythBalance.zero())
+ setUnvestedLockedPythBalance(PythBalance.zero())
+ setUnvestedPreUnlockingPythBalance(PythBalance.zero())
+ setUnvestedUnlockingPythBalance(PythBalance.zero())
+ setUnvestedUnlockedPythBalance(PythBalance.zero())
+ setUnlockedPythBalance(PythBalance.zero())
+ setNextVestingAmount(PythBalance.zero())
}
const refreshVestingAccountState = async () => {
@@ -235,7 +235,7 @@ const Staking: NextPage = () => {
return
}
const depositAmount = PythBalance.fromString(amount)
- if (depositAmount.toBN().gt(new BN(0))) {
+ if (depositAmount.gt(PythBalance.zero())) {
try {
await stakeConnection?.depositAndLockTokens(
mainStakeAccount,
@@ -262,7 +262,7 @@ const Staking: NextPage = () => {
return
}
const unlockAmount = PythBalance.fromString(amount)
- if (unlockAmount.toBN().gt(new BN(0))) {
+ if (unlockAmount.gt(PythBalance.zero())) {
if (mainStakeAccount) {
try {
await stakeConnection?.unlockTokens(mainStakeAccount, unlockAmount)
@@ -291,7 +291,7 @@ const Staking: NextPage = () => {
return
}
const withdrawAmount = PythBalance.fromString(amount)
- if (withdrawAmount.toBN().gt(new BN(0))) {
+ if (withdrawAmount.gt(PythBalance.zero())) {
if (mainStakeAccount) {
try {
await stakeConnection?.withdrawTokens(
@@ -322,7 +322,7 @@ const Staking: NextPage = () => {
setLockingPythBalance(locked.locking)
setLockedPythBalance(locked.locked)
setUnlockingPythBalance(
- new PythBalance(locked.unlocking.toBN().add(locked.preunlocking.toBN()))
+ locked.unlocking.add(locked.preunlocking)
)
setUnvestedTotalPythBalance(unvested.total)
setUnvestedLockingPythBalance(unvested.locking)
@@ -413,9 +413,9 @@ const Staking: NextPage = () => {
try {
await stakeConnection.unlockBeforeVestingEvent(mainStakeAccount)
toast.success(
- `${new PythBalance(
- nextVestingAmount.toBN().add(lockedPythBalance.toBN())
- ).toString()} tokens have started unlocking. You will be able to withdraw them after ${nextVestingDate?.toLocaleString()}`
+ `${
+ nextVestingAmount.add(lockedPythBalance)
+ .toString()} tokens have started unlocking. You will be able to withdraw them after ${nextVestingDate?.toLocaleString()}`
)
} catch (e) {
toast.error(capitalizeFirstLetter(e.message))
@@ -777,7 +777,7 @@ const Staking: NextPage = () => {
tokens.
{lockingPythBalance &&
- lockingPythBalance.toString() !== '0' ? (
+ !lockingPythBalance.isZero()? (
{lockingPythBalance.toString()} tokens will be locked
from the beginning of the next epoch.
@@ -845,7 +845,7 @@ const Staking: NextPage = () => {
unlocked tokens.
{unlockingPythBalance &&
- unlockingPythBalance.toString() !== '0' ? (
+ !unlockingPythBalance.isZero() ? (
{unlockingPythBalance.toString()} tokens have to go
through a cool-down period for 2 epochs before they can
@@ -906,7 +906,7 @@ const Staking: NextPage = () => {
You currently have {unvestedTotalPythBalance?.toString()}{' '}
unvested tokens.{' '}
- {unvestedTotalPythBalance.toString() !== '0'
+ {!unvestedTotalPythBalance.isZero()
? `${nextVestingAmount.toString()} tokens
will vest on ${nextVestingDate?.toLocaleString()}.`
: null}
@@ -950,7 +950,7 @@ const Staking: NextPage = () => {
{lockedPythBalance?.toString()}{' '}
{lockingPythBalance &&
- lockingPythBalance.toString() !== '0' ? (
+ !lockingPythBalance.isZero() ? (
@@ -1002,7 +1002,7 @@ const Staking: NextPage = () => {
{unlockedPythBalance?.toString()}{' '}
{unlockingPythBalance &&
- unlockingPythBalance.toString() !== '0' ? (
+ !unlockingPythBalance.isZero() ? (