Skip to content

Commit

Permalink
feat(ui): add default widget
Browse files Browse the repository at this point in the history
  • Loading branch information
pwltr committed May 25, 2024
1 parent 0f31076 commit 5683b8a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
1 change: 1 addition & 0 deletions e2e/backup.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ d('Backup', () => {
await element(by.id('NavigationClose')).tap();

// add price widget
await element(by.id('WalletsScrollView')).scroll(300, 'down', NaN, 0.85);
await element(by.id('WidgetsAdd')).tap();
await element(by.id('WidgetsOnboarding-button')).tap();
await element(by.id('PriceWidget')).tap();
Expand Down
1 change: 1 addition & 0 deletions e2e/widgets.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ d('Widgets', () => {
}

// add price widget
await element(by.id('WalletsScrollView')).scroll(300, 'down', NaN, 0.85);
await element(by.id('WidgetsAdd')).tap();
await element(by.id('WidgetsOnboarding-button')).tap();
await element(by.id('PriceWidget')).tap();
Expand Down
25 changes: 22 additions & 3 deletions src/screens/Wallets/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import { Trans, useTranslation } from 'react-i18next';
import { Display } from '../../styles/text';
import { useBalance } from '../../hooks/wallet';
import useColors from '../../hooks/colors';
import { useSlashfeed } from '../../hooks/widgets';
import { useAppDispatch, useAppSelector } from '../../hooks/redux';
import { updateSettings } from '../../store/slices/settings';
import { widgetsSelector } from '../../store/reselect/widgets';
import { refreshWallet } from '../../utils/wallet';
import { SUPPORTED_FEED_TYPES } from '../../utils/widgets';
import ActivityListShort from '../../screens/Activity/ActivityListShort';
import DetectSwipe from '../../components/DetectSwipe';
import BalanceHeader from '../../components/BalanceHeader';
Expand All @@ -21,6 +23,7 @@ import SafeAreaInset from '../../components/SafeAreaInset';
import WalletOnboarding from '../../components/WalletOnboarding';
import Balances from '../../components/Balances';
import Header from './Header';
import { PriceFeedURL } from '../Widgets/WidgetsSuggestions';
import type { WalletScreenProps } from '../../navigation/types';
import {
enableSwipeToHideBalanceSelector,
Expand All @@ -31,6 +34,7 @@ import {
import { showToast } from '../../utils/notifications';
import { ignoresHideBalanceToastSelector } from '../../store/reselect/user';
import { ignoreHideBalanceToast } from '../../store/slices/user';
import { setFeedWidget } from '../../store/slices/widgets';

const HEADER_HEIGHT = 46;

Expand All @@ -55,6 +59,7 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
const widgets = useAppSelector(widgetsSelector);
const insets = useSafeAreaInsets();
const { t } = useTranslation('wallet');
const { config } = useSlashfeed({ url: PriceFeedURL });

// tell WalletNavigator that this screen is focused
useFocusEffect(
Expand Down Expand Up @@ -91,6 +96,22 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
setRefreshing(false);
};

const onHideOnboarding = (): void => {
// add default widgets
if (config) {
dispatch(
setFeedWidget({
url: PriceFeedURL,
type: SUPPORTED_FEED_TYPES.PRICE_FEED,
fields: config.fields.filter((f) => f.name === 'BTC/USD'),
extras: { period: '1D', showSource: false },
}),
);
}

dispatch(updateSettings({ hideOnboardingMessage: true }));
};

const hideOnboarding =
hideOnboardingSetting ||
totalBalance > 0 ||
Expand Down Expand Up @@ -149,9 +170,7 @@ const Wallets = ({ navigation, onFocus }: Props): ReactElement => {
components={{ accent: <Display color="brand" /> }}
/>
}
onHide={(): void => {
dispatch(updateSettings({ hideOnboardingMessage: true }));
}}
onHide={onHideOnboarding}
/>
)}
</ScrollView>
Expand Down
3 changes: 2 additions & 1 deletion src/store/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { showToast } from '../../utils/notifications';
import { wipeLdkStorage } from '../../utils/lightning';
import { getSelectedWallet } from '../../utils/wallet';
import { TWalletName } from '../types/wallet';
import { __E2E__ } from '../../constants/env';

/**
* This method will wipe all data for the specified wallet.
Expand Down Expand Up @@ -48,7 +49,7 @@ export const wipeApp = async ({
});
}

if (restartApp) {
if (restartApp && !__E2E__) {
// avoid freeze on iOS
await sleep(1000);
RNRestart.Restart();
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10190,6 +10190,11 @@ [email protected]:
dependencies:
p-defer "^3.0.0"

react-native-flipper@^0.164.0:
version "0.164.0"
resolved "https://registry.yarnpkg.com/react-native-flipper/-/react-native-flipper-0.164.0.tgz#64f6269a86a13a72e30f53ba9f5281d2073a7697"
integrity sha512-iJhIe3rqx6okuzBp4AJsTa2b8VRAOGzoLRFx/4HGbaGvu8AurZjz8TTQkhJsRma8dsHN2b6KKZPvGGW3wdWzvA==

[email protected]:
version "2.20.0"
resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.20.0.tgz#05a9362b473bfc0910772c0acbb73a78dbc810f6"
Expand Down

0 comments on commit 5683b8a

Please sign in to comment.