Skip to content

Commit

Permalink
Merge branch 'dev' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidHaji-zada committed Nov 2, 2023
2 parents 5a6c72c + d8f7ba6 commit a128125
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 48 deletions.
13 changes: 13 additions & 0 deletions patches/react-native-popover-view+5.1.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/react-native-popover-view/dist/Utility.js b/node_modules/react-native-popover-view/dist/Utility.js
index 35c6c1d..c51c62c 100644
--- a/node_modules/react-native-popover-view/dist/Utility.js
+++ b/node_modules/react-native-popover-view/dist/Utility.js
@@ -40,7 +40,7 @@ import { DEFAULT_ARROW_SIZE, DEFAULT_BORDER_RADIUS } from './Constants';
export function getRectForRef(ref) {
return new Promise(function (resolve, reject) {
if (ref.current) {
- NativeModules.UIManager.measure(findNodeHandle(ref.current), function (_1, _2, width, height, x, y) {
+ ref.current.measureInWindow(function (x, y, width, height) {
return resolve(new Rect(x, y, width, height));
});
}
9 changes: 3 additions & 6 deletions src/components/composite/PopUpInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,23 @@
import React from 'react';
import { StatusBar, View } from 'react-native';
import { View } from 'react-native';
import Popover, { PopoverPlacement } from 'react-native-popover-view';
import { Button, Spacer, Text } from '@components/base';
import { PopUpInfoProps } from './PopUpInfo.types';
import { styles } from './styles';
import { verticalScale } from '@utils/scaling';
import { COLORS } from '@constants/colors';
import { DeviceUtils } from '@utils/device';

export const PopUpInfo = (props: PopUpInfoProps): JSX.Element => {
const { body, title, placement, testID, isVisible, onBackdropPress } = props;

return (
<Popover
isVisible={isVisible}
placement={(placement || 'auto') as PopoverPlacement}
popoverStyle={styles.popoverStyle}
onRequestClose={onBackdropPress}
verticalOffset={
DeviceUtils.isAndroid ? -(StatusBar.currentHeight || 0) : 0
}
from={(sourceRef, showPopover) => (
<View>
<View collapsable={false}>
<Button
testID={testID}
onPress={showPopover}
Expand Down
1 change: 1 addition & 0 deletions src/database/services/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export class AccountDB {
'wallet'
);
}
return finalAccount;
} catch (error) {
throw error;
}
Expand Down
3 changes: 2 additions & 1 deletion src/database/services/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export class WalletDB {
static async createWallet(wallet: Wallet) {
const walletInDB = await this.getWalletByHash(wallet.hash);
if (!walletInDB) {
await Database.createModel(walletsDb, wallet);
return (await Database.createModel(walletsDb, wallet)) as WalletDBModel;
}
return walletInDB;
}

static async updateWalletByHash(
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/usePasscodeEntryRevealer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const usePasscodeEntryRevealer = () => {
const isBiometricAuthenticationInProgress = await Cache.getItem(
CacheKey.isBiometricAuthenticationInProgress
);
if (isBiometricAuthenticationInProgress === 'false') {
if (!isFaceIDEnabled || isBiometricAuthenticationInProgress === 'false') {
navigation.navigate('Passcode');
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/lib/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ const getNotificationSettings = async (): Promise<NotificationSettings> => {

const setItem = async (key: CacheKey | string, item: any): Promise<void> => {
try {
await store.setItem(key, JSON.stringify(item));
await store.setItem(
key,
typeof item === 'string' ? item : JSON.stringify(item)
);
} catch (error) {
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion src/screens/AMBMarket/components/DetailedInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function AMBDetailedInfo(props: AMBDetailedInfoProps): JSX.Element {
testID={row.testID}
body={t(row.body)}
title={t(row.title)}
isVisible={visiblePopUpKey === row.key ? true : undefined}
isVisible={visiblePopUpKey === row.key}
onBackdropPress={() => setVisiblePopUpKey('')}
/>
</Row>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const createAccountInDB = async (
changesLog: '',
currencyCode
};
await AccountDB.createAccount(account, true);
return await AccountDB.createAccount(account, true);
} catch (error) {
throw error;
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/passcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const getPasscodeFromDB = async () => {

const setPasscodeInDB = async (passcode: string[]) => {
try {
await Cache.setItem(CacheKey.Passcode, passcode);
await Cache.setItem(CacheKey.Passcode, passcode.join(''));
} catch (error) {
console.error('Error setting Passcode in the database:', error);
}
Expand All @@ -37,8 +37,8 @@ const setFaceIDStatusInDB = async (isEnabled: boolean) => {
};

const verifyPasscode = async (enteredPasscode: string[]) => {
const passcode = await PasscodeUtils.getPasscodeFromDB();
return JSON.stringify(passcode) === JSON.stringify(enteredPasscode);
const passcode = await getPasscodeFromDB();
return passcode == enteredPasscode.join('');
};

export const PasscodeUtils = {
Expand Down
87 changes: 53 additions & 34 deletions src/utils/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Wallet } from '@models/Wallet';
import { DatabaseTable, WalletMetadata } from '@appTypes';
import AirDAOKeysStorage from '@lib/helpers/AirDAOKeysStorage';
import { Database, WalletDB, AccountDB } from '@database';
import {
Database,
WalletDB,
AccountDB,
AccountDBModel,
WalletDBModel
} from '@database';
import { AirDAODictTypes } from '@crypto/common/AirDAODictTypes';
import AirDAOKeysForRef from '@lib/helpers/AirDAOKeysForRef';
import { MnemonicUtils } from './mnemonics';
Expand Down Expand Up @@ -48,39 +54,52 @@ const _getWalletName = async () => {
};

const processWallet = async (mnemonic: string) => {
const number = await _getWalletNumber();
const name = await _getWalletName();
const hash = await _saveWallet({ mnemonic, name, number });
const fullWallet: Wallet = new Wallet({
hash,
name,
number
});
// get wallet info from network
const { cashbackToken } = await CashBackUtils.getByHash(hash);
fullWallet.cashback = cashbackToken;
const _account = await AirDAOKeysForRef.discoverPublicAndPrivate({
mnemonic: mnemonic
});
// create wallet in db
await WalletDB.createWallet(fullWallet);
// securely save private key
await Cache.setItem(
`${CacheKey.WalletPrivateKey}-${fullWallet.hash}`,
_account.privateKey
);
// create account in db
const currencyCode = AirDAODictTypes.Code.AMB; // TODO this needs to be changed if we support multiple currencies
await AccountUtils.createAccountInDB(
_account.address,
fullWallet.hash,
_account.path,
_account.index,
currencyCode
);
// subscribe to notifications
API.watcherService.watchAddresses([_account.address]);
return { hash };
let walletInDb: WalletDBModel | null = null;
let accountInDb: AccountDBModel | null = null;
try {
const number = await _getWalletNumber();
const name = await _getWalletName();
const hash = await _saveWallet({ mnemonic, name, number });
const fullWallet: Wallet = new Wallet({
hash,
name,
number
});
// get wallet info from network
const { cashbackToken } = await CashBackUtils.getByHash(hash);
fullWallet.cashback = cashbackToken;
const _account = await AirDAOKeysForRef.discoverPublicAndPrivate({
mnemonic: mnemonic
});
const currencyCode = AirDAODictTypes.Code.AMB; // TODO this needs to be changed if we support multiple currencies
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [walletInDbResult, _, accountInDbResult] = await Promise.all([
// create wallet in db
WalletDB.createWallet(fullWallet),
// securely store private key
Cache.setItem(
`${CacheKey.WalletPrivateKey}-${fullWallet.hash}`,
_account.privateKey
),
// create account in db
AccountUtils.createAccountInDB(
_account.address,
fullWallet.hash,
_account.path,
_account.index,
currencyCode
)
]);
walletInDb = walletInDbResult;
accountInDb = accountInDbResult;
// subscribe to notifications
API.watcherService.watchAddresses([_account.address]);
return { hash };
} catch (error) {
if (walletInDb) walletInDb.destroyPermanently();
if (accountInDb) accountInDb.destroyPermanently();
throw error;
}
};

const changeSelectedWallet = async (hash: string) => {
Expand Down

0 comments on commit a128125

Please sign in to comment.