Skip to content

Commit

Permalink
feat(settings): add app status screen in support
Browse files Browse the repository at this point in the history
  • Loading branch information
ovitrif committed Jan 26, 2024
1 parent f56ac9e commit 3f33a5c
Show file tree
Hide file tree
Showing 8 changed files with 360 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/assets/icons/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,34 @@ export const githubIcon = (color = 'white'): string =>
export const globeIcon = (color = 'white'): string =>
`<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path opacity="0.2" d="M12 21C16.9706 21 21 16.9706 21 12C21 7.02944 16.9706 3 12 3C7.02944 3 3 7.02944 3 12C3 16.9706 7.02944 21 12 21Z" fill="${color}"/><path fill-rule="evenodd" clip-rule="evenodd" d="M12 3.75C7.44365 3.75 3.75 7.44365 3.75 12C3.75 16.5563 7.44365 20.25 12 20.25C16.5563 20.25 20.25 16.5563 20.25 12C20.25 7.44365 16.5563 3.75 12 3.75ZM2.25 12C2.25 6.61522 6.61522 2.25 12 2.25C17.3848 2.25 21.75 6.61522 21.75 12C21.75 17.3848 17.3848 21.75 12 21.75C6.61522 21.75 2.25 17.3848 2.25 12Z" fill="${color}"/><path fill-rule="evenodd" clip-rule="evenodd" d="M2.7627 9C2.7627 8.58579 3.09848 8.25 3.5127 8.25H20.4875C20.9017 8.25 21.2375 8.58579 21.2375 9C21.2375 9.41421 20.9017 9.75 20.4875 9.75H3.5127C3.09848 9.75 2.7627 9.41421 2.7627 9Z" fill="${color}"/><path fill-rule="evenodd" clip-rule="evenodd" d="M2.7627 15C2.7627 14.5858 3.09848 14.25 3.5127 14.25H20.4874C20.9017 14.25 21.2374 14.5858 21.2374 15C21.2374 15.4142 20.9017 15.75 20.4874 15.75H3.5127C3.09848 15.75 2.7627 15.4142 2.7627 15Z" fill="${color}"/><path fill-rule="evenodd" clip-rule="evenodd" d="M10.0378 6.10169C9.4079 7.57289 9 9.6576 9 11.9996C9 14.3416 9.4079 16.4263 10.0378 17.8975C10.3533 18.6345 10.7098 19.1829 11.0674 19.5362C11.4218 19.8863 11.7361 20.008 12 20.008C12.2639 20.008 12.5782 19.8863 12.9326 19.5362C13.2902 19.1829 13.6467 18.6345 13.9622 17.8975C14.5921 16.4263 15 14.3416 15 11.9996C15 9.6576 14.5921 7.57289 13.9622 6.10169C13.6467 5.36474 13.2902 4.81632 12.9326 4.46305C12.5782 4.11294 12.2639 3.99121 12 3.99121C11.7361 3.99121 11.4218 4.11294 11.0674 4.46305C10.7098 4.81632 10.3533 5.36474 10.0378 6.10169ZM10.0132 3.39593C10.5561 2.85964 11.2284 2.49121 12 2.49121C12.7716 2.49121 13.4439 2.85964 13.9868 3.39593C14.5264 3.92906 14.978 4.66327 15.3411 5.51129C16.0684 7.21001 16.5 9.50449 16.5 11.9996C16.5 14.4947 16.0684 16.7892 15.3411 18.4879C14.978 19.336 14.5264 20.0702 13.9868 20.6033C13.4439 21.1396 12.7716 21.508 12 21.508C11.2284 21.508 10.5561 21.1396 10.0132 20.6033C9.47357 20.0702 9.02197 19.336 8.65889 18.4879C7.93156 16.7892 7.5 14.4947 7.5 11.9996C7.5 9.50449 7.93156 7.21001 8.65889 5.51129C9.02197 4.66327 9.47357 3.92906 10.0132 3.39593Z" fill="${color}"/></svg>`;

