-
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
male-gal
committed
Nov 28, 2023
1 parent
f27d82a
commit 5d03bf5
Showing
9 changed files
with
151 additions
and
50 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,6 @@ | ||
--- | ||
"@ledgerhq/types-live": patch | ||
"ledger-live-desktop": patch | ||
--- | ||
|
||
Adding new items to LLD post onboarding |
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
117 changes: 76 additions & 41 deletions
117
apps/ledger-live-desktop/src/renderer/modals/Receive/index.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 |
---|---|---|
@@ -1,61 +1,96 @@ | ||
import React, { PureComponent } from "react"; | ||
import React, { useState, useCallback, useEffect } from "react"; | ||
import logger from "~/renderer/logger"; | ||
import Modal from "~/renderer/components/Modal"; | ||
import Body, { StepId } from "./Body"; | ||
import { useDispatch, useSelector } from "react-redux"; | ||
import { accountsSelector } from "~/renderer/reducers/accounts"; | ||
import { openModal, closeModal } from "~/renderer/actions/modals"; | ||
|
||
type State = { | ||
stepId: StepId; | ||
isAddressVerified: boolean | undefined | null; | ||
verifyAddressError: Error | undefined | null; | ||
}; | ||
|
||
const INITIAL_STATE = { | ||
stepId: "account" as StepId, | ||
isAddressVerified: null, | ||
verifyAddressError: null, | ||
}; | ||
class ReceiveModal extends PureComponent<{}, State> { | ||
state = INITIAL_STATE; | ||
handleReset = () => | ||
this.setState({ | ||
...INITIAL_STATE, | ||
}); | ||
|
||
handleStepChange = (stepId: StepId) => | ||
this.setState({ | ||
stepId, | ||
}); | ||
|
||
handleChangeAddressVerified = (isAddressVerified?: boolean | null, err?: Error | null) => { | ||
const ReceiveModal = () => { | ||
const [state, setState] = useState<State>(INITIAL_STATE); | ||
|
||
const { stepId, isAddressVerified, verifyAddressError } = state; | ||
|
||
const setStepId = (newStepId: State["stepId"]) => { | ||
setState(prevState => ({ ...prevState, stepId: newStepId })); | ||
}; | ||
|
||
const setIsAddressVerified = (newIsAddressVerified: State["isAddressVerified"]) => { | ||
setState(prevState => ({ ...prevState, isAddressVerified: newIsAddressVerified })); | ||
}; | ||
|
||
const setVerifyAddressError = (newVerifyAddressError: State["verifyAddressError"]) => { | ||
setState(prevState => ({ ...prevState, verifyAddressError: newVerifyAddressError })); | ||
}; | ||
|
||
const handleReset = () => { | ||
setStepId(INITIAL_STATE.stepId); | ||
setIsAddressVerified(INITIAL_STATE.isAddressVerified); | ||
setVerifyAddressError(INITIAL_STATE.verifyAddressError); | ||
}; | ||
|
||
const handleChangeAddressVerified = (isAddressVerified?: boolean | null, err?: Error | null) => { | ||
if (err && err.name !== "UserRefusedAddress") { | ||
logger.critical(err); | ||
} | ||
this.setState({ | ||
isAddressVerified, | ||
verifyAddressError: err, | ||
}); | ||
setIsAddressVerified(isAddressVerified); | ||
setVerifyAddressError(err); | ||
}; | ||
|
||
render() { | ||
const { stepId, isAddressVerified, verifyAddressError } = this.state; | ||
const isModalLocked = stepId === "receive" && isAddressVerified === null; | ||
return ( | ||
<Modal | ||
name="MODAL_RECEIVE" | ||
centered | ||
onHide={this.handleReset} | ||
preventBackdropClick={isModalLocked} | ||
render={({ data, onClose }) => ( | ||
<Body | ||
onClose={onClose} | ||
stepId={stepId} | ||
isAddressVerified={isAddressVerified} | ||
verifyAddressError={verifyAddressError} | ||
onChangeAddressVerified={this.handleChangeAddressVerified} | ||
onChangeStepId={this.handleStepChange} | ||
params={data || {}} | ||
/> | ||
)} | ||
/> | ||
// Making sure at least one account exists, if not, redirecting to the add account modal | ||
const accounts = useSelector(accountsSelector); | ||
|
||
const dispatch = useDispatch(); | ||
const hasAccounts = !!accounts.length; | ||
|
||
const openAddAccounts = useCallback(() => { | ||
dispatch(closeModal("MODAL_RECEIVE")); | ||
dispatch( | ||
openModal("MODAL_ADD_ACCOUNTS", { | ||
currency: null, | ||
}), | ||
); | ||
} | ||
} | ||
}, [dispatch]); | ||
|
||
useEffect(() => { | ||
if (!hasAccounts) { | ||
openAddAccounts(); | ||
} | ||
}, [hasAccounts, openAddAccounts]); | ||
|
||
if (!hasAccounts) return null; | ||
|
||
const isModalLocked = stepId === "receive" && isAddressVerified === null; | ||
return ( | ||
<Modal | ||
name="MODAL_RECEIVE" | ||
centered | ||
onHide={handleReset} | ||
preventBackdropClick={isModalLocked} | ||
render={({ data, onClose }) => ( | ||
<Body | ||
onClose={onClose} | ||
stepId={stepId} | ||
isAddressVerified={isAddressVerified} | ||
verifyAddressError={verifyAddressError} | ||
onChangeAddressVerified={handleChangeAddressVerified} | ||
onChangeStepId={setStepId} | ||
params={data || {}} | ||
/> | ||
)} | ||
/> | ||
); | ||
}; | ||
|
||
export default ReceiveModal; |
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