Skip to content

Commit efd3e9a

Browse files
committed
fixed stake amount bug
1 parent 4a5842d commit efd3e9a

File tree

3 files changed

+29
-15
lines changed

3 files changed

+29
-15
lines changed

frontend/src/components/GeyserFirst/GeyserStakeView.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,18 @@ export const GeyserStakeView = () => {
7070
useEffect(() => {
7171
refreshInputAmount()
7272
if (geyserAction === GeyserAction.STAKE && stakingTokenInfo.price > 0) {
73-
const initialStakeAmountUSD = 1000
74-
const stakeAmt = Math.max(initialStakeAmountUSD / stakingTokenInfo.price, 0.000001)
75-
const stakeAmtFP = parseUnits(stakeAmt.toFixed(stakingTokenInfo.decimals), stakingTokenInfo.decimals)
76-
setUserInput(stakeAmt)
77-
setParsedUserInput(BigNumber.from(stakeAmtFP))
73+
if (stakableAmount.eq(0)) {
74+
const initialStakeAmountUSD = 1000
75+
const stakeAmt = Math.max(initialStakeAmountUSD / stakingTokenInfo.price, 0.000001)
76+
const stakeAmtFP = parseUnits(stakeAmt.toFixed(stakingTokenInfo.decimals), stakingTokenInfo.decimals)
77+
setUserInput(stakeAmt)
78+
setParsedUserInput(BigNumber.from(stakeAmtFP))
79+
} else {
80+
setUserInput(formatUnits(stakableAmount, stakingTokenDecimals))
81+
setParsedUserInput(stakableAmount)
82+
}
7883
}
79-
}, [geyserAction])
84+
}, [geyserAction, stakingTokenBalance, currentStakeable])
8085

8186
const handleGeyserInteraction = () => {
8287
if (geyserAction === GeyserAction.STAKE) {
@@ -182,7 +187,7 @@ export const GeyserStakeView = () => {
182187
<EstimatedRewards parsedUserInput={parsedUserInput} />
183188
{!address && <ConnectWalletWarning onClick={() => connectWallet()} />}
184189
{address && parsedUserInput.gt(0) && (
185-
<StakeWarning link={poolAddress} balance={stakableAmount} staked={currentStakeAmount} />
190+
<StakeWarning link={poolAddress} balance={stakableAmount.sub(parsedUserInput)} staked={currentStakeAmount} />
186191
)}
187192
<GeyserInteractionButton
188193
disabled={!address || parsedUserInput.isZero() || parsedUserInput.gt(stakableAmount)}

frontend/src/components/GeyserFirst/StakeWarning.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ interface Props {
1010
}
1111

1212
export const StakeWarning: React.FC<Props> = ({ link, balance, staked }) => {
13-
if (balance.gt(0) && staked.lte(0)) {
13+
if (balance.gte(0)) {
1414
return <></>
1515
}
16+
1617
return (
1718
<StakeWarningContainer>
1819
<ColoredDiv />
1920
<Content>
2021
<MessageContainer>
21-
<Message>{staked.lte(0) ? 'Insufficient balance' : 'Entire balance staked'}</Message>
22+
<Message>Insufficient balance</Message>
2223
</MessageContainer>
2324
<ButtonWrapper>
2425
<Button onClick={() => window.open(link, '_blank')}>{staked.lte(0) ? 'Get LP' : 'Get more'}</Button>

frontend/src/context/GeyserContext.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,16 +166,24 @@ export const GeyserContextProvider: React.FC = ({ children }) => {
166166
})()
167167
}
168168

169+
const clearSatsCache = (selectedGeyser: Geyser | null, selectedVault: Vault | null) => {
170+
if (selectedGeyser) {
171+
clearGeyserStatsCache(selectedGeyser)
172+
}
173+
if (selectedGeyser && selectedVault) {
174+
clearUserStatsCache(selectedGeyser, selectedVault)
175+
}
176+
}
177+
169178
const handleStakeUnstake = async (selectedVault: Vault | null, parsedAmount: BigNumber) => {
170-
let r: any
179+
clearSatsCache(selectedGeyserInfo?.geyser, selectedVault)
171180
if (geyserAction === GeyserAction.STAKE) {
172-
r = await handleStake(selectedVault, parsedAmount)
181+
return handleStake(selectedVault, parsedAmount)
173182
} else if (geyserAction === GeyserAction.UNSTAKE) {
174-
r = await handleUnstake(selectedVault, parsedAmount)
183+
return handleUnstake(selectedVault, parsedAmount)
184+
} else {
185+
return undefined
175186
}
176-
clearGeyserStatsCache(selectedGeyser)
177-
clearUserStatsCache(selectedGeyser, selectedVault)
178-
return r
179187
}
180188

181189
const handleWrapping = async (

0 commit comments

Comments
 (0)