export const globeSimpleIcon = (color = 'white'): string =>
`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.2" d="M8 14C11.3137 14 14 11.3137 14 8C14 4.68629 11.3137 2 8 2C4.68629 2 2 4.68629 2 8C2 11.3137 4.68629 14 8 14Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 2.5C4.96243 2.5 2.5 4.96243 2.5 8C2.5 11.0376 4.96243 13.5 8 13.5C11.0376 13.5 13.5 11.0376 13.5 8C13.5 4.96243 11.0376 2.5 8 2.5ZM1.5 8C1.5 4.41015 4.41015 1.5 8 1.5C11.5899 1.5 14.5 4.41015 14.5 8C14.5 11.5899 11.5899 14.5 8 14.5C4.41015 14.5 1.5 11.5899 1.5 8Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 8C1.5 7.72386 1.72386 7.5 2 7.5H14C14.2761 7.5 14.5 7.72386 14.5 8C14.5 8.27614 14.2761 8.5 14 8.5H2C1.72386 8.5 1.5 8.27614 1.5 8Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M6.69187 4.06812C6.27193 5.04892 6 6.43873 6 8.00007C6 9.56141 6.27193 10.9512 6.69187 11.932C6.90223 12.4233 7.13987 12.7889 7.37828 13.0244C7.61455 13.2578 7.82408 13.339 8 13.339C8.17592 13.339 8.38545 13.2578 8.62172 13.0244C8.86013 12.7889 9.09777 12.4233 9.30813 11.932C9.72807 10.9512 10 9.56141 10 8.00007C10 6.43873 9.72807 5.04892 9.30813 4.06812C9.09777 3.57682 8.86013 3.21121 8.62172 2.97569C8.38545 2.74229 8.17592 2.66113 8 2.66113C7.82408 2.66113 7.61455 2.74229 7.37828 2.97569C7.13987 3.21121 6.90223 3.57682 6.69187 4.06812ZM6.6755 2.26428C7.03742 1.90675 7.48557 1.66113 8 1.66113C8.51443 1.66113 8.96258 1.90675 9.3245 2.26428C9.68428 2.6197 9.98535 3.10917 10.2274 3.67452C10.7123 4.807 11 6.33665 11 8.00007C11 9.66348 10.7123 11.1931 10.2274 12.3256C9.98535 12.891 9.68428 13.3804 9.3245 13.7359C8.96258 14.0934 8.51443 14.339 8 14.339C7.48557 14.339 7.03742 14.0934 6.6755 13.7359C6.31572 13.3804 6.01465 12.891 5.77259 12.3256C5.28771 11.1931 5 9.66348 5 8.00007C5 6.33665 5.28771 4.807 5.77259 3.67452C6.01465 3.10917 6.31572 2.6197 6.6755 2.26428Z" fill="${color}"/>
</svg>
`;

