Skip to content

Commit

Permalink
Merge pull request #3087 from Emurgo/Ahmed/wallet-nav
Browse files Browse the repository at this point in the history
Make the last selected wallet get selected by default
  • Loading branch information
vsubhuman authored Jan 31, 2023
2 parents 7c499d1 + 8cdefac commit 96a59bd
Show file tree
Hide file tree
Showing 21 changed files with 327 additions and 148 deletions.
12 changes: 10 additions & 2 deletions packages/yoroi-extension/app/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ export const Routes = (
)
)}
/>

<Route
path={ROUTES.NFTS.ROOT}
component={(props) => (
Expand All @@ -237,7 +236,6 @@ export const Routes = (
)
)}
/>

<Route
exact
path={ROUTES.WALLETS.ADD}
Expand Down Expand Up @@ -300,6 +298,11 @@ export const Routes = (
path={ROUTES.SWITCH}
component={(props) => <WalletSwitch {...props} stores={stores} actions={actions} />}
/>
<Route
exact
path={ROUTES.REVAMP.CATALYST_VOTING}
component={(props) => <VotingPage {...props} stores={stores} actions={actions} />}
/>
<Redirect to={ROUTES.MY_WALLETS} />
</Switch>
</Suspense>
Expand Down Expand Up @@ -352,6 +355,11 @@ const WalletsSubpages = (stores, actions) => (
path={ROUTES.WALLETS.CATALYST_VOTING}
component={(props) => <VotingPage {...props} stores={stores} actions={actions} />}
/>
<Route
exact
path={ROUTES.REVAMP.TRANSFER}
component={(props) => <Transfer {...props} stores={stores} actions={actions} />}
/>
</Switch>
);

Expand Down
14 changes: 14 additions & 0 deletions packages/yoroi-extension/app/api/localStorage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const storageKeys = {
CATALYST_ROUND_INFO: networkForLocalStorage + '-CATALYST_ROUND_INFO',
// ========== CONNECTOR ========== //
ERGO_CONNECTOR_WHITELIST: 'connector_whitelist',
SELECTED_WALLET: 'SELECTED_WALLET',
};

export type SetCustomUserThemeRequest = {|
Expand Down Expand Up @@ -118,6 +119,19 @@ export default class LocalStorageApi {

unsetUserTheme: void => Promise<void> = () => removeLocalItem(storageKeys.THEME);

// ========== Select Wallet ========== //

getSelectedWalletId: void => number | null = () => {
const id = localStorage.getItem(storageKeys.SELECTED_WALLET);
if (!id) return null
if (isNaN(Number(id))) throw new Error(`Invalid wallet Id: ${id}`);
return Number(id)
}

setSelectedWalletId: number => void = (id) => {
localStorage.setItem(storageKeys.SELECTED_WALLET, id.toString())
}

// ========== Custom User Theme ========== //

getCustomUserTheme: void => Promise<?string> = () => getLocalItem(storageKeys.CUSTOM_THEME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ function TextField({
theme.name === 'classic' ? { shrink: true, ...InputLabelProps } : { ...InputLabelProps }
}
InputProps={{
disableUnderline: revamp,
...(theme.name === 'classic' ? { notched: false } : {}),
endAdornment:
type === 'password' ? (
Expand Down Expand Up @@ -112,7 +113,6 @@ function TextField({
{Boolean(error) === true ? <ErrorIcon /> : done === true ? <DoneIcon /> : null}
</InputAdornment>
),
disableUnderline: revamp,
placeholder: placeholder != null ? placeholder : '',
}}
{...props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ const messages = defineMessages({

type Props = {|
+currentTheme: Theme,
+selectTheme: ({| theme: string |}) => PossiblyAsync<void>,
+onSubmit: (theme: string) => PossiblyAsync<void>,
+onExternalLinkClick: MouseEvent => void,
+switchToFirstWallet: void => void,
|};

const NEW_THEME = THEMES.YOROI_REVAMP
Expand All @@ -89,7 +88,7 @@ export default class ThemeSettingsBlock extends Component<Props> {
render(): Node {
const {
currentTheme,
selectTheme,
onSubmit,
onExternalLinkClick,
} = this.props;
const { intl } = this.context;
Expand Down Expand Up @@ -121,7 +120,7 @@ export default class ThemeSettingsBlock extends Component<Props> {
value={currentTheme === NEW_THEME ? NEW_THEME : OLD_THEME}
onChange={(e) => {
const theme = e.target.value === NEW_THEME ? NEW_THEME : THEMES.YOROI_MODERN
selectTheme({ theme })
onSubmit(theme)
}}
sx={{
display: 'flex',
Expand Down Expand Up @@ -177,7 +176,7 @@ export default class ThemeSettingsBlock extends Component<Props> {
row
value={currentTheme}
onChange={(e) => {
selectTheme({ theme: e.target.value })
onSubmit(e.target.value)
}}
>
<Box sx={{ display: 'flex', flexDirection: 'column', justifyContent: 'flex-start', marginRight: '24px' }}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ export default class TransactionRevamp extends Component<Props, State> {
</ExplorableHashContainer>
</CopyableAddress>
{this.generateAddressButton(request.address.address)}
<Typography variant="body2" color="var(--yoroi-palette-gray-900)">
<Typography component='span' variant="body2" color="var(--yoroi-palette-gray-900)">
{renderAmount(request.address.value.getDefaultEntry())}
</Typography>
{request.address.value.nonDefaultEntries().map(entry => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import AboutYoroiSettingsBlock from '../../../components/settings/categories/gen
import UnitOfAccountSettings from '../../../components/settings/categories/general-setting/UnitOfAccountSettings';
import LocalizableError from '../../../i18n/LocalizableError';
import type { LanguageType } from '../../../i18n/translations';
import { THEMES } from '../../../styles/utils';
import type { Theme } from '../../../styles/utils';
import { PublicDeriver } from '../../../api/ada/lib/storage/models/PublicDeriver';
import { ReactComponent as AdaCurrency } from '../../../assets/images/currencies/ADA.inline.svg';
Expand Down Expand Up @@ -64,22 +65,6 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
intl: intlShape.isRequired,
};

switchWallet: (PublicDeriver<>) => void = publicDeriver => {
this.generated.actions.router.goToRoute.trigger({
route: this.generated.stores.app.currentRoute,
publicDeriver,
});
};

handleSwitchToFirstWallet: void => void = () => {
const selectedWallet = this.generated.stores.wallets.selected;
if (selectedWallet == null) {
const wallets = this.generated.stores.wallets.publicDerivers;
const firstWallet = wallets[0];
this.switchWallet(firstWallet);
}
};

onSelectUnitOfAccount: string => Promise<void> = async (value) => {
const unitOfAccount = (value === 'ADA')
? unitOfAccountDisabledValue
Expand Down Expand Up @@ -143,8 +128,21 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
/>
<ThemeSettingsBlock
currentTheme={currentTheme}
switchToFirstWallet={this.handleSwitchToFirstWallet}
selectTheme={this.generated.actions.profile.updateTheme.trigger}
onSubmit={(theme: string) => {
if (theme === THEMES.YOROI_REVAMP) {
const { wallets } = this.generated.stores;
const publicDeriver = wallets.selected;
const publicDerivers = wallets.publicDerivers;

if (publicDeriver == null && publicDerivers.length !== 0) {
const lastSelectedWallet = wallets.getLastSelectedWallet();
this.generated.actions.wallets.setActiveWallet.trigger({
wallet: lastSelectedWallet ?? publicDerivers[0],
});
}
}
this.generated.actions.profile.updateTheme.trigger({ theme })
}}
onExternalLinkClick={handleExternalLinkClick}
/>
<AboutYoroiSettingsBlock
Expand Down Expand Up @@ -182,6 +180,13 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
|}) => void,
|},
|},
wallets: {|
setActiveWallet: {|
trigger: (params: {|
wallet: PublicDeriver<>,
|}) => void,
|},
|},
|},
stores: {|
app: {| currentRoute: string |},
Expand All @@ -206,6 +211,7 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
wallets: {|
selected: null | PublicDeriver<>,
publicDerivers: Array<PublicDeriver<>>,
getLastSelectedWallet: void => ?PublicDeriver<>,
|},
coinPriceStore: {|
getCurrentPrice: (
Expand Down Expand Up @@ -248,6 +254,7 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
wallets: {
selected: stores.wallets.selected,
publicDerivers: stores.wallets.publicDerivers,
getLastSelectedWallet: stores.wallets.getLastSelectedWallet,
},
coinPriceStore: {
getCurrentPrice: stores.coinPriceStore.getCurrentPrice,
Expand All @@ -258,6 +265,9 @@ export default class GeneralSettingsPage extends Component<InjectedOrGenerated<G
},
},
actions: {
wallets: {
setActiveWallet: { trigger: actions.wallets.setActiveWallet.trigger },
},
profile: {
updateLocale: { trigger: actions.profile.updateLocale.trigger },
updateTheme: { trigger: actions.profile.updateTheme.trigger },
Expand Down
43 changes: 9 additions & 34 deletions packages/yoroi-extension/app/containers/transfer/Transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ import type { $npm$ReactIntl$IntlFormat } from 'react-intl';
import { PublicDeriver } from '../../api/ada/lib/storage/models/PublicDeriver/index';
import { CoinTypes } from '../../config/numbersConfig';
import HorizontalLine from '../../components/widgets/HorizontalLine';
import NavBarContainerRevamp from '../NavBarContainerRevamp';
import { withLayout } from '../../styles/context/layout';
import type { LayoutComponentMap } from '../../styles/context/layout';
import type { GeneratedData as NavBarContainerRevampData } from '../NavBarContainerRevamp';
import SubMenu from '../../components/topbar/SubMenu';
import { allSubcategoriesRevamp } from '../../stores/stateless/topbarCategories';

export type GeneratedData = typeof Transfer.prototype.generated;

Expand All @@ -52,52 +49,30 @@ class Transfer extends Component<AllProps> {

render(): Node {
const sidebarContainer = <SidebarContainer {...this.generated.SidebarContainerProps} />;

const menu = (
<SubMenu
options={allSubcategoriesRevamp.map(category => ({
className: category.className,
label: this.context.intl.formatMessage(category.label),
route: category.route,
}))}
onItemClick={route => this.generated.actions.router.goToRoute.trigger({ route })}
isActiveItem={route => this.generated.stores.app.currentRoute.startsWith(route)}
/>
);
const navbarClassic = (
const navbar = (
<NavBarContainer
{...this.generated.NavBarContainerProps}
title={
<NavBarTitle title={this.context.intl.formatMessage(globalMessages.sidebarTransfer)} />
}
/>
);

const navbarRevamp = (
<NavBarContainerRevamp
{...this.generated.NavBarContainerRevampProps}
title={
<NavBarTitle title={this.context.intl.formatMessage(globalMessages.walletLabel)} />
}
menu={menu}
/>
);

const navbar = this.props.renderLayoutComponent({
CLASSIC: navbarClassic,
REVAMP: navbarRevamp,
});

return (
const content = this.getContent();
const transferClassic = (
<TopBarLayout
banner={<BannerContainer {...this.generated.BannerContainerProps} />}
navbar={navbar}
sidebar={sidebarContainer}
showInContainer
>
{this.getContent()}
{content}
</TopBarLayout>
);

return this.props.renderLayoutComponent({
CLASSIC: transferClassic,
REVAMP: content,
})
}

getContent: void => Node = () => {
Expand Down
36 changes: 23 additions & 13 deletions packages/yoroi-extension/app/containers/wallet/MyWalletsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ import { genLookupOrFail, getTokenName } from '../../stores/stateless/tokenHelpe
import { getReceiveAddress } from '../../stores/stateless/addressStores';
import BuySellDialog from '../../components/buySell/BuySellDialog';
import type { WalletInfo } from '../../components/buySell/BuySellDialog';
import { addressToDisplayString } from '../../api/ada/lib/storage/bridge/utils'
import { networks } from '../../api/ada/lib/storage/database/prepackaged/networks'
import NavBarRevamp from '../../components/topbar/NavBarRevamp'
import { withLayout } from '../../styles/context/layout'
import type { LayoutComponentMap } from '../../styles/context/layout'
import { Box } from '@mui/system'
import { addressToDisplayString } from '../../api/ada/lib/storage/bridge/utils';
import { networks } from '../../api/ada/lib/storage/database/prepackaged/networks';
import NavBarRevamp from '../../components/topbar/NavBarRevamp';
import { withLayout } from '../../styles/context/layout';
import type { LayoutComponentMap } from '../../styles/context/layout';
import { Box } from '@mui/system';

export type GeneratedData = typeof MyWalletsPage.prototype.generated;

type Props = InjectedOrGenerated<GeneratedData>
type Props = InjectedOrGenerated<GeneratedData>;

type InjectedProps = {| +renderLayoutComponent: LayoutComponentMap => Node |};
type AllProps = {| ...Props, ...InjectedProps |};
Expand All @@ -76,7 +76,14 @@ class MyWalletsPage extends Component<AllProps> {
}

componentDidMount () {
this.generated.actions.wallets.unselectWallet.trigger();
const isRevamp = this.generated.stores.profile.isRevampTheme;
if (isRevamp) {
this.generated.actions.router.goToRoute.trigger({
route: ROUTES.WALLETS.ROOT,
});
} else {
this.generated.actions.wallets.unselectWallet.trigger();
}
}

handleWalletNavItemClick: PublicDeriver<> => void = (
Expand Down Expand Up @@ -105,13 +112,10 @@ class MyWalletsPage extends Component<AllProps> {
const { uiDialogs } = stores;

const sidebarContainer = <SidebarContainer {...this.generated.SidebarContainerProps} />

const wallets = this.generated.stores.wallets.publicDerivers;

const navbarTitle = (
<NavBarTitle title={intl.formatMessage(globalMessages.sidebarWallets)} />
);

const navbarElementClassic = (
<NavBar
title={navbarTitle}
Expand Down Expand Up @@ -417,11 +421,16 @@ class MyWalletsPage extends Component<AllProps> {
|},
wallets: {|
unselectWallet: {| trigger: (params: void) => void |},
setActiveWallet: {| trigger: (params: {| wallet: PublicDeriver<> |}) => void |},
setActiveWallet: {| trigger: (params: {|
wallet: PublicDeriver<>,
|}) => void |},
|},
|},
stores: {|
profile: {| shouldHideBalance: boolean |},
profile: {|
shouldHideBalance: boolean,
isRevampTheme: boolean,
|},
uiDialogs: {|
isOpen: any => boolean
|},
Expand Down Expand Up @@ -462,6 +471,7 @@ class MyWalletsPage extends Component<AllProps> {
stores: {
profile: {
shouldHideBalance: stores.profile.shouldHideBalance,
isRevampTheme: stores.profile.isRevampTheme,
},
uiDialogs: {
isOpen: stores.uiDialogs.isOpen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const genBaseProps: {|
stores: {
profile: {
shouldHideBalance: false,
isRevampTheme: false,
},
wallets: {
publicDerivers: request.publicDerivers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ export default class NFTsWrapper extends Component<Props> {
BannerContainerProps: InjectedOrGenerated<BannerContainerData>,
SidebarContainerProps: InjectedOrGenerated<SidebarContainerData>,
NavBarContainerRevampProps: InjectedOrGenerated<NavBarContainerRevampData>,

stores: {|
router: {| location: any |},
tokenInfoStore: {|
Expand Down
Loading

0 comments on commit 96a59bd

Please sign in to comment.