-
Notifications
You must be signed in to change notification settings - Fork 327
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
112 additions
and
55 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 |
73 changes: 73 additions & 0 deletions
73
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,73 @@ | ||
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 | ||
* /> | ||
* | ||
* Note: The component only renders if the currency is supported for "buy" actions | ||
* and if there's a valid error passed. | ||
*/ | ||
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, trackingSource]); | ||
Check failure on line 57 in apps/ledger-live-desktop/src/renderer/families/evm/SendAmountFields/LowGasAlertBuyMore.tsx live-github-bot / @Desktop • Test Appreact-hooks/exhaustive-deps
Check failure on line 57 in apps/ledger-live-desktop/src/renderer/families/evm/SendAmountFields/LowGasAlertBuyMore.tsx live-github-bot / @Desktop • Test Appreact-hooks/exhaustive-deps
|
||
|
||
if (!isCurrencySupported("BUY", account.currency)) { | ||
return null; | ||
} | ||
|
||
if (!gasPriceError) return null; | ||
return ( | ||
<Flex onClick={onBuyClick}> | ||
<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