export const broadcastIcon = (color = 'white'): string =>
`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.2" d="M8 10C9.10457 10 10 9.10457 10 8C10 6.89543 9.10457 6 8 6C6.89543 6 6 6.89543 6 8C6 9.10457 6.89543 10 8 10Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M8 6.5C7.17157 6.5 6.5 7.17157 6.5 8C6.5 8.82843 7.17157 9.5 8 9.5C8.82843 9.5 9.5 8.82843 9.5 8C9.5 7.17157 8.82843 6.5 8 6.5ZM5.5 8C5.5 6.61929 6.61929 5.5 8 5.5C9.38071 5.5 10.5 6.61929 10.5 8C10.5 9.38071 9.38071 10.5 8 10.5C6.61929 10.5 5.5 9.38071 5.5 8Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M5.17151 4.46413C5.36661 4.65956 5.36634 4.97614 5.17091 5.17124C4.79911 5.5424 4.50414 5.98324 4.30289 6.46852C4.10164 6.9538 3.99805 7.47401 3.99805 7.99936C3.99805 8.52472 4.10164 9.04492 4.30289 9.53021C4.50414 10.0155 4.79911 10.4563 5.17091 10.8275C5.36634 11.0226 5.36661 11.3392 5.17151 11.5346C4.97642 11.73 4.65984 11.7303 4.46441 11.5352C3.99957 11.0712 3.63079 10.52 3.37917 9.91328C3.12756 9.30656 2.99805 8.65619 2.99805 7.99936C2.99805 7.34254 3.12756 6.69216 3.37917 6.08544C3.63079 5.47873 3.99957 4.92757 4.46441 4.46353C4.65984 4.26843 4.97642 4.2687 5.17151 4.46413Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.8278 4.46413C11.0229 4.2687 11.3395 4.26843 11.5349 4.46353C11.9997 4.92758 12.3685 5.47873 12.6201 6.08544C12.8717 6.69216 13.0013 7.34254 13.0013 7.99936C13.0013 8.65619 12.8717 9.30656 12.6201 9.91328C12.3685 10.52 11.9997 11.0712 11.5349 11.5352C11.3395 11.7303 11.0229 11.73 10.8278 11.5346C10.6327 11.3392 10.633 11.0226 10.8284 10.8275C11.2002 10.4563 11.4952 10.0155 11.6964 9.53021C11.8977 9.04492 12.0013 8.52472 12.0013 7.99936C12.0013 7.47401 11.8977 6.9538 11.6964 6.46852C11.4952 5.98324 11.2002 5.5424 10.8284 5.17124C10.633 4.97614 10.6327 4.65956 10.8278 4.46413Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3.40463 2.69655C3.59973 2.89198 3.59946 3.20856 3.40403 3.40366C2.79983 4.00683 2.32049 4.72322 1.99344 5.51183C1.66639 6.30045 1.49805 7.14581 1.49805 7.99955C1.49805 8.85329 1.66639 9.69866 1.99344 10.4873C2.32049 11.2759 2.79983 11.9923 3.40403 12.5954C3.59946 12.7905 3.59973 13.1071 3.40463 13.3026C3.20954 13.498 2.89295 13.4983 2.69753 13.3032C2.00028 12.6071 1.44713 11.7804 1.06972 10.8703C0.69231 9.9603 0.498047 8.98476 0.498047 7.99955C0.498047 7.01435 0.69231 6.03881 1.06972 5.12875C1.44713 4.2187 2.00028 3.392 2.69753 2.69595C2.89295 2.50085 3.20954 2.50112 3.40463 2.69655Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.5973 2.69655C12.7924 2.50112 13.109 2.50085 13.3044 2.69595C14.0017 3.392 14.5548 4.2187 14.9322 5.12875C15.3096 6.03881 15.5039 7.01435 15.5039 7.99955C15.5039 8.98476 15.3096 9.9603 14.9322 10.8703C14.5548 11.7804 14.0017 12.6071 13.3044 13.3032C13.109 13.4983 12.7924 13.498 12.5973 13.3026C12.4022 13.1071 12.4025 12.7905 12.5979 12.5954C13.2021 11.9923 13.6815 11.2759 14.0085 10.4873C14.3356 9.69866 14.5039 8.85329 14.5039 7.99955C14.5039 7.14581 14.3356 6.30045 14.0085 5.51183C13.6815 4.72322 13.2021 4.00683 12.5979 3.40366C12.4025 3.20856 12.4022 2.89198 12.5973 2.69655Z" fill="${color}"/>
</svg>
`;

