mirror of
https://github.com/oceanprotocol/market.git
synced 2024-12-02 05:57:29 +01:00
display token approval message on loading (#1280)
This commit is contained in:
parent
905be83a00
commit
aa4bdda207
@ -11,7 +11,8 @@ export default function TokenApproval({
|
|||||||
amount,
|
amount,
|
||||||
tokenAddress,
|
tokenAddress,
|
||||||
tokenSymbol,
|
tokenSymbol,
|
||||||
setSubmitting
|
setSubmitting,
|
||||||
|
setIsTokenApproved
|
||||||
}: {
|
}: {
|
||||||
actionButton: JSX.Element
|
actionButton: JSX.Element
|
||||||
disabled: boolean
|
disabled: boolean
|
||||||
@ -19,6 +20,7 @@ export default function TokenApproval({
|
|||||||
tokenAddress: string
|
tokenAddress: string
|
||||||
tokenSymbol: string
|
tokenSymbol: string
|
||||||
setSubmitting?: (isSubmitting: boolean) => void
|
setSubmitting?: (isSubmitting: boolean) => void
|
||||||
|
setIsTokenApproved: (isApproved: boolean) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { asset, isAssetNetwork } = useAsset()
|
const { asset, isAssetNetwork } = useAsset()
|
||||||
const [tokenApproved, setTokenApproved] = useState(false)
|
const [tokenApproved, setTokenApproved] = useState(false)
|
||||||
@ -44,6 +46,9 @@ export default function TokenApproval({
|
|||||||
setTokenApproved(
|
setTokenApproved(
|
||||||
new Decimal(allowanceValue).greaterThanOrEqualTo(new Decimal(amount))
|
new Decimal(allowanceValue).greaterThanOrEqualTo(new Decimal(amount))
|
||||||
)
|
)
|
||||||
|
setIsTokenApproved(
|
||||||
|
new Decimal(allowanceValue).greaterThanOrEqualTo(new Decimal(amount))
|
||||||
|
)
|
||||||
}, [web3, tokenAddress, spender, accountId, amount, isAssetNetwork])
|
}, [web3, tokenAddress, spender, accountId, amount, isAssetNetwork])
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import React, { ReactElement } from 'react'
|
import React, { ReactElement, useState } from 'react'
|
||||||
import Loader from '@shared/atoms/Loader'
|
import Loader from '@shared/atoms/Loader'
|
||||||
import Button from '@shared/atoms/Button'
|
import Button from '@shared/atoms/Button'
|
||||||
import styles from './Actions.module.css'
|
import styles from './Actions.module.css'
|
||||||
@ -36,6 +36,7 @@ export default function Actions({
|
|||||||
setSubmitting?: (isSubmitting: boolean) => void
|
setSubmitting?: (isSubmitting: boolean) => void
|
||||||
}): ReactElement {
|
}): ReactElement {
|
||||||
const { networkId } = useWeb3()
|
const { networkId } = useWeb3()
|
||||||
|
const [isTokenApproved, setIsTokenApproved] = useState(false)
|
||||||
|
|
||||||
const actionButton = (
|
const actionButton = (
|
||||||
<Button
|
<Button
|
||||||
@ -64,11 +65,18 @@ export default function Actions({
|
|||||||
<>
|
<>
|
||||||
<div className={styles.actions}>
|
<div className={styles.actions}>
|
||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<Loader message={loaderMessage} />
|
<Loader
|
||||||
|
message={
|
||||||
|
isTokenApproved || actionName === 'Remove'
|
||||||
|
? loaderMessage
|
||||||
|
: `Approving ${tokenSymbol}...`
|
||||||
|
}
|
||||||
|
/>
|
||||||
) : actionName === 'Supply' || actionName === 'Swap' ? (
|
) : actionName === 'Supply' || actionName === 'Swap' ? (
|
||||||
<TokenApproval
|
<TokenApproval
|
||||||
actionButton={actionButton}
|
actionButton={actionButton}
|
||||||
amount={slippage ? applySlippage(amount) : amount}
|
amount={slippage ? applySlippage(amount) : amount}
|
||||||
|
setIsTokenApproved={setIsTokenApproved}
|
||||||
tokenAddress={tokenAddress}
|
tokenAddress={tokenAddress}
|
||||||
tokenSymbol={tokenSymbol}
|
tokenSymbol={tokenSymbol}
|
||||||
disabled={isDisabled}
|
disabled={isDisabled}
|
||||||
|
Loading…
Reference in New Issue
Block a user