-
Notifications
You must be signed in to change notification settings - Fork 449
Feature/live 20724 [LLD][UI] Memo screen #13505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Moustafa-Koterba
wants to merge
9
commits into
develop
Choose a base branch
from
feature/LIVE-20724
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f09dbac
feat(desktop): [LLD][UI] Memo screen (new send flow - LIVE-20724)
Moustafa-Koterba 4bc7b5e
feat: refacto / fix conflicts / update banner
dilaouid 0c8b3d8
feat: implement settings for dont show again + fix reset memo on naviβ¦
Moustafa-Koterba 97d20cb
PR reviews
Moustafa-Koterba 3e663e2
feat(desktop): reviews + reset code to develop
Moustafa-Koterba 8feb951
feat(desktop): fix knip.json
Moustafa-Koterba 2219804
feat(desktop): fix desktop typecheck
Moustafa-Koterba 80fdd1d
feat(desktop): setup mvvm for SendHeader component
Moustafa-Koterba e0c01b8
test(lld): update screenshots (ubuntu-22.04) lld, test, screenshot
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 @@ | ||
| --- | ||
| "ledger-live-desktop": minor | ||
| "@ledgerhq/live-common": minor | ||
| --- | ||
|
|
||
| Feature/live 20724 [LLD][UI] Memo screen |
This file contains hidden or 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 hidden or 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 hidden or 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,76 +1,82 @@ | ||
| import React, { useCallback, useMemo } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { BigNumber } from "bignumber.js"; | ||
| import { AddressInput, DialogHeader } from "@ledgerhq/lumen-ui-react"; | ||
| import { useFlowWizard } from "../../FlowWizard/FlowWizardContext"; | ||
| import { useSendFlowData, useSendFlowActions } from "../context/SendFlowContext"; | ||
| import { sendFeatures } from "@ledgerhq/live-common/bridge/descriptor"; | ||
| import { | ||
| SEND_FLOW_STEP, | ||
| type SendFlowStep, | ||
| type SendFlowBusinessContext, | ||
| type SendFlowStep, | ||
| } from "@ledgerhq/live-common/flows/send/types"; | ||
| import type { SendStepConfig } from "../types"; | ||
| import { getRecipientDisplayValue, getRecipientSearchPrefillValue } from "./utils"; | ||
| import { AddressInput, DialogHeader } from "@ledgerhq/lumen-ui-react"; | ||
| import React, { useMemo } from "react"; | ||
| import { useTranslation } from "react-i18next"; | ||
| import { useFlowWizard } from "../../FlowWizard/FlowWizardContext"; | ||
| import { useSendFlowActions, useSendFlowData } from "../context/SendFlowContext"; | ||
| import { useAvailableBalance } from "../hooks/useAvailableBalance"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can keep the import instead of adding the whole function inside the file
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
| import { useSendHeaderModel } from "../hooks/useSendHeaderModel"; | ||
| import { MemoTypeSelect } from "../screens/Recipient/components/Memo/MemoTypeSelect"; | ||
| import { MemoValueInput } from "../screens/Recipient/components/Memo/MemoValueInput"; | ||
| import { SkipMemoSection } from "../screens/Recipient/components/Memo/SkipMemoSection"; | ||
| import { useRecipientMemo } from "../screens/Recipient/hooks/useRecipientMemo"; | ||
| import type { SendStepConfig } from "../types"; | ||
|
|
||
| export function SendHeader() { | ||
| const wizard = useFlowWizard<SendFlowStep, SendFlowBusinessContext, SendStepConfig>(); | ||
| const { state, uiConfig, recipientSearch } = useSendFlowData(); | ||
| const { close, transaction } = useSendFlowActions(); | ||
| const { t } = useTranslation(); | ||
| const availableText = useAvailableBalance(state.account.account); | ||
|
|
||
| const { navigation, currentStep } = wizard; | ||
| const currentStepConfig = wizard.currentStepConfig as SendStepConfig; | ||
| const currencyId = state.account.currency?.id; | ||
|
|
||
| const currencyName = state.account.currency?.ticker ?? ""; | ||
| const availableText = useAvailableBalance(state.account.account); | ||
| const memoDefaultOption = useMemo(() => { | ||
| return sendFeatures.getMemoDefaultOption(state.account.currency ?? undefined); | ||
| }, [state.account.currency]); | ||
|
|
||
| const handleBack = useCallback(() => { | ||
| if (navigation.canGoBack()) { | ||
| // Reset amount-related state when leaving Amount step (back navigation), | ||
| // otherwise the transaction amount can persist while the UI remounts empty. | ||
| if (currentStep === SEND_FLOW_STEP.AMOUNT) { | ||
| transaction.updateTransaction(tx => ({ | ||
| ...tx, | ||
| amount: new BigNumber(0), | ||
| useAllAmount: false, | ||
| feesStrategy: null, | ||
| })); | ||
| } | ||
| navigation.goToPreviousStep(); | ||
| } else { | ||
| close(); | ||
| } | ||
| }, [close, currentStep, navigation, transaction]); | ||
| const memoTypeOptions = useMemo(() => { | ||
| return uiConfig.memoOptions ?? []; | ||
| }, [uiConfig]); | ||
|
|
||
| const showBackButton = navigation.canGoBack(); | ||
| const showTitle = currentStepConfig?.showTitle !== false; | ||
| const { | ||
| hasMemoTypeOptions, | ||
| memo, | ||
| onMemoTypeChange, | ||
| showMemoValueInput, | ||
| onMemoValueChange, | ||
| showSkipMemo, | ||
| skipMemoState, | ||
| onSkipMemoRequestConfirm, | ||
| onSkipMemoCancelConfirm, | ||
| onSkipMemoConfirm, | ||
| resetViewState, | ||
| } = useRecipientMemo({ | ||
| hasMemo: uiConfig.hasMemo, | ||
| memoDefaultOption, | ||
| memoType: uiConfig.memoType, | ||
| memoTypeOptions, | ||
| onMemoChange: memo => { | ||
| transaction.setRecipient({ ...state.recipient, memo }); | ||
| }, | ||
| onMemoSkip: () => { | ||
| navigation.goToNextStep(); | ||
| }, | ||
| resetKey: `${state.account.account?.id ?? ""}|${currencyId ?? ""}|${ | ||
| recipientSearch.value.length === 0 ? "empty" : "filled" | ||
| }`, | ||
| }); | ||
|
|
||
| const title = showTitle ? t("newSendFlow.title", { currency: currencyName }) : ""; | ||
| const descriptionText = | ||
| showTitle && availableText ? t("newSendFlow.available", { amount: availableText }) : ""; | ||
| const { | ||
| addressInputValue, | ||
| descriptionText, | ||
| handleBack, | ||
| handleRecipientInputClick, | ||
| showBackButton, | ||
| showMemoControls, | ||
| showRecipientInput, | ||
| title, | ||
| transactionErrorName, | ||
| } = useSendHeaderModel({ availableText, resetViewState }); | ||
|
|
||
| const showRecipientInput = currentStepConfig?.addressInput ?? false; | ||
| const isRecipientStep = currentStep === SEND_FLOW_STEP.RECIPIENT; | ||
| const isAmountStep = currentStep === SEND_FLOW_STEP.AMOUNT; | ||
|
|
||
| const addressInputValue = useMemo(() => { | ||
| if (isRecipientStep) return recipientSearch.value; | ||
| if (isAmountStep) return getRecipientDisplayValue(state.recipient); | ||
| return recipientSearch.value; | ||
| }, [isRecipientStep, isAmountStep, recipientSearch.value, state.recipient]); | ||
|
|
||
| const handleRecipientInputClick = useCallback(() => { | ||
| if (!isAmountStep) return; | ||
|
|
||
| const prefillValue = getRecipientSearchPrefillValue(state.recipient); | ||
| if (prefillValue) { | ||
| recipientSearch.setValue(prefillValue); | ||
| } | ||
|
|
||
| handleBack(); | ||
| }, [handleBack, isAmountStep, recipientSearch, state.recipient]); | ||
|
|
||
| const recipientInputContent = useMemo(() => { | ||
| if (!showRecipientInput) return null; | ||
|
|
||
|
|
@@ -91,30 +97,82 @@ export function SendHeader() { | |
| } | ||
|
|
||
| return ( | ||
| <AddressInput | ||
| className="-mt-12 mb-24 px-24" | ||
| defaultValue={addressInputValue} | ||
| onChange={e => recipientSearch.setValue(e.target.value)} | ||
| onClear={recipientSearch.clear} | ||
| placeholder={ | ||
| uiConfig.recipientSupportsDomain | ||
| ? t("newSendFlow.placeholder") | ||
| : t("newSendFlow.placeholderNoENS") | ||
| } | ||
| /> | ||
| <> | ||
| <AddressInput | ||
| className="-mt-12 mb-12 px-24" | ||
| value={addressInputValue} | ||
| onChange={e => recipientSearch.setValue(e.target.value)} | ||
| onClear={recipientSearch.clear} | ||
| placeholder={ | ||
| uiConfig.recipientSupportsDomain | ||
| ? t("newSendFlow.placeholder") | ||
| : t("newSendFlow.placeholderNoENS") | ||
| } | ||
| /> | ||
| {showMemoControls && currencyId ? ( | ||
| <div className="mb-24 px-24"> | ||
| <div className="flex flex-col gap-12"> | ||
| {hasMemoTypeOptions ? ( | ||
| <MemoTypeSelect | ||
| currencyId={currencyId} | ||
| options={memoTypeOptions} | ||
| value={memo.type} | ||
| onChange={onMemoTypeChange} | ||
| /> | ||
| ) : null} | ||
|
|
||
| {showMemoValueInput ? ( | ||
| <MemoValueInput | ||
| currencyId={currencyId} | ||
| value={memo.value} | ||
| maxLength={uiConfig.memoMaxLength} | ||
| transactionErrorName={transactionErrorName} | ||
| onChange={onMemoValueChange} | ||
| /> | ||
| ) : null} | ||
| </div> | ||
|
|
||
| {showSkipMemo ? ( | ||
| <SkipMemoSection | ||
| currencyId={currencyId} | ||
| state={skipMemoState} | ||
| onRequestConfirm={onSkipMemoRequestConfirm} | ||
| onCancelConfirm={onSkipMemoCancelConfirm} | ||
| onConfirm={onSkipMemoConfirm} | ||
| /> | ||
| ) : null} | ||
| </div> | ||
| ) : null} | ||
| </> | ||
| ); | ||
| }, [ | ||
| showRecipientInput, | ||
| isAmountStep, | ||
| addressInputValue, | ||
| handleRecipientInputClick, | ||
| recipientSearch, | ||
| uiConfig.recipientSupportsDomain, | ||
| uiConfig.memoMaxLength, | ||
| t, | ||
| showMemoControls, | ||
| currencyId, | ||
| hasMemoTypeOptions, | ||
| memoTypeOptions, | ||
| memo.type, | ||
| memo.value, | ||
| onMemoTypeChange, | ||
| showMemoValueInput, | ||
| transactionErrorName, | ||
| onMemoValueChange, | ||
| showSkipMemo, | ||
| skipMemoState, | ||
| onSkipMemoRequestConfirm, | ||
| onSkipMemoCancelConfirm, | ||
| onSkipMemoConfirm, | ||
| handleRecipientInputClick, | ||
| ]); | ||
|
|
||
| return ( | ||
| <div className="-mb-12 flex flex-col"> | ||
| <div className="flex flex-col"> | ||
| <DialogHeader | ||
| appearance="compact" | ||
| title={title} | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your
SendHeadershould use MVVM at this stage IMOThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I will add unit test in an other PR for the new hook π