export const cloudCheckIcon = (color = 'white'): string =>
`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.2" d="M5.0005 8C5.0005 7.0111 5.29375 6.0444 5.84315 5.22215C6.39256 4.39991 7.17345 3.75904 8.08708 3.3806C9.00071 3.00217 10.006 2.90315 10.976 3.09608C11.9459 3.289 12.8368 3.76521 13.536 4.46447C14.2353 5.16373 14.7115 6.05465 14.9044 7.02455C15.0974 7.99446 14.9983 8.99979 14.6199 9.91342C14.2415 10.827 13.6006 11.6079 12.7784 12.1573C11.9561 12.7068 10.9894 13 10.0005 13H4.5005C4.00415 12.9995 3.51358 12.8935 3.06135 12.6889C2.60911 12.4843 2.20557 12.1859 1.87749 11.8134C1.54941 11.441 1.30431 11.003 1.15845 10.5285C1.01258 10.0541 0.9693 9.55407 1.03147 9.06163C1.09364 8.56919 1.25983 8.0956 1.51903 7.6723C1.77823 7.249 2.12449 6.88567 2.53484 6.60643C2.94519 6.32718 3.41025 6.13842 3.89913 6.05265C4.38802 5.96688 4.88956 5.98608 5.37045 6.10897" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M10.8784 3.58647C10.0055 3.41284 9.10069 3.50195 8.27843 3.84254C7.45616 4.18314 6.75335 4.75992 6.25889 5.49994C5.76442 6.23996 5.5005 7.10999 5.5005 8C5.5005 8.27614 5.27664 8.5 5.0005 8.5C4.72436 8.5 4.5005 8.27614 4.5005 8C4.5005 7.49243 4.57073 6.99017 4.70705 6.50689C4.46654 6.49057 4.22428 6.50325 3.98553 6.54513C3.56648 6.61864 3.16787 6.78044 2.81614 7.01979C2.46441 7.25915 2.16761 7.57057 1.94544 7.9334C1.72327 8.29623 1.58082 8.70216 1.52753 9.12425C1.47424 9.54635 1.51134 9.97495 1.63637 10.3816C1.76139 10.7883 1.97148 11.1637 2.25269 11.4829C2.5339 11.8022 2.8798 12.058 3.26743 12.2333C3.65505 12.4087 4.07554 12.4996 4.50099 12.5H10.0005C10.8905 12.5 11.7605 12.2361 12.5006 11.7416C13.2406 11.2471 13.8174 10.5443 14.158 9.72208C14.4986 8.89981 14.5877 7.99501 14.414 7.1221C14.2404 6.24918 13.8118 5.44736 13.1825 4.81802C12.5531 4.18869 11.7513 3.7601 10.8784 3.58647ZM5.08043 5.54177C4.66046 5.4806 4.23252 5.48653 3.81274 5.56017C3.25401 5.65819 2.72252 5.87392 2.25355 6.19306C1.78457 6.51219 1.38884 6.92743 1.09262 7.4112C0.796395 7.89497 0.606455 8.43621 0.535406 8.999C0.464357 9.5618 0.513823 10.1333 0.680523 10.6755C0.847222 11.2177 1.12734 11.7182 1.50229 12.1439C1.87723 12.5696 2.33843 12.9106 2.85527 13.1444C3.3721 13.3783 3.93276 13.4994 4.50002 13.5H10.0005C11.0883 13.5 12.1517 13.1774 13.0561 12.5731C13.9606 11.9687 14.6656 11.1098 15.0818 10.1048C15.4981 9.09977 15.607 7.9939 15.3948 6.92701C15.1826 5.86011 14.6588 4.8801 13.8896 4.11092C13.1204 3.34173 12.1404 2.8179 11.0735 2.60568C10.0066 2.39346 8.90074 2.50238 7.89574 2.91867C6.89075 3.33495 6.03177 4.0399 5.42742 4.94437C5.29888 5.13674 5.18308 5.33631 5.08043 5.54177Z" fill="${color}"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M12.3536 6.89645C12.5488 7.09171 12.5488 7.40829 12.3536 7.60355L9.35355 10.6036C9.15829 10.7988 8.84171 10.7988 8.64645 10.6036L7.14645 9.10355C6.95118 8.90829 6.95118 8.59171 7.14645 8.39645C7.34171 8.20118 7.65829 8.20118 7.85355 8.39645L9 9.54289L11.6464 6.89645C11.8417 6.70118 12.1583 6.70118 12.3536 6.89645Z" fill="${color}"/>
</svg>
`;

export const mediumIcon = (color = 'white'): string =>
`<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M23 0.294922H1C0.734784 0.294922 0.48043 0.400279 0.292893 0.587815C0.105357 0.775351 0 1.02971 0 1.29492L0 23.2949C0 23.5601 0.105357 23.8145 0.292893 24.002C0.48043 24.1896 0.734784 24.2949 1 24.2949H23C23.2652 24.2949 23.5196 24.1896 23.7071 24.002C23.8946 23.8145 24 23.5601 24 23.2949V1.29492C24 1.02971 23.8946 0.775351 23.7071 0.587815C23.5196 0.400279 23.2652 0.294922 23 0.294922V0.294922ZM19.938 5.98092L18.651 7.21492C18.5966 7.25639 18.5545 7.31192 18.5293 7.37553C18.5041 7.43915 18.4967 7.50843 18.508 7.57592V16.6439C18.4967 16.7114 18.5041 16.7807 18.5293 16.8443C18.5545 16.9079 18.5966 16.9635 18.651 17.0049L19.908 18.2389V18.5099H13.586V18.2389L14.886 16.9749C15.014 16.8469 15.014 16.8089 15.014 16.6139V9.28492L11.393 18.4849H10.904L6.691 9.28492V15.4479C6.67366 15.5757 6.68562 15.7058 6.72599 15.8283C6.76636 15.9508 6.83407 16.0625 6.924 16.1549L8.618 18.2089V18.4799H3.818V18.2089L5.509 16.1549C5.5982 16.0624 5.6644 15.9502 5.70227 15.8274C5.74014 15.7046 5.74861 15.5746 5.727 15.4479V8.32192C5.73727 8.22455 5.72452 8.12613 5.68978 8.0346C5.65504 7.94306 5.59929 7.86096 5.527 7.79492L4.019 5.98092V5.70992H8.693L12.306 13.6339L15.482 5.70992H19.938V5.98092Z" fill="${color}"/></svg>`;

