-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: LowGasAlert errors on EVM (#7782)
* refactor: LowGasAlert errors on EVM * chore: lint * chore: I crave consistent behaviour * chore: redirect only if buy supported but still display the error
- Loading branch information
Showing
8 changed files
with
132 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"ledger-live-desktop": minor | ||
--- | ||
|
||
refactor: LowGasAlert to be consistent with all other errors |
67 changes: 67 additions & 0 deletions
67
apps/ledger-live-desktop/src/renderer/families/evm/SendAmountFields/LowGasAlertBuyMore.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { useCallback } from "react"; | ||
import { useHistory } from "react-router-dom"; | ||
import { useDispatch } from "react-redux"; | ||
import { setTrackingSource } from "~/renderer/analytics/TrackPage"; | ||
import { isCurrencySupported } from "~/renderer/screens/exchange/config"; | ||
import Alert from "~/renderer/components/Alert"; | ||
import { Account } from "@ledgerhq/types-live/lib/account"; | ||
import { Flex } from "@ledgerhq/react-ui"; | ||
import TranslatedError from "~/renderer/components/TranslatedError"; | ||
|
||
type LowGasAlertBuyMoreProps = { | ||
account: Account; | ||
handleRequestClose: () => void; | ||
gasPriceError: Error | null; | ||
trackingSource: string; | ||
}; | ||
|
||
/** | ||
* LowGasAlertBuyMore | ||
* | ||
* This component renders an alert message when the user has insufficient gas | ||
* to complete a transaction. | ||
* It also provides a call to action to buy more crypto, | ||
* handling redirection to the exchange flow. | ||
* | ||
* Usage: | ||
* <LowGasAlertBuyMore | ||
* account={mainAccount} | ||
* handleRequestClose={closeAllModal} | ||
* gasPriceError={gasPriceError} | ||
* trackingSource={"swap | send or whatever"}s | ||
* /> | ||
* | ||
*/ | ||
const LowGasAlertBuyMore = ({ | ||
account, | ||
handleRequestClose, | ||
gasPriceError, | ||
trackingSource, | ||
}: LowGasAlertBuyMoreProps) => { | ||
const history = useHistory(); | ||
const dispatch = useDispatch(); | ||
|
||
const onBuyClick = useCallback(() => { | ||
dispatch(handleRequestClose()); | ||
setTrackingSource(trackingSource); | ||
history.push({ | ||
pathname: "/exchange", | ||
state: { | ||
currency: account.currency.id, | ||
account: account.id, | ||
mode: "buy", | ||
}, | ||
}); | ||
}, [account.currency.id, account.id, history, dispatch, handleRequestClose, trackingSource]); | ||
|
||
if (!gasPriceError) return null; | ||
return ( | ||
<Flex onClick={isCurrencySupported("BUY", account.currency) ? onBuyClick : undefined}> | ||
<Alert type="warning"> | ||
<TranslatedError error={gasPriceError} /> | ||
</Alert> | ||
</Flex> | ||
); | ||
}; | ||
|
||
export default LowGasAlertBuyMore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters