Skip to content

Commit

Permalink
fix: zap button loading state
Browse files Browse the repository at this point in the history
  • Loading branch information
0xMasayoshi committed Nov 9, 2024
1 parent 8b417c5 commit f1bff99
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
16 changes: 10 additions & 6 deletions apps/web/src/app/(networks)/(evm)/[chainId]/pool/v2/add/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ const ZapWidget: FC<ZapWidgetProps> = ({ chainId, pool, poolState, title }) => {
[inputAmount, inputCurrency],
)

const { data: zapResponse, isError: isZapError } = useZap({
const {
data: zapResponse,
isError: isZapError,
isLoading: isZapLoading,
} = useZap({
chainId,
fromAddress: address,
tokenIn: [inputCurrency.isNative ? NativeAddress : inputCurrency.address],
Expand All @@ -232,8 +236,8 @@ const ZapWidget: FC<ZapWidgetProps> = ({ chainId, pool, poolState, title }) => {

const {
data: estGas,
isError: isEstimateGasError,
isLoading: isEstimateGasLoading,
isError: isEstGasError,
isLoading: isEstGasLoading,
} = useEstimateGas({
chainId,
account: address,
Expand Down Expand Up @@ -292,10 +296,10 @@ const ZapWidget: FC<ZapWidgetProps> = ({ chainId, pool, poolState, title }) => {
fullWidth
testId="zap-liquidity"
onClick={() => preparedTx && sendTransaction(preparedTx)}
loading={isEstimateGasLoading || isWritePending}
disabled={isZapError || isEstimateGasError}
loading={isZapLoading || isEstGasLoading || isWritePending}
disabled={isZapError || isEstGasError}
>
{isZapError || isEstimateGasError ? (
{isZapError || isEstGasError ? (
'Shoot! Something went wrong :('
) : isWritePending ? (
<Dots>{title}</Dots>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ export const SteerPositionZap: FC<SteerPositionAddProps> = ({ vault }) => {
[inputAmount, inputCurrency],
)

const { data: zapResponse, isError: isZapError } = useZap({
const {
data: zapResponse,
isError: isZapError,
isLoading: isZapLoading,
} = useZap({
chainId: vault.chainId,
fromAddress: address,
tokenIn: [inputCurrency.isNative ? NativeAddress : inputCurrency.address],
Expand All @@ -40,8 +44,8 @@ export const SteerPositionZap: FC<SteerPositionAddProps> = ({ vault }) => {

const {
data: estGas,
isError: isEstimateGasError,
isLoading: isEstimateGasLoading,
isError: isEstGasError,
isLoading: isEstGasLoading,
} = useEstimateGas({
chainId: vault.chainId,
account: address,
Expand Down Expand Up @@ -103,10 +107,12 @@ export const SteerPositionZap: FC<SteerPositionAddProps> = ({ vault }) => {
fullWidth
testId="zap-liquidity"
onClick={() => preparedTx && sendTransaction(preparedTx)}
loading={isEstimateGasLoading || isWritePending}
disabled={isZapError || isEstimateGasError}
loading={
isZapLoading || isEstGasLoading || isWritePending
}
disabled={isZapError || isEstGasError}
>
{isZapError || isEstimateGasError ? (
{isZapError || isEstGasError ? (
'Shoot! Something went wrong :('
) : isWritePending ? (
<Dots>Add Liquidity</Dots>
Expand Down
18 changes: 12 additions & 6 deletions apps/web/src/ui/pool/ZapSectionLegacy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ export const ZapSectionLegacy: FC<ZapSectionLegacyProps> = ({
[inputAmount, inputCurrency],
)

const { data: zapResponse, isError: isZapError } = useZap({
const {
data: zapResponse,
isError: isZapError,
isLoading: isZapLoading,
} = useZap({
chainId: _pool.chainId,
fromAddress: address,
tokenIn: [inputCurrency.isNative ? NativeAddress : inputCurrency.address],
Expand All @@ -73,8 +77,8 @@ export const ZapSectionLegacy: FC<ZapSectionLegacyProps> = ({

const {
data: estGas,
isError: isEstimateGasError,
isLoading: isEstimateGasLoading,
isError: isEstGasError,
isLoading: isEstGasLoading,
} = useEstimateGas({
chainId: _pool.chainId,
account: address,
Expand Down Expand Up @@ -166,10 +170,12 @@ export const ZapSectionLegacy: FC<ZapSectionLegacyProps> = ({
fullWidth
testId="zap-liquidity"
onClick={() => preparedTx && sendTransaction(preparedTx)}
loading={isEstimateGasLoading || isWritePending}
disabled={isZapError || isEstimateGasError}
loading={
isZapLoading || isEstGasLoading || isWritePending
}
disabled={isZapError || isEstGasError}
>
{isZapError || isEstimateGasError ? (
{isZapError || isEstGasError ? (
'Shoot! Something went wrong :('
) : isWritePending ? (
<Dots>Add Liquidity</Dots>
Expand Down

0 comments on commit f1bff99

Please sign in to comment.