Skip to content

Commit

Permalink
Merge pull request #3489 from pillarwallet/develop #minor
Browse files Browse the repository at this point in the history
Release Candidate 3.30.0
  • Loading branch information
IAmKio committed Apr 4, 2024
2 parents e21c9ed + f91e453 commit 54c0daf
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 32 deletions.
2 changes: 1 addition & 1 deletion android/Gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source "https://rubygems.org"
gem 'rake'
gem 'fastlane', :git => 'https://github.com/fastlane/fastlane.git', :tag => '2.135.1'
gem 'fastlane', :git => 'https://github.com/fastlane/fastlane.git', :tag => '2.220.0'
gem 'fastlane-plugin-get_version_name'
gem 'fastlane-plugin-property_file_read'
gem 'fastlane-plugin-appcenter'
Expand Down
24 changes: 24 additions & 0 deletions ios/pillarwallet/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,34 @@
#import "RCTLinkingManager.h"
#import "RNNotifications.h"

static void ClearKeychainIfNecessary() {
// Checks wether or not this is the first time the app is run
if ([[NSUserDefaults standardUserDefaults] boolForKey:@"HAS_RUN_BEFORE"] == NO) {
// Set the appropriate value so we don't clear next time the app is launched
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"HAS_RUN_BEFORE"];

NSArray *secItemClasses = @[
(__bridge id)kSecClassGenericPassword,
(__bridge id)kSecClassInternetPassword,
(__bridge id)kSecClassCertificate,
(__bridge id)kSecClassKey,
(__bridge id)kSecClassIdentity
];

// Maps through all Keychain classes and deletes all items that match
for (id secItemClass in secItemClasses) {
NSDictionary *spec = @{(__bridge id)kSecClass: secItemClass};
SecItemDelete((__bridge CFDictionaryRef)spec);
}
}
}

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
ClearKeychainIfNecessary();

