Skip to content
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

Make the last selected wallet get selected by default #3087

Merged
merged 14 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -119,6 +120,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
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
Loading