Expand Down
3 changes: 3 additions & 0 deletions src/navigation/settings/SettingsNavigator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import LightningNavigator, {
} from '../lightning/LightningNavigator';
import WebRelay from '../../screens/Settings/WebRelay';
import { __E2E__ } from '../../constants/env';
import AppStatus from '../../screens/Settings/AppStatus';

export type SettingsNavigationProp =
StackNavigationProp<SettingsStackParamList>;
Expand All @@ -73,6 +74,7 @@ export type SettingsStackParamList = {
AdvancedSettings: undefined;
AboutSettings: undefined;
SupportSettings: undefined;
AppStatus: undefined;
ReportIssue: undefined;
FormSuccess: undefined;
FormError: undefined;
Expand Down Expand Up @@ -131,6 +133,7 @@ const SettingsNavigator = (): ReactElement => {
<Stack.Screen name="AdvancedSettings" component={AdvancedSettings} />
<Stack.Screen name="AboutSettings" component={AboutSettings} />
<Stack.Screen name="SupportSettings" component={SupportSettings} />
<Stack.Screen name="AppStatus" component={AppStatus} />
<Stack.Screen name="ReportIssue" component={ReportIssue} />
<Stack.Screen name="FormSuccess" component={FormSuccess} />
<Stack.Screen name="FormError" component={FormError} />
Expand Down
251 changes: 251 additions & 0 deletions src/screens/Settings/AppStatus/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { SettingsScreenProps } from '../../../navigation/types';
import React, { memo, ReactElement, useEffect, useMemo, useState } from 'react';
import { ScrollView, View as ThemedView } from '../../../styles/components';
import SettingsView from '../SettingsView';
import { Caption13M, Text01M } from '../../../styles/text';
import { StyleSheet, View } from 'react-native';
import { useTranslation } from 'react-i18next';
import {
BitcoinSlantedIcon,
BroadcastIcon,
CloudCheckIcon,
GlobeSimpleIcon,
LightningHollow,
} from '../../../styles/icons';
import { IColors } from '../../../styles/colors';
import { useAppSelector } from '../../../hooks/redux';
import {
isConnectedToElectrumSelector,
isLDKReadySelector,
isOnlineSelector,
} from '../../../store/reselect/ui';
import {
openChannelsSelector,
pendingChannelsSelector,
} from '../../../store/reselect/lightning';
import { blocktankPaidOrdersFullSelector } from '../../../store/reselect/blocktank';
import { backupSelector } from '../../../store/reselect/backup';
import { i18nTime } from '../../../utils/i18n';
import { FAILED_BACKUP_CHECK_TIME } from '../../../utils/backup/backups-subscriber';

type TStatusItem =
| 'internet'
| 'bitcoin_node'
| 'lightning_node'
| 'lightning_connection'
| 'full_backup';

type TItemState = 'ready' | 'pending' | 'error';

interface IStatusItemProps {
Icon: React.FunctionComponent<any>;
item: TStatusItem;
state: TItemState;
subtitle?: string;
}

const Status = ({
Icon,
item,
state,
subtitle,
}: IStatusItemProps): ReactElement => {
const { t } = useTranslation('settings');
const { bg, fg }: { fg: keyof IColors; bg: keyof IColors } = useMemo(() => {
switch (state) {
case 'ready':
return { bg: 'green16', fg: 'green' };
case 'pending':
return { bg: 'yellow16', fg: 'yellow' };
case 'error':
return { bg: 'red16', fg: 'red' };
}
}, [state]);

subtitle = subtitle || t(`status.${item}.${state}`);

return (
<View style={styles.status} testID={`Status-${item}`}>
<View style={styles.iconContainer}>
<ThemedView color={bg} style={styles.icon}>
<Icon width={16} height={16} color={fg} />
</ThemedView>
</View>
<View style={styles.desc}>
<Text01M>{t(`status.${item}.title`)}</Text01M>
<Caption13M color="gray1">{subtitle}</Caption13M>
</View>
</View>
);
};

const AppStatus = ({}: SettingsScreenProps<'AppStatus'>): ReactElement => {
const { t } = useTranslation('settings');
const { t: tTime } = useTranslation('intl', { i18n: i18nTime });
const isOnline = useAppSelector(isOnlineSelector);
const isConnectedToElectrum = useAppSelector(isConnectedToElectrumSelector);
const isLDKReady = useAppSelector(isLDKReadySelector);
const openChannels = useAppSelector(openChannelsSelector);
const pendingChannels = useAppSelector(pendingChannelsSelector);
const paidOrders = useAppSelector(blocktankPaidOrdersFullSelector);
const backup = useAppSelector(backupSelector);
const [now, setNow] = useState<number>(new Date().getTime());

const internetState: TItemState = useMemo(() => {
return isOnline ? 'ready' : 'error';
}, [isOnline]);

const bitcoinNodeState: TItemState = useMemo(() => {
if (isOnline && !isConnectedToElectrum) {
return 'pending';
}
return isConnectedToElectrum ? 'ready' : 'error';
}, [isConnectedToElectrum, isOnline]);

const lightningNodeState: TItemState = useMemo(() => {
return isLDKReady ? 'ready' : 'error';
}, [isLDKReady]);

const lightningConnectionState: TItemState = useMemo(() => {
if (openChannels.length > 0) {
return 'ready';
} else if (
pendingChannels.length > 0 ||
Object.keys(paidOrders.created).length > 0
) {
return 'pending';
}
return 'error';
}, [openChannels, pendingChannels, paidOrders]);

// Keep checking backup status
useEffect(() => {
const timer = setInterval(() => {
setNow(new Date().getTime());
}, FAILED_BACKUP_CHECK_TIME);

return (): void => clearInterval(timer);
}, []);

const isBackupSyncOk = useMemo(() => {
const isSyncOk = (key: number | undefined): boolean => {
// undefined = no sync required = ok
return key ? now - key < FAILED_BACKUP_CHECK_TIME : true;
};

return (
isSyncOk(backup.remoteLdkBackupLastSyncRequired) &&
isSyncOk(backup.remoteLdkActivityBackupSyncRequired) &&
isSyncOk(backup.remoteBlocktankBackupSyncRequired) &&
isSyncOk(backup.remoteSettingsBackupSyncRequired) &&
isSyncOk(backup.remoteMetadataBackupSyncRequired) &&
isSyncOk(backup.remoteWidgetsBackupSyncRequired)
);
}, [backup, now]);

const fullBackupState: { state: TItemState; subtitle?: string } =
useMemo(() => {
if (!isBackupSyncOk) {
return { state: 'error' };
}
const syncTimes = [
backup.remoteLdkBackupLastSync,
backup.remoteLdkActivityBackupLastSync,
backup.remoteBlocktankBackupLastSync,
backup.remoteSettingsBackupLastSync,
backup.remoteMetadataBackupLastSync,
backup.remoteWidgetsBackupLastSync,
].filter((i) => i !== undefined) as Array<number>;
const max = Math.max(...syncTimes);
let subtitle = tTime('dateTime', {
v: new Date(max),
formatParams: {
v: {
year: 'numeric',
month: 'long',
day: 'numeric',
hour: 'numeric',
minute: 'numeric',
},
},
});
return { state: 'ready', subtitle };
}, [tTime, backup, isBackupSyncOk]);

const items: IStatusItemProps[] = [
{
Icon: GlobeSimpleIcon,
item: 'internet',
state: internetState,
},
{
Icon: BitcoinSlantedIcon,
item: 'bitcoin_node',
state: bitcoinNodeState,
},
{
Icon: BroadcastIcon,
item: 'lightning_node',
state: lightningNodeState,
},
{
Icon: LightningHollow,
item: 'lightning_connection',
state: lightningConnectionState,
},
{
Icon: CloudCheckIcon,
item: 'full_backup',
state: fullBackupState.state,
subtitle: fullBackupState.subtitle,
},
];

return (
<ThemedView style={styles.container}>
<SettingsView
title={t('status.title')}
fullHeight={true}
showBackNavigation={true}>
<ScrollView style={styles.statusRoot}>
{items.map((it) => (
<Status key={it.item} {...it} />
))}
</ScrollView>
</SettingsView>
</ThemedView>
);
};

const styles = StyleSheet.create({
container: {
flex: 1,
},
statusRoot: {
flex: 1,
},
status: {
marginHorizontal: 16,
borderBottomWidth: 1,
borderBottomColor: 'rgba(255, 255, 255, 0.1)',
height: 56,
flexDirection: 'row',
alignItems: 'center',
},
iconContainer: {
marginRight: 16,
alignItems: 'center',
},
icon: {
alignItems: 'center',
justifyContent: 'center',
borderRadius: 16,
width: 32,
height: 32,
},
desc: {
flex: 1,
},
});

export default memo(AppStatus);
Loading

0 comments on commit 3f33a5c

Please sign in to comment.