[RNNotifications startMonitorNotifications];
if ([FIRApp defaultApp] == nil) {
[FIRApp configure];
Expand Down
58 changes: 30 additions & 28 deletions src/actions/appActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import Storage from 'services/storage';
import { navigate } from 'services/navigation';
import { migrate } from 'services/dataMigration';
import { firebaseCrashlytics } from 'services/firebase';
import { getCurrentTime } from 'services/ntpSync';

// constants
import { IS_APP_VERSION_V3 } from 'constants/appConstants';
Expand All @@ -42,7 +41,7 @@ import {
SET_DEFAULT_LIST,
} from 'constants/assetsConstants';
import { SET_ASSETS_BALANCES } from 'constants/assetsBalancesConstants';
import { UPDATE_PIN_ATTEMPTS, TODAY_FAILED_ATTEMPTS, UPDATE_WALLET_BACKUP_STATUS } from 'constants/walletConstants';
import { UPDATE_WALLET_BACKUP_STATUS } from 'constants/walletConstants';
import { UPDATE_TX_COUNT } from 'constants/txCountConstants';
import { SET_COLLECTIBLES, SET_COLLECTIBLES_TRANSACTION_HISTORY } from 'constants/collectiblesConstants';
import { SET_RATES } from 'constants/ratesConstants';
Expand Down Expand Up @@ -96,14 +95,17 @@ export const initAppAndRedirectAction = () => {
dispatch({ type: RESET_APP_LOADED });

let storageData = await storage.getAll();
const { wallet: encryptedWallet } = await encryptedStorage.get('wallet');
await storage.migrateFromPouchDB(storageData);

// Note: only wallet data migrate local stroage to encrypted storage
await encryptedStorage.migrateFromLocalStorage(storageData);

await dispatch(fetchOfflineLocalAssets());

storageData = await migrate('app_settings', storageData, dispatch, getState, 'appSettings');
const { appSettings = {} } = get(storageData, 'app_settings', {});

const { wallet: encryptedWallet } = await encryptedStorage.get('wallet');
// $FlowFixMe
const { wallet, walletTimestamp } = await getWalletFromStorage(storageData, encryptedWallet, dispatch);

Expand Down Expand Up @@ -190,29 +192,29 @@ export const initAppAndRedirectAction = () => {
const user = storageData?.user?.user ?? {};
dispatch({ type: SET_USER, payload: user });

const currentTime = await getCurrentTime();

const { failedAttempts = {}, pinAttempt = {} } = get(storageData, 'pinAttempt', {});
const { numberOfFailedAttempts = 0, date = new Date() } = failedAttempts;
const { pinAttemptsCount = 0 } = pinAttempt;

if (new Date(date)?.toDateString() === currentTime?.toDateString()) {
dispatch({
type: UPDATE_PIN_ATTEMPTS,
payload: {
pinAttemptsCount,
},
});
dispatch({
type: TODAY_FAILED_ATTEMPTS,
payload: {
failedAttempts: {
numberOfFailedAttempts,
date: new Date(date),
},
},
});
}
// const currentTime = await getCurrentTime();

// const { failedAttempts = {}, pinAttempt = {} } = get(storageData, 'pinAttempt', {});
// const { numberOfFailedAttempts = 0, date = new Date() } = failedAttempts;
// const { pinAttemptsCount = 0 } = pinAttempt;

// if (new Date(date)?.toDateString() === currentTime?.toDateString()) {
// dispatch({
// type: UPDATE_PIN_ATTEMPTS,
// payload: {
// pinAttemptsCount,
// },
// });
// dispatch({
// type: TODAY_FAILED_ATTEMPTS,
// payload: {
// failedAttempts: {
// numberOfFailedAttempts,
// date: new Date(date),
// },
// },
// });
// }

const {
upgradeStatus = null,
Expand All @@ -230,7 +232,7 @@ export const initAppAndRedirectAction = () => {
const { ensRegistry = {} } = get(storageData, 'ensRegistry', {});
dispatch({ type: SET_ENS_REGISTRY_RECORDS, payload: ensRegistry });

if (wallet.backupStatus) dispatch({ type: UPDATE_WALLET_BACKUP_STATUS, payload: wallet.backupStatus });
if (wallet?.backupStatus) dispatch({ type: UPDATE_WALLET_BACKUP_STATUS, payload: wallet.backupStatus });

if (!wallet?.pinV2 && !appSettings?.data?.hasSixDigitsPin) {
dispatch({ type: UPDATE_APP_SETTINGS, payload: { hasSixDigitsPin: true } });
Expand All @@ -242,7 +244,7 @@ export const initAppAndRedirectAction = () => {

dispatch({ type: UPDATE_APP_SETTINGS, payload: appSettings });
let navAction;
if (walletTimestamp) {
if (walletTimestamp && wallet) {
const appearanceVisible = get(storageData, 'appearance_visible');
navAction = {
name: AUTH_FLOW,
Expand Down
26 changes: 25 additions & 1 deletion src/services/encryptedStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,16 @@
*/
// eslint-disable-next-line import/no-extraneous-dependencies
import RNEncryptedStorage from 'react-native-encrypted-storage';
import get from 'lodash.get';
import merge from 'lodash.merge';
import { reportErrorLog, logBreadcrumb } from 'utils/common';
import { isEmpty } from 'lodash';

import { printLog, reportErrorLog, logBreadcrumb } from 'utils/common';

// Local
import Storage from './storage';

const storage = Storage.getInstance('db');

function EncryptedStorage(name: string) {
this.name = name;
Expand Down Expand Up @@ -70,6 +78,22 @@ EncryptedStorage.prototype.save = async function (id: string, data: Object, forc
return null;
};

EncryptedStorage.prototype.migrateFromLocalStorage = async function (storageData: Object) {
const { wallet = {} } = get(storageData, 'wallet', {});
if (isEmpty(wallet)) return Promise.resolve();

try {
printLog('Encrypted Storage migrating data');
// eslint-disable-next-line i18next/no-literal-string
await this.save('wallet', { wallet });
// eslint-disable-next-line i18next/no-literal-string
await storage.remove('wallet');
} catch (e) {
reportErrorLog('AsyncStorage migration to Encrypted Storage failed', { error: e });
}
return Promise.resolve();
};

EncryptedStorage.prototype.removeAll = async function () {
try {
await RNEncryptedStorage.clear();
Expand Down
8 changes: 6 additions & 2 deletions src/services/ntpSync.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@ const options = {
syncDelay: 10,
history: 15,
};
export const ntp = new ntpSync(options);
const ntp = new ntpSync(options);

let status;

export const getCurrentTime = async () => {
try {
const status = await ntp.syncTime();
if (!status) {
status = await ntp.syncTime();
}

if (status) {
const currentTime = ntp.getTime();
Expand Down
4 changes: 4 additions & 0 deletions src/services/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ Storage.prototype.removeAll = async function () {
return AsyncStorage.multiRemove(keys);
};

Storage.prototype.remove = async function (id: string) {
return AsyncStorage.removeItem(this.getKey(id));
};

Storage.prototype.migrateFromPouchDB = async function (storageData: Object) {
const { storageSettings = {} } = get(storageData, STORAGE_SETTINGS_KEY, {});
if (storageSettings.pouchDBMigrated) return Promise.resolve();
Expand Down

0 comments on commit 54c0daf

Please sign in to comment.