Skip to content

Commit

Permalink
feat(Realm): Move app onboarded and initialized (#2204)
Browse files Browse the repository at this point in the history
* feat(HW-941): Remove restore screen

* feat(HW-941): Update sss routing rules

* feat(HW-941): Remove SSS from settings

* feat(HW-941): Remove replace option from SSS migration

* feat(HW-941): Translation fix

* Change sss screen parameters

* Remove unnecessary useCallback

* FIx provider for sss

* Remove errors

* Fix wallet type

* Fix types

* feat: Move app onboarded and initialized logic into AppStore

- Remove Events.onOnbardedChanged event
- Remove initialized state from app.tsx

* Remove unnecessary storage definition

* Update observers

* Migrtation

* Restore onboarding from Realm into AppStore

* fix: Cart Wallet styles (#2207)

* fix: wallet card name (#2209)

* fix(SSS): google iOS login (#2208)

* fix(HW-961): sss sentry handling (#2210)

* Remove contact migration

* Sentry handling for sss issues

* fix(HW-965): no wallets on import iardware wallet (#2211)

* feat(HW-967): watch only wallet (#2212)

* fix: wallet bages (#2214)

* fix(SocketStore): improve socket error handling (#2213)

* fix(HW-963): Update wallet model after sss removal (#2215)

* build

* fix: Deep check for address list to prevent infinity transactions fetches (#2218)

* chore: Hide remove sss button (#2219)

* chore: Hide remove sss button

* chore: isFeature enabled

* fix: sss errors (#2217)

* feat(HW-966): immediatly re-create SSS cloud share (#2220)

* feat(HW-966): immediatly re-create SSS cloud share

* feat(HW-966): sss recovery error handling

* build

* update: version

* build

* Restore storage for Provider and ProviderConfig (#2221)

* feat: Update onboarded variable migration

* Update logs

* Change MMKV configuration

* Restore storage

* app.store storage

* build

* Revert "update: version"

This reverts commit a3567cf.

* build

* chore: Setup provider cache to 3 hours (#2227)

* update: version

* fix: tron fee (#2230)

* fix: tron fee

* fix: tron fee calculation

* build

---------

Co-authored-by: Kirill Ageychenko <[email protected]>
Co-authored-by: Build <[email protected]>
Co-authored-by: Kirill Ageychenko <[email protected]>
  • Loading branch information
4 people committed Dec 5, 2024
1 parent e688da2 commit 03c1795
Show file tree
Hide file tree
Showing 44 changed files with 217 additions and 158 deletions.
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import {App} from './src/app';
import './src/event-actions';
import {Jailbreak} from './src/jailbreak';
import {Language} from '@app/models/language';
import {configurePersistable} from 'mobx-persist-store';
import {storage} from '@app/services/mmkv';

configurePersistable({storage});

LogBox.ignoreAllLogs();
if (!global.BigInt) {
Expand Down
47 changes: 11 additions & 36 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ import {
Theme,
} from '@react-navigation/native';
import * as Sentry from '@sentry/react-native';
import {observer} from 'mobx-react';
import PostHog, {PostHogProvider} from 'posthog-react-native';
import {
AppState,
Dimensions,
InteractionManager,
Linking,
StyleSheet,
} from 'react-native';
import {AppState, Dimensions, Linking, StyleSheet} from 'react-native';
import {GestureHandlerRootView} from 'react-native-gesture-handler';
import {MenuProvider} from 'react-native-popup-menu';
import {Metrics, SafeAreaProvider} from 'react-native-safe-area-context';
Expand Down Expand Up @@ -47,6 +42,7 @@ import {sleep} from '@app/utils';
import {SPLASH_TIMEOUT_MS} from '@app/variables/common';

import {AppVersionAbsoluteView} from './components/app-version-absolute-view';
import {AppStore} from './models/app';
import {migrationWallets} from './models/migration-wallets';
import {EventTracker} from './services/event-tracker';

Expand Down Expand Up @@ -81,11 +77,9 @@ const SAFE_AREA_INTIAL_METRICS: Metrics = {
},
};

export const App = () => {
const [initialized, setInitialized] = useState(false);
export const App = observer(() => {
const [isPinReseted, setPinReseted] = useState(false);
const [posthog, setPosthog] = useState<PostHog | null>(null);
const [onboarded, setOnboarded] = useState(app.onboarded);
const theme = useTheme();
const toast = useToast();

Expand All @@ -100,20 +94,6 @@ export const App = () => {
[theme],
);

useEffect(() => {
const sub = (value: boolean) => {
InteractionManager.setDeadline(1000);
InteractionManager.runAfterInteractions(() => {
setOnboarded(value);
});
};

app.addListener(Events.onOnboardedChanged, sub);
return () => {
app.removeListener(Events.onOnboardedChanged, sub);
};
}, []);

useEffect(() => {
const splashTimer = setTimeout(() => {
hideModal(ModalType.splash);
Expand All @@ -125,7 +105,7 @@ export const App = () => {
.then(async () => await Language.init())
.then(async () => {
await Stories.fetch(true);
if (app.onboarded) {
if (AppStore.isOnboarded) {
await app.init();
await migrationWallets();

Expand All @@ -135,7 +115,6 @@ export const App = () => {
}
})
.then(() => {
setOnboarded(app.onboarded);
awaitForEventDone(Events.onAppLoggedId);
})
.then(() => {
Expand All @@ -147,7 +126,7 @@ export const App = () => {
})
.finally(async () => {
await awaitForEventDone(Events.onAppStarted);
setInitialized(true);
AppStore.isInitialized = true;
hideModal(ModalType.splash);
});

Expand All @@ -157,7 +136,7 @@ export const App = () => {
}, []);

useEffect(() => {
if (initialized) {
if (AppStore.isInitialized) {
const subscription = ({isConnected}: NetInfoState) => {
isConnected
? hideModal(ModalType.noInternet)
Expand Down Expand Up @@ -189,7 +168,7 @@ export const App = () => {
unsubscribeLinking.remove();
};
}
}, [initialized]);
}, [AppStore.isInitialized]);

useEffect(() => {
EventTracker.instance.initialize();
Expand Down Expand Up @@ -242,16 +221,12 @@ export const App = () => {
captureLifecycleEvents: true,
captureScreens: true,
navigation: {
routeToProperties: (name, params) => {
routeToProperties: (_, params) => {
return params;
},
},
}}>
<RootStack
onboarded={onboarded}
isPinReseted={isPinReseted}
isReady={initialized}
/>
<RootStack isPinReseted={isPinReseted} />
<AppScreenSecurityOverview />
{toast}
<AppVersionAbsoluteView />
Expand All @@ -263,7 +238,7 @@ export const App = () => {
<SocketHandler />
</GestureHandlerRootView>
);
};
});

const styles = StyleSheet.create({
rootView: {
Expand Down
4 changes: 2 additions & 2 deletions src/components/signin-networks/signin-networks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import {
TextVariant,
} from '@app/components/ui';
import {HardwareWalletButton} from '@app/components/ui/hardware-wallet-button';
import {app} from '@app/contexts';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {AppStore} from '@app/models/app';
import {Wallet} from '@app/models/wallet';
import {SssProviders} from '@app/services/provider-sss';
import {WalletType} from '@app/types';
Expand Down Expand Up @@ -86,7 +86,7 @@ export const SigninNetworks = observer(
wallet => wallet.type === WalletType.sss,
).length;

const isSSSDisabled = app.onboarded
const isSSSDisabled = AppStore.isOnboarded
? mnemonicWalletsCount >= 1 || sssWalletsCount >= 1
: false;

Expand Down
12 changes: 2 additions & 10 deletions src/contexts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {getRpcProvider} from '@app/helpers/get-rpc-provider';
import {getUid} from '@app/helpers/get-uid';
import {SecurePinUtils} from '@app/helpers/secure-pin-utils';
import {I18N, getText} from '@app/i18n';
import {AppStore} from '@app/models/app';
import {Currencies} from '@app/models/currencies';
import {Provider, RemoteProviderConfig} from '@app/models/provider';
import {VariablesBool} from '@app/models/variables-bool';
Expand Down Expand Up @@ -222,15 +223,6 @@ class App extends AsyncEventEmitter {
VariablesBool.set('bluetooth', value);
}

get onboarded() {
return VariablesBool.get('onboarded') || false;
}

set onboarded(value) {
this.emit(Events.onOnboardedChanged, value);
VariablesBool.set('onboarded', value);
}

get hasNotifications() {
return this.notifications && this.notificationToken !== '';
}
Expand Down Expand Up @@ -360,7 +352,7 @@ class App extends AsyncEventEmitter {
}

async init(): Promise<void> {
if (!this.onboarded) {
if (!AppStore.isOnboarded) {
return Promise.resolve();
}

Expand Down
3 changes: 2 additions & 1 deletion src/event-actions/on-app-logged-in.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {app} from '@app/contexts';
import {Events} from '@app/events';
import {prefetchBrowserLinkIcons} from '@app/helpers/prefetch-browser-link-icons';
import {prefetchWalletCardImages} from '@app/helpers/prefetch-wallet-card-images';
import {AppStore} from '@app/models/app';
import {WalletConnect} from '@app/services/wallet-connect';

/**
Expand All @@ -11,7 +12,7 @@ export async function onAppLoggedIn() {
prefetchWalletCardImages();
prefetchBrowserLinkIcons();

if (app.onboarded) {
if (AppStore.isOnboarded) {
app.emit(Events.onBlockRequestCheck);
WalletConnect.instance.init();
}
Expand Down
3 changes: 2 additions & 1 deletion src/event-actions/on-app-reset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import RNRestart from 'react-native-restart';

import {app} from '@app/contexts';
import {cleanGoogle} from '@app/helpers/get-google-tokens';
import {AppStore} from '@app/models/app';
import {Contact} from '@app/models/contact';
import {Transaction} from '@app/models/transaction';
import {VariablesString} from '@app/models/variables-string';
Expand Down Expand Up @@ -51,7 +52,7 @@ export async function onAppReset() {
} catch (err) {
Logger.captureException(err, 'onAppReset');
} finally {
app.onboarded = false;
AppStore.isOnboarded = false;
RNRestart.restart();
}
}
4 changes: 2 additions & 2 deletions src/event-actions/on-banner-notifications-turn-on.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {app} from '@app/contexts';
import {onPushSubscriptionTransactionsSubscribe} from '@app/event-actions/on-push-subscription-transactions-subscribe';
import {AppStore} from '@app/models/app';
import {Banner} from '@app/models/banner';
import {navigator} from '@app/navigator';
import {
Expand All @@ -22,7 +22,7 @@ export async function onBannerNotificationsTurnOn(
'notificationTopic:news',
PushNotificationTopicsEnum.news,
);
} else if (app.onboarded) {
} else if (AppStore.isOnboarded) {
navigator.navigate('settingsNotification');
}

Expand Down
6 changes: 3 additions & 3 deletions src/event-actions/on-wallet-remove.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {app} from '@app/contexts';
import {Events} from '@app/events';
import {AppStore} from '@app/models/app';
import {VariablesString} from '@app/models/variables-string';
import {Wallet} from '@app/models/wallet';
import {Web3BrowserSession} from '@app/models/web3-browser-session';
Expand All @@ -11,15 +11,15 @@ import {onWalletReset} from './on-wallet-reset';

export async function onWalletRemove(address: string) {
try {
if (!app.onboarded) {
if (!AppStore.isOnboarded) {
return;
}
WalletConnect.instance.onWalletRemove(address);
const wallets = Wallet.addressList();

// last wallet removed
if (wallets.length === 0) {
app.onboarded = false;
AppStore.isOnboarded = false;
await onAppReset();
await onWalletReset();
}
Expand Down
1 change: 0 additions & 1 deletion src/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export enum Events {
onAppReviewRequest = 'onAppReviewRequest',
openInAppBrowserPageLoaded = 'openInAppBrowserPageLoaded',
enterPinSuccess = 'enterPinSuccess',
onOnboardedChanged = 'onOnboardedChanged',
onVestingBalanceSync = 'onVestingBalanceSync',
onStakingBalanceSync = 'onStakingBalanceSync',
onWalletsVestingBalanceCheck = 'onWalletsVestingBalanceCheck',
Expand Down
31 changes: 31 additions & 0 deletions src/models/app/app.store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import {makeAutoObservable} from 'mobx';
import {isHydrated, makePersistable} from 'mobx-persist-store';

import {storage} from '@app/services/mmkv';

class AppStore {
// App session properties
private _isInitialized = false;

// Hydrated properties
isOnboarded = false;

constructor() {
makeAutoObservable(this);
makePersistable(this, {
name: this.constructor.name,
properties: ['isOnboarded'],
storage,
});
}

get isInitialized() {
return isHydrated(this) && this._isInitialized;
}
set isInitialized(value: boolean) {
this._isInitialized = value;
}
}

const instance = new AppStore();
export {instance as AppStore};
1 change: 1 addition & 0 deletions src/models/app/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './app.store';
2 changes: 2 additions & 0 deletions src/models/banner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {makeAutoObservable} from 'mobx';
import {makePersistable} from 'mobx-persist-store';

import {Color} from '@app/colors';
import {storage} from '@app/services/mmkv';

import UUID = Realm.BSON.UUID;

Expand Down Expand Up @@ -68,6 +69,7 @@ class BannerStore {
makePersistable(this, {
name: this.constructor.name,
properties: ['banners'],
storage,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/models/browser-permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {Alert} from 'react-native';

import {app} from '@app/contexts';
import {I18N, getText} from '@app/i18n';
import {storage} from '@app/services/mmkv';
import {
BrowserPermissionItem,
BrowserPermissionStatus,
Expand All @@ -30,6 +31,7 @@ class BrowserPermissionStore {
name: this.constructor.name,
// @ts-ignore
properties: ['_data'],
storage,
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/models/contact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {makeAutoObservable} from 'mobx';
import {isHydrated, makePersistable} from 'mobx-persist-store';

import {storage} from '@app/services/mmkv';

export enum ContactType {
address = 'address',
contract = 'contract',
Expand All @@ -22,6 +24,7 @@ class ContactStore {
makePersistable(this, {
name: this.constructor.name,
properties: ['contacts'],
storage,
});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/models/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {Wallet} from '@app/models/wallet';
import {Backend} from '@app/services/backend';
import {Balance} from '@app/services/balance';
import {Indexer} from '@app/services/indexer';
import {storage} from '@app/services/mmkv';
import {RemoteConfig} from '@app/services/remote-config';
import {ChainId, RatesResponse} from '@app/types';
import {createAsyncTask} from '@app/utils';
Expand All @@ -32,6 +33,7 @@ class CurrenciesStore {
name: this.constructor.name,
//@ts-ignore
properties: ['_currencies', '_selectedCurrency'],
storage,
}).finally(() => runInAction(() => (this._isInited = true)));
} else {
runInAction(() => (this._isInited = true));
Expand Down
Loading

0 comments on commit 03c1795

Please sign in to comment.