-
Notifications
You must be signed in to change notification settings - Fork 315
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
1 parent
b53bc94
commit f459232
Showing
14 changed files
with
223 additions
and
114 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
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
69 changes: 69 additions & 0 deletions
69
apps/ledger-live-mobile/src/newArch/features/Accounts/hooks/useAddAccount.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,69 @@ | ||
import { useSelector } from "react-redux"; | ||
import { BaseNavigation } from "~/components/RootNavigator/types/helpers"; | ||
import { readOnlyModeEnabledSelector } from "~/reducers/settings"; | ||
import { useNavigation } from "@react-navigation/native"; | ||
import { NavigatorName } from "~/const"; | ||
import { useCallback, useMemo, useState } from "react"; | ||
import { track } from "~/analytics"; | ||
import { useFeature } from "@ledgerhq/live-common/featureFlags/index"; | ||
import { AddAccountScreenProps } from "LLM/features/Accounts/types/addAccount"; | ||
|
||
const useAddAccount = ({ currency, onClose }: AddAccountScreenProps) => { | ||
const navigation = useNavigation<BaseNavigation>(); | ||
const walletSyncFeatureFlag = useFeature("llmWalletSync"); | ||
|
||
const isReadOnlyModeEnabled = useSelector(readOnlyModeEnabledSelector); | ||
const isWalletSyncEnabled = walletSyncFeatureFlag?.enabled; | ||
const hasCurrency = !!currency; | ||
|
||
const [isWalletSyncDrawerVisible, setWalletSyncDrawerVisible] = useState(false); | ||
|
||
const navigationParams = useMemo(() => { | ||
return hasCurrency | ||
? currency.type === "TokenCurrency" | ||
? { token: currency } | ||
: { currency } | ||
: {}; | ||
}, [hasCurrency, currency]); | ||
|
||
const trackButtonClick = useCallback((button: string) => { | ||
track("button_clicked", { | ||
button, | ||
drawer: "AddAccountsModal", | ||
}); | ||
}, []); | ||
|
||
const onClickImport = useCallback(() => { | ||
trackButtonClick("Import from Desktop"); | ||
onClose?.(); | ||
navigation.navigate(NavigatorName.ImportAccounts); | ||
}, [navigation, trackButtonClick, onClose]); | ||
|
||
const onClickAdd = useCallback(() => { | ||
trackButtonClick("With your Ledger"); | ||
onClose?.(); | ||
navigation.navigate(NavigatorName.AddAccounts, navigationParams); | ||
}, [navigation, navigationParams, trackButtonClick, onClose]); | ||
|
||
const onClickWalletSync = useCallback(() => { | ||
trackButtonClick("With Wallet Sync"); | ||
onClose?.(); | ||
setWalletSyncDrawerVisible(true); | ||
}, [trackButtonClick, setWalletSyncDrawerVisible, onClose]); | ||
|
||
const onCloseWalletSyncDrawer = useCallback(() => { | ||
setWalletSyncDrawerVisible(false); | ||
}, [setWalletSyncDrawerVisible]); | ||
|
||
return { | ||
isWalletSyncEnabled, | ||
isReadOnlyModeEnabled, | ||
isWalletSyncDrawerVisible, | ||
onClickAdd, | ||
onClickImport, | ||
onClickWalletSync, | ||
onCloseWalletSyncDrawer, | ||
}; | ||
}; | ||
|
||
export default useAddAccount; |
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
74 changes: 74 additions & 0 deletions
74
.../newArch/features/Accounts/screens/AddAccount/components/SelectAddAccountMethod/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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React from "react"; | ||
import { useTranslation } from "react-i18next"; | ||
import useAddAccount from "LLM/features/Accounts/hooks/useAddAccount"; | ||
import { Flex, Icons, Text } from "@ledgerhq/native-ui"; | ||
import ActionRow from "LLM/components/ActionRow"; | ||
import { AddAccountScreenProps } from "LLM/features/Accounts/types/addAccount"; | ||
|
||
const SelectAddAccountMethod = ({ | ||
currency, | ||
doesNotHaveAccount, | ||
onClose, | ||
setWalletSyncDrawerVisible, | ||
}: AddAccountScreenProps) => { | ||
const { t } = useTranslation(); | ||
const rows = []; | ||
|
||
const { isWalletSyncEnabled, isReadOnlyModeEnabled, onClickAdd, onClickImport } = useAddAccount({ | ||
currency, | ||
doesNotHaveAccount, | ||
onClose, | ||
}); | ||
|
||
if (!isReadOnlyModeEnabled) { | ||
rows.push({ | ||
titleKey: "addAccountsModal.drawer.add.title", | ||
descriptionKey: "addAccountsModal.drawer.add.description", | ||
onPress: onClickAdd, | ||
icon: <Icons.LedgerDevices color={"primary.c80"} />, | ||
testID: "add-accounts-modal-add-button", | ||
}); | ||
} | ||
if (isWalletSyncEnabled) { | ||
rows.push({ | ||
titleKey: "addAccountsModal.drawer.walletSync.title", | ||
descriptionKey: "addAccountsModal.drawer.walletSync.description", | ||
onPress: setWalletSyncDrawerVisible, | ||
icon: <Icons.QrCode color={"primary.c80"} />, | ||
}); | ||
} else { | ||
rows.push({ | ||
titleKey: "addAccountsModal.drawer.import.title", | ||
descriptionKey: "addAccountsModal.drawer.import.description", | ||
onPress: onClickImport, | ||
icon: <Icons.QrCode color={"primary.c80"} />, | ||
}); | ||
} | ||
|
||
return ( | ||
<> | ||
<Text variant="h4" fontWeight="semiBold" fontSize="24px" mb={16}> | ||
{doesNotHaveAccount | ||
? t("addAccountsModal.title") | ||
: t("addAccountsModal.drawer.drawerTitleHasAccount")} | ||
</Text> | ||
<Text variant="large" fontWeight="medium" fontSize="14px" color="neutral.c70" mb="32px"> | ||
{t("addAccountsModal.drawer.drawerSubTitle")} | ||
</Text> | ||
<Flex flexDirection="column" rowGap={16}> | ||
{rows.map((row, index) => ( | ||
<ActionRow | ||
key={index} | ||
title={t(row.titleKey)} | ||
description={t(row.descriptionKey)} | ||
onPress={row.onPress} | ||
icon={row.icon} | ||
testID={row.testID} | ||
/> | ||
))} | ||
</Flex> | ||
</> | ||
); | ||
}; | ||
|
||
export default SelectAddAccountMethod; |
54 changes: 54 additions & 0 deletions
54
apps/ledger-live-mobile/src/newArch/features/Accounts/screens/AddAccount/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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React, { useState } from "react"; | ||
import useAddAccountDrawer from "~/newArch/features/Accounts/hooks/useAddAccountDrawer"; | ||
import QueuedDrawer from "~/components/QueuedDrawer"; | ||
import { TrackScreen } from "~/analytics"; | ||
import SelectAddAccountMethod from "./components/SelectAddAccountMethod"; | ||
import { AddAccountDrawerProps } from "LLM/features/Accounts/types/addAccountDrawer"; | ||
import Drawer from "LLM/components/Dummy/Drawer"; | ||
|
||
const AddAccountDrawer = ({ | ||
isOpened, | ||
currency, | ||
doesNotHaveAccount, | ||
onClose, | ||
reopenDrawer, | ||
}: AddAccountDrawerProps) => { | ||
const { isAddAccountDrawerVisible, onCloseAddAccountDrawer } = useAddAccountDrawer({ | ||
isOpened, | ||
currency, | ||
onClose, | ||
reopenDrawer, | ||
}); | ||
|
||
const [isWalletSyncDrawerVisible, setWalletSyncDrawerVisible] = useState(false); | ||
|
||
const onWalletSyncOpen = () => { | ||
onCloseAddAccountDrawer(); | ||
setWalletSyncDrawerVisible(true); | ||
}; | ||
|
||
const onCloseWalletSyncDrawer = () => { | ||
setWalletSyncDrawerVisible(false); | ||
reopenDrawer(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<QueuedDrawer | ||
isRequestingToBeOpened={isAddAccountDrawerVisible} | ||
onClose={onCloseAddAccountDrawer} | ||
> | ||
<TrackScreen category="Add/Import accounts" type="drawer" /> | ||
<SelectAddAccountMethod | ||
doesNotHaveAccount={doesNotHaveAccount} | ||
currency={currency} | ||
onClose={onCloseAddAccountDrawer} | ||
setWalletSyncDrawerVisible={onWalletSyncOpen} | ||
/> | ||
</QueuedDrawer> | ||
<Drawer isOpen={isWalletSyncDrawerVisible} handleClose={onCloseWalletSyncDrawer} /> | ||
</> | ||
); | ||
}; | ||
|
||
export default AddAccountDrawer; |
8 changes: 8 additions & 0 deletions
8
apps/ledger-live-mobile/src/newArch/features/Accounts/types/addAccount.ts
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,8 @@ | ||
import { CryptoCurrency, TokenCurrency } from "@ledgerhq/types-cryptoassets"; | ||
|
||
export type AddAccountScreenProps = { | ||
currency?: CryptoCurrency | TokenCurrency | null; | ||
doesNotHaveAccount?: boolean; | ||
onClose?: () => void; | ||
setWalletSyncDrawerVisible?: () => void; | ||
}; |
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
93 changes: 0 additions & 93 deletions
93
apps/ledger-live-mobile/src/newArch/features/WalletSync/drawers/addAccount/index.tsx
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.