Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Dashboard buttons, reward calculation LUNC #405

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions components/AssetInput/AssetInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ interface AssetInputProps {
balance?: number
whalePrice?: number
disabled?: boolean
minMax?: boolean
hideHalfMax?: boolean
isSingleInput?: boolean
hideToken?: string
edgeTokenList?: string[]
ignoreSlack?: boolean
hideMax?: boolean
hideDollarValue?: boolean
showBalanceSlider?: boolean
isBonding?: boolean
Expand All @@ -45,7 +44,7 @@ const AssetInput = forwardRef((props: AssetInputProps, _) => {
token,
onChange,
ignoreSlack,
hideMax,
hideHalfMax,
hideDollarValue,
mobile,
} = props
Expand Down Expand Up @@ -104,7 +103,7 @@ const AssetInput = forwardRef((props: AssetInputProps, _) => {
numberOfTokens={numberOfTokens}
dollarValue={dollarValue}
maxDisabled={maxDisabled}
hideMax={hideMax}
hideHalfMax={hideHalfMax}
onMaxClick={onMaxClick}
onHalfClick={onHalfClick}
mobile={mobile}
Expand Down
2 changes: 1 addition & 1 deletion components/AssetInput/AssetList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const AssetList: FC<AssetListProps> = ({
: tokenList?.tokens

const [tokenBalance = []] =
unbondingBalances !== null
unbondingBalances
? [
tokens?.map(({ symbol }) => unbondingBalances.find((b) => b.tokenSymbol === symbol)?.amount),
]
Expand Down
20 changes: 10 additions & 10 deletions components/AssetInput/BalanceWithMax.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const MaxButton = ({
}
return (
<Button
disabled={disabled}
isDisabled={disabled}
variant="outline"
size={size}
onClick={onClick}
Expand All @@ -79,7 +79,7 @@ const HalfButton = ({
}
return (
<Button
disabled={disabled}
isDisabled={disabled}
variant="outline"
size={size}
onClick={onClick}
Expand Down Expand Up @@ -129,7 +129,7 @@ type BalanceWithMaxProps = {
dollarValue: number | string
onMaxClick: () => void
onHalfClick: () => void
hideMax?: boolean
hideHalfMax?: boolean
hideDollarValue?: boolean
mobile?: boolean
}
Expand All @@ -141,7 +141,7 @@ const BalanceWithMaxNHalf = ({
dollarValue,
onMaxClick,
onHalfClick,
hideMax,
hideHalfMax,
hideDollarValue,
mobile,
}: BalanceWithMaxProps) => (
Expand All @@ -159,14 +159,14 @@ const BalanceWithMaxNHalf = ({
<HalfButton
disabled={maxDisabled}
onClick={onHalfClick}
hideHalf={hideMax}
hideHalf={hideHalfMax}
maxwidth={'50'}
size={'xs'}
/>
<MaxButton
disabled={maxDisabled}
onClick={onMaxClick}
hideMax={hideMax}
hideMax={hideHalfMax}
maxwidth={'50'}
size={'xs'}
/>
Expand All @@ -176,15 +176,15 @@ const BalanceWithMaxNHalf = ({
<>
<HStack justifyContent="center" spacing={2} width={'full'} paddingTop={1} paddingBottom={4}>
<HalfButton
disabled={hideMax}
disabled={hideHalfMax}
onClick={onHalfClick}
hideHalf={hideMax}
hideHalf={hideHalfMax}
size={'md'}
/>
<MaxButton
disabled={hideMax}
disabled={hideHalfMax}
onClick={onMaxClick}
hideMax={hideMax}
hideMax={hideHalfMax}
size={'md'}
/>
</HStack>
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/BondingActions/Bond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const Bond = ({ balances, tokenSymbols }) => {
{...field}
token={currentBondState}
balance={currentTokenBalance}
minMax={false}
hideHalfMax={false}
disabled={false}
onChange={(value, isTokenChange) => {
onInputChange(value, 0)
Expand Down
8 changes: 5 additions & 3 deletions components/Pages/Dashboard/BondingActions/BondingActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -232,12 +232,14 @@ const BondingActions = ({ globalAction }) => {
borderRadius="full"
width="80%"
variant="primary"
disabled={
isDisabled={
txStep === TxStep.Estimating ||
txStep === TxStep.Posting ||
txStep === TxStep.Broadcasting ||
(currentBondState.amount <= 0 &&
globalAction !== ActionType.withdraw &&
(globalAction === ActionType.bond && currentBondState.amount <= 0 &&
isWalletConnected) ||
(currentBondState.amount === 0 &&
globalAction === ActionType.unbond &&
isWalletConnected) ||
(totalWithdrawable === 0 && ActionType.withdraw === globalAction)
}
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/BondingActions/Unbond.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const Unbond = ({ bondedAssets }: { bondedAssets: BondedData[] }) => {
{...field}
token={currentBondState}
balance={currentTokenBalance}
minMax={false}
hideHalfMax={false}
disabled={false}
onChange={(value, isTokenChange) => {
onInputChange(value, 0)
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/BondingActions/Withdraw.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ const Withdraw = ({
<TokenBox label="Withdrawable" tokens={withdrawableTokens} />
</Stack>
{isWalletConnected &&
unbondingRequests !== null &&
unbondingRequests &&
unbondingRequests?.length > 0 && (
<Box
overflowY="scroll"
Expand Down
27 changes: 12 additions & 15 deletions components/Pages/Dashboard/BondingActions/hooks/useTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const useTransaction = () => {
(/insufficient funds/u).test(error.toString()) ||
(/Overflow: Cannot Sub with/u).test(error.toString())
) {
console.error(error)
console.error(error.toString())
setTxStep(TxStep.Idle)
setError('Insufficient Funds')
setButtonLabel('Insufficient Funds')
Expand All @@ -59,7 +59,7 @@ export const useTransaction = () => {
setButtonLabel('You have pending transaction')
throw new Error('You have pending transaction')
} else {
console.error({ error })
console.error(error.toString())
setTxStep(TxStep.Idle)
setError(error?.message)
throw Error(error?.message)
Expand All @@ -72,7 +72,7 @@ export const useTransaction = () => {
}
},
{
enabled: txStep === TxStep.Idle && error === null && Boolean(signingClient),
enabled: txStep === TxStep.Idle && !error && Boolean(signingClient),
refetchOnWindowFocus: false,
retry: false,
staleTime: 0,
Expand All @@ -85,34 +85,34 @@ export const useTransaction = () => {
},
)

const { mutate } = useMutation((data: any) => {
const { mutate } = useMutation(async (data: any) => {
const adjustedAmount = convertDenomToMicroDenom(data.amount, 6)
if (data.bondingAction === ActionType.bond) {
return bondTokens(
if (data.bondingAction === ActionType.bond) {
return await bondTokens(
signingClient,
address,
adjustedAmount,
data.denom,
config,
)
} else if (data.bondingAction === ActionType.unbond) {
return unbondTokens(
return await unbondTokens(
signingClient,
address,
adjustedAmount,
data.denom,
config,
)
} else if (data.bondingAction === ActionType.withdraw) {
return withdrawTokens(
return await withdrawTokens(
signingClient, address, data.denom, config,
)
} else if (data.bondingAction === ActionType.claim) {
return claimRewards(
return await claimRewards(
signingClient, address, config,
)
} else {
return createNewEpoch(
return await createNewEpoch(
signingClient, config, address,
)
}
Expand Down Expand Up @@ -222,7 +222,7 @@ export const useTransaction = () => {
return signingClient?.getTx(txHash)
},
{
enabled: txHash !== null,
enabled: Boolean(txHash),
retry: true,
},
)
Expand All @@ -238,9 +238,6 @@ export const useTransaction = () => {
amount: number | null,
denom: string | null,
) => {
if (fee === null) {
return
}
setBondingAction(bondingAction)

mutate({
Expand All @@ -253,7 +250,7 @@ export const useTransaction = () => {
[fee, mutate])

useEffect(() => {
if (txInfo !== null && txHash !== null) {
if (txInfo && txHash) {
if (txInfo?.code) {
setTxStep(TxStep.Failed)
} else {
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/BondingOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const BondingOverview = ({
<WhaleTooltip
key={`${e.tokenType}${e.actionType}`}
label={
e?.value !== null && isWalletConnected
e?.value && isWalletConnected
? `$${(Number(e.value) * Number(whalePrice)).toFixed(2)}`
: 'n/a'
}
Expand Down
3 changes: 1 addition & 2 deletions components/Pages/Dashboard/RewardsComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ const RewardsComponent = ({

const bondingHasStarted: boolean = useMemo(() => genesisStartTimeInNano / 1_000_000 < Date.now(),
[genesisStartTimeInNano])

return (
<VStack
px={4}
Expand Down Expand Up @@ -253,7 +252,7 @@ const RewardsComponent = ({
borderRadius="full"
variant="primary"
width={'100%'}
disabled={
isDisabled={
txStep === TxStep.Estimating ||
txStep === TxStep.Posting ||
txStep === TxStep.Broadcasting ||
Expand Down
2 changes: 1 addition & 1 deletion components/Pages/Dashboard/hooks/useDashboardData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const useDashboardData = (
])

const isLoading = useMemo(() => queries.some((query) => (
query.isLoading || query.data === null || query.data === undefined
query.isLoading || !query.data
)),
[queries])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ const DepositForm = ({
>
<VStack width="full" alignItems="flex-start" paddingBottom={8}>
<AssetInput
ignoreSlack={false}
value={token}
token={token}
disabled={false}
minMax={true}
hideHalfMax={false}
balance={balance}
showList={showList}
edgeTokenList={edgeTokenList}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ const WithdrawForm = ({
tx?.reset()
}
}, [tx, token, setToken])

return (
<VStack
paddingY={6}
Expand Down Expand Up @@ -109,7 +108,9 @@ const WithdrawForm = ({
tx?.txStep === TxStep.Posting ||
tx?.txStep === TxStep.Broadcasting
}
disabled={tx.txStep !== TxStep.Ready && isWalletConnected}
disabled={tx.txStep === TxStep.Estimating ||
tx.txStep === TxStep.Posting ||
tx.txStep === TxStep.Broadcasting }
>
{buttonLabel}
</Button>
Expand Down
15 changes: 9 additions & 6 deletions components/Pages/Flashloan/Vaults/hooks/useTransaction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export const useTransaction = ({
return signingClient.getTx(txHash)
},
{
enabled: txHash !== null,
enabled: Boolean(txHash),
retry: true,
},
)
Expand All @@ -72,8 +72,11 @@ export const useTransaction = ({
async () => {
setError(null)
setTxStep(TxStep.Estimating)
if (!signingClient) {
return
}
try {
const response = await signingClient.simulate(
const response = await signingClient?.simulate(
senderAddress,
debouncedMsgs,
'',
Expand Down Expand Up @@ -112,9 +115,9 @@ export const useTransaction = ({
},
{
enabled:
debouncedMsgs !== null &&
Boolean(debouncedMsgs) &&
txStep === TxStep.Idle &&
error === null &&
!error &&
Boolean(signingClient) &&
enabled,
refetchOnWindowFocus: false,
Expand Down Expand Up @@ -215,13 +218,13 @@ export const useTransaction = ({
}

const submit = useCallback(() => {
if (!(fee === null || msgs === null || msgs.length < 1)) {
if (!(!fee || !msgs || msgs.length < 1)) {
mutate()
}
}, [msgs, fee, mutate])

useEffect(() => {
if (txInfo !== null && txHash !== null) {
if (txInfo && txHash) {
if (txInfo?.code) {
setTxStep(TxStep.Failed)
onError?.(txHash, txInfo)
Expand Down
Loading
Loading