Skip to content

Commit

Permalink
feat(HW-611): Wallet store upgrade and prepare for move balances from…
Browse files Browse the repository at this point in the history
… context to mobx (#2130)

* chore: upgrade build tools

* feat(HW-611): Wallet store refactoring

* feat(HW-611): move some wallet functions to wallet.utils

* feat(HW-695): Create class BalanceModel

* feat(HW-695): Add balances to wallet.store

* ios project file update

* code style fixes: formatting

* chore: update workflow (#2136)

* chore: run patch_build only on main branch

* chore: fix hermes (#2135)

---------

Co-authored-by: iGroza <[email protected]>
Co-authored-by: Kudasov Dmitriy <[email protected]>

* FIx BalanceModel add methods

---------

Co-authored-by: Kirill Ageychenko <[email protected]>
Co-authored-by: iGroza <[email protected]>
  • Loading branch information
3 people authored Oct 15, 2024
1 parent 190e454 commit 71681e9
Show file tree
Hide file tree
Showing 59 changed files with 456 additions and 326 deletions.
3 changes: 1 addition & 2 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import {Contact} from '@app/models/contact';
import {Language} from '@app/models/language';
import {Stories} from '@app/models/stories';
import {VariablesBool} from '@app/models/variables-bool';
import {Wallet} from '@app/models/wallet';
import {navigator} from '@app/navigator';
import {
KeystoneStackRoutes,
Expand Down Expand Up @@ -122,7 +121,7 @@ export const App = () => {
await app.init();
await migrationWallets();
// MobX stores migration
await Promise.allSettled([Contact.migrate(), Wallet.migrate()]);
await Promise.allSettled([Contact.migrate()]);

// We need reopen app for start SSS check
// because we are working with cloud snapshots
Expand Down
4 changes: 2 additions & 2 deletions src/components/account-detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {Provider} from '@app/models/provider';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {sendNotification} from '@app/services';
import {GRADIENT_END, GRADIENT_START} from '@app/variables/common';

Expand All @@ -34,7 +34,7 @@ enum TabNames {
}

export interface DetailsQrModalProps {
wallet: Wallet;
wallet: WalletModel;
onClose: () => void;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/account-info/account-info-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {CopyMenu} from '@app/components/ui/copy-menu';
import {createTheme} from '@app/helpers';
import {shortAddress} from '@app/helpers/short-address';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {Balance} from '@app/services/balance';

import {StackedVestedTokens} from '../stacked-vested-tokens';
Expand All @@ -26,7 +26,7 @@ const CARD_WIDTH = 78;
const CARD_RADIUS = 8;

export type AccountInfoProps = {
wallet: Wallet;
wallet: WalletModel;
available: Balance;
locked: Balance;
staked: Balance;
Expand Down
6 changes: 3 additions & 3 deletions src/components/account-info/account-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {createTheme} from '@app/helpers';
import {Feature, isFeatureEnabled} from '@app/helpers/is-feature-enabled';
import {useShowNft} from '@app/hooks/nft';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {Balance} from '@app/services/balance';
import {HaqqEthereumAddress, IToken, IndexerTransaction} from '@app/types';

Expand All @@ -26,7 +26,7 @@ enum TabNames {
}

export type AccountInfoProps = {
wallet: Wallet;
wallet: WalletModel;
available: Balance;
locked: Balance;
staked: Balance;
Expand All @@ -38,7 +38,7 @@ export type AccountInfoProps = {
onSend: () => void;
onReceive: () => void;
onPressTxRow: (tx: IndexerTransaction) => void;
onPressToken?: (wallet: Wallet, token: IToken) => void;
onPressToken?: (wallet: WalletModel, token: IToken) => void;
};

const TAB_INDEX_MAP = {
Expand Down
4 changes: 2 additions & 2 deletions src/components/json-rpc-sign/json-rpc-sign-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {createTheme} from '@app/helpers';
import {AddressUtils} from '@app/helpers/address-utils';
import {EthereumSignInMessage} from '@app/helpers/ethereum-message-checker';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {JsonRpcMetadata, PartialJsonRpcRequest} from '@app/types';
import {
getHostnameFromUrl,
Expand All @@ -38,7 +38,7 @@ import {WalletRow, WalletRowTypes} from '../wallet-row';
interface WalletConnectSignInfoProps {
request: PartialJsonRpcRequest;
metadata: JsonRpcMetadata;
wallet: Wallet;
wallet: WalletModel;
phishingTxRequest: Transaction | null;
messageIsHex: boolean;
blindSignEnabled: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/components/json-rpc-sign/json-rpc-sign.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {createTheme} from '@app/helpers';
import {EthereumSignInMessage} from '@app/helpers/ethereum-message-checker';
import {I18N} from '@app/i18n';
import {Fee} from '@app/models/fee';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {IContract, JsonRpcMetadata, PartialJsonRpcRequest} from '@app/types';

export interface JsonRpcSignProps {
Expand All @@ -21,7 +21,7 @@ export interface JsonRpcSignProps {
signLoading: boolean;
request: PartialJsonRpcRequest;
metadata: JsonRpcMetadata;
wallet: Wallet;
wallet: WalletModel;
verifyAddressResponse: IContract | null;
chainId?: number;
hideContractAttention?: boolean;
Expand Down
4 changes: 2 additions & 2 deletions src/components/locked-tokens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {createTheme} from '@app/helpers';
import {useIsBalancesFirstSync} from '@app/hooks/use-is-balances-sync';
import {I18N} from '@app/i18n';
import {Provider} from '@app/models/provider';
import {BalanceData} from '@app/types';
import {BalanceModel} from '@app/models/wallet';

import {
Badge,
Expand All @@ -23,7 +23,7 @@ import {
import {Placeholder} from './ui/placeholder';

export interface LockedTokensProps {
balance?: BalanceData;
balance?: BalanceModel;

onForwardPress(): void;
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/modals/details-qr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {Provider} from '@app/models/provider';
import {Wallet} from '@app/models/wallet';
import {Wallet, WalletModel} from '@app/models/wallet';
import {sendNotification} from '@app/services';
import {ModalType, Modals} from '@app/types';
import {GRADIENT_END, GRADIENT_START} from '@app/variables/common';
Expand All @@ -33,7 +33,7 @@ export const DetailsQrModal = observer(
({address, onClose}: Modals[ModalType.cardDetailsQr]) => {
const svg = useRef();
// TODO wallet can be null
const wallet = Wallet.getById(address) as Wallet;
const wallet = Wallet.getById(address) as WalletModel;
const {width} = useWindowDimensions();

const onCopy = () => {
Expand Down
4 changes: 2 additions & 2 deletions src/components/nft-viewer/nft-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {useTypedNavigation} from '@app/hooks';
import {useLayoutAnimation} from '@app/hooks/use-layout-animation';
import {I18N, getText} from '@app/i18n';
import {Nft, NftCollection, NftItem} from '@app/models/nft';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {HomeStackRoutes, NftStackRoutes} from '@app/route-types';
import {NftWidgetSize} from '@app/types';
import {SortDirectionEnum, arraySortUtil} from '@app/utils';
Expand All @@ -38,7 +38,7 @@ import {

export interface NftViewerProps {
scrollEnabled?: boolean;
wallet?: Wallet;
wallet?: WalletModel;
style?: StyleProp<ViewStyle>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/settings-account-style.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {HapticEffects, vibrate} from '@app/services/haptic';
import {WalletCardPattern, WalletCardStyle} from '@app/types';
import {generateFlatColors, generateGradientColors} from '@app/utils';
Expand Down Expand Up @@ -59,7 +59,7 @@ type SettingsAccountStyleProps = {
setColors: (value: string[]) => void;
setPatternStyle: (value: WalletCardPattern) => void;
setCardStyle: (value: WalletCardStyle) => void;
wallet: Wallet;
wallet: WalletModel;
};

export const SettingsAccountStyle = ({
Expand Down
6 changes: 3 additions & 3 deletions src/components/settings-accounts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {NoTransactionsIcon, Text} from '@app/components/ui';
import {WalletRow} from '@app/components/wallet-row';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';

type SettingsAccountsProps = {
onPressRow: (address: string) => void;
rows: Wallet[];
rows: WalletModel[];
};

export const SettingsAccounts = ({onPressRow, rows}: SettingsAccountsProps) => {
Expand All @@ -35,7 +35,7 @@ export const SettingsAccounts = ({onPressRow, rows}: SettingsAccountsProps) => {
<FlatList
data={rows}
renderItem={({item}) => <WalletRow item={item} onPress={onPressRow} />}
keyExtractor={(wallet: Wallet) => wallet.address}
keyExtractor={(wallet: WalletModel) => wallet.address}
style={styles.container}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ import {Feature, isFeatureEnabled} from '@app/helpers/is-feature-enabled';
import {useCalculatedDimensionsValue} from '@app/hooks/use-calculated-dimensions-value';
import {I18N} from '@app/i18n';
import {Provider} from '@app/models/provider';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {sendNotification} from '@app/services';
import {WalletType} from '@app/types';

type SettingsAccountDetailProps = {
wallet: Wallet;
wallet: WalletModel;
onPressRename: () => void;
onPressStyle: () => void;
onToggleIsHidden: () => void;
Expand Down
4 changes: 2 additions & 2 deletions src/components/swap/swap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {I18N} from '@app/i18n';
import {Currencies} from '@app/models/currencies';
import {Provider} from '@app/models/provider';
import {Token} from '@app/models/tokens';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';
import {Balance} from '@app/services/balance';
import {
SushiPoolEstimateResponse,
Expand Down Expand Up @@ -60,7 +60,7 @@ export type PoolsData = Omit<SushiPoolResponse, 'contracts'> & {
};

export interface SwapProps {
currentWallet: Wallet;
currentWallet: WalletModel;
poolData: PoolsData;
estimateData: Partial<SushiPoolEstimateResponse>;
tokenIn: IToken;
Expand Down
8 changes: 4 additions & 4 deletions src/components/token-viewer/token-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ import {WalletCard} from '@app/components/ui/walletCard';
import {createTheme} from '@app/helpers';
import {useWalletsBalance} from '@app/hooks/use-wallets-balance';
import {I18N, getText} from '@app/i18n';
import {Wallet} from '@app/models/wallet';
import {Wallet, WalletModel} from '@app/models/wallet';
import {HaqqEthereumAddress, IToken} from '@app/types';

export interface TokenViewerProps {
data: Record<HaqqEthereumAddress, IToken[]>;
style?: StyleProp<ViewStyle>;
wallet?: Wallet;
wallet?: WalletModel;
hideFilter?: boolean;
onPressToken?: (wallet: Wallet, token: IToken) => void;
onPressToken?: (wallet: WalletModel, token: IToken) => void;
}

const SortingNamesMap = {
Expand All @@ -48,7 +48,7 @@ export const TokenViewer = observer(
() =>
Object.keys(data)
.map(item => Wallet.getById(item))
.filter(item => !!item) as Wallet[],
.filter(item => !!item) as WalletModel[],
[data],
);
const balances = useWalletsBalance(wallets);
Expand Down
26 changes: 15 additions & 11 deletions src/components/total-value-info/total-value-info-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import React from 'react';
import {View} from 'react-native';

import {Color} from '@app/colors';
import {First, Spacer, Text} from '@app/components/ui';
import {First, Spacer, Text, TextVariant} from '@app/components/ui';
import {createTheme} from '@app/helpers';
import {I18N} from '@app/i18n';
import {BalanceData} from '@app/types';
import {BalanceModel} from '@app/models/wallet';

import {StackedVestedTokens} from '../stacked-vested-tokens';

export type TotalValueInfoProps = {
balance: BalanceData;
balance: BalanceModel;
onPressInfo: () => void;
};

Expand All @@ -22,18 +22,22 @@ export const TotalValueInfoHeader = ({
return (
<>
<View style={styles.header}>
<Text t12 i18n={I18N.totalValueAccount} color={Color.textBase2} />
<Text
variant={TextVariant.t12}
i18n={I18N.totalValueAccount}
color={Color.textBase2}
/>
<Spacer height={4} />
<View style={styles.balanceWrapper}>
<Text t3 children={balance.total.toBalanceString('auto')} />
<Text variant={TextVariant.t3}>
{balance.total.toBalanceString('auto')}
</Text>
</View>
{!!balance.total.toFiat() && (
<View style={styles.usdWrapper}>
<Text
style={styles.usdText}
t13
children={balance.total.toFiat()}
/>
<Text style={styles.usdText} variant={TextVariant.t13}>
{balance.total.toFiat()}
</Text>
</View>
)}
</View>
Expand All @@ -44,7 +48,7 @@ export const TotalValueInfoHeader = ({
vestedBalance={balance?.vested}
stakingBalance={balance?.staked}
onPressInfo={onPressInfo}
unlock={balance?.unlock}
unlock={balance?.nextVestingUnlockDate}
/>
</First>
</>
Expand Down
8 changes: 4 additions & 4 deletions src/components/total-value-info/total-value-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {Feature, isFeatureEnabled} from '@app/helpers/is-feature-enabled';
import {useShowNft} from '@app/hooks/nft';
import {I18N} from '@app/i18n';
import {Transaction} from '@app/models/transaction';
import {Wallet} from '@app/models/wallet';
import {BalanceData, HaqqEthereumAddress, IToken} from '@app/types';
import {BalanceModel, WalletModel} from '@app/models/wallet';
import {HaqqEthereumAddress, IToken} from '@app/types';

import {TotalValueInfoHeader} from './total-value-info-header';

Expand All @@ -32,13 +32,13 @@ const TabIndexMap = {
};

export type TotalValueInfoProps = {
balance: BalanceData;
balance: BalanceModel;
addressList: string[];
tokens: Record<HaqqEthereumAddress, IToken[]>;
initialTab?: TotalValueTabNames;
onPressTxRow: (tx: Transaction) => void;
onPressInfo: () => void;
onPressToken?: (wallet: Wallet, token: IToken) => void;
onPressToken?: (wallet: WalletModel, token: IToken) => void;
};

export const TotalValueInfo = observer(
Expand Down
4 changes: 2 additions & 2 deletions src/components/transaction-account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import {FlatList} from 'react-native';
import {PopupContainer} from '@app/components/ui';
import {WalletRow} from '@app/components/wallet-row';
import {createTheme} from '@app/helpers';
import {Wallet} from '@app/models/wallet';
import {WalletModel} from '@app/models/wallet';

type TransactionAccountProps = {
rows: Wallet[];
rows: WalletModel[];
onPressRow: (address: string) => void;
};

Expand Down
Loading

0 comments on commit 71681e9

Please sign in to comment.