Skip to content

Nt/wallet tab optimise #2953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion __tests__/App-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ test('renders correctly', async () => {
await ReactTestRenderer.act(() => {
ReactTestRenderer.create(<App />);
});
});
});
10 changes: 3 additions & 7 deletions metro.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');
const {
wrapWithReanimatedMetroConfig,
} = require('react-native-reanimated/metro-config');
const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
const { wrapWithReanimatedMetroConfig } = require('react-native-reanimated/metro-config');

/**
* Metro configuration
Expand All @@ -11,6 +9,4 @@ const {
*/
const config = {};

module.exports = wrapWithReanimatedMetroConfig(
mergeConfig(getDefaultConfig(__dirname), config)
);
module.exports = wrapWithReanimatedMetroConfig(mergeConfig(getDefaultConfig(__dirname), config));
2 changes: 1 addition & 1 deletion src/components/postCard/children/postCardContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import { useIntl } from 'react-intl';
// Components

// Styles
import { Image as ExpoImage } from 'expo-image';
import styles from './postCardStyles';
import { PostCardActionIds } from '../container/postCard';
import ROUTES from '../../../constants/routeNames';
import { ContentType } from '../../../providers/hive/hive.types';
import { Image as ExpoImage } from 'expo-image';

const DEFAULT_IMAGE =
'https://images.ecency.com/DQmT8R33geccEjJfzZEdsRHpP3VE8pu3peRCnQa1qukU4KR/no_image_3x.png';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const ProposalVoteRequest = () => {
const intl = useIntl();
const dispatch = useDispatch();

//reference query with active proposal id
// reference query with active proposal id
const activeProposalMetaQuery = useActiveProposalMetaQuery();
const _ecencyProposalId = activeProposalMetaQuery.data?.id;

Expand Down
2 changes: 1 addition & 1 deletion src/components/quickReplyModal/quickReplyModalView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const QuickReplyModal = () => {
containerStyle={styles.sheetContent}
indicatorStyle={styles.sheetIndicator}
defaultOverlayOpacity={0}
keyboardHandlerEnabled={Platform.OS !== 'android'} //hack to prevent sheet height issue on android
keyboardHandlerEnabled={Platform.OS !== 'android'} // hack to prevent sheet height issue on android
onClose={_onClose}
>
<QuickReplyModalContent
Expand Down
23 changes: 17 additions & 6 deletions src/containers/walletContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { toastNotification } from '../redux/actions/uiAction';
import { getAccount, claimRewardBalance } from '../providers/hive/dhive';

// Utils
import { groomingWalletData, groomingTransactionData, transferTypes } from '../utils/wallet';
import { groomingWalletTabData, groomingTransactionData, transferTypes } from '../utils/wallet';
import parseToken from '../utils/parseToken';
import { vestsToHp } from '../utils/conversions';
import RootNavigation from '../navigation/rootNavigation';
Expand All @@ -35,6 +35,7 @@ const WalletContainer = ({
children,
currentAccount,
coinSymbol,
quotes,
globalProps,
pinCode,
selectedUser,
Expand Down Expand Up @@ -123,8 +124,14 @@ const WalletContainer = ({
// Components functions

const _getWalletData = useCallback(
async (_selectedUser) => {
const _walletData = await groomingWalletData(_selectedUser, globalProps, currency);
async (_selectedUser, isRefresh = false) => {
const _walletData = await groomingWalletTabData({
user: _selectedUser,
globalProps,
userCurrency: currency,
quotes,
isRefresh,
});

setWalletData(_walletData);
setIsLoading(false);
Expand Down Expand Up @@ -177,7 +184,8 @@ const WalletContainer = ({
})
.then(() => getAccount(currentAccount.name))
.then(() => {
_getWalletData(selectedUser);
const _isRefresh = true;
_getWalletData(selectedUser, _isRefresh);
if (isHasUnclaimedRewards) {
dispatch(
toastNotification(
Expand All @@ -189,7 +197,8 @@ const WalletContainer = ({
}
})
.then(() => {
_getWalletData(selectedUser);
const _isRefresh = true;
_getWalletData(selectedUser, _isRefresh);
setIsClaiming(false);
})
.catch(() => {
Expand All @@ -211,7 +220,8 @@ const WalletContainer = ({

getAccount(selectedUser.name)
.then(() => {
_getWalletData(selectedUser);
const _isRefresh = true;
_getWalletData(selectedUser, _isRefresh);
setRefreshing(false);
})
.catch(() => {
Expand Down Expand Up @@ -341,6 +351,7 @@ const mapStateToProps = (state) => ({
currentAccount: state.account.currentAccount,
pinCode: state.application.pin,
globalProps: state.account.globalProps,
quotes: state.wallet.quotes,
currency: state.application.currency.currency,
hivePerMVests: state.account.globalProps.hivePerMVests,
isPinCodeOpen: state.application.isPinCodeOpen,
Expand Down
2 changes: 1 addition & 1 deletion src/providers/ecency/ecency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ export const getBotAuthers = async () => {
}
};

//get active proposal meta api call
// get active proposal meta api call
export const getActiveProposalMeta = async () => {
try {
const res = await ecencyApi.get('/private-api/proposal/active');
Expand Down
9 changes: 3 additions & 6 deletions src/screens/assetsSelect/screen/assetsSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,14 @@ const AssetsSelect = ({ navigation }) => {
}));
}

//extract a list of tokens with meta entry
const assetsWithMeta = currentAccount.about.profile.tokens.filter((item) => (!!item.meta))
// extract a list of tokens with meta entry
const assetsWithMeta = currentAccount.about.profile.tokens.filter((item) => !!item.meta);

const updatedCurrentAccountData = currentAccount;
updatedCurrentAccountData.about.profile = {
...updatedCurrentAccountData.about.profile,
// make sure entries with meta are preserved
tokens: [
...assetsData,
...assetsWithMeta
],
tokens: [...assetsData, ...assetsWithMeta],
};
const params = {
...updatedCurrentAccountData.about.profile,
Expand Down
2 changes: 1 addition & 1 deletion src/screens/wallet/screen/walletScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const WalletScreen = ({ navigation }) => {

// actions
const populateSelectedAssets = (tokensArr) => {
//filter out any other type of token other than ENGINE and SPK
// filter out any other type of token other than ENGINE and SPK
return tokensArr
.filter(({ type }) => type === 'ENGINE' || type === 'SPK')
.map(({ symbol, type }) => ({
Expand Down
57 changes: 23 additions & 34 deletions src/utils/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import get from 'lodash/get';
import { operationOrders } from '@hiveio/dhive/lib/utils';
import { utils } from '@hiveio/dhive';
import { SpkApiWallet } from 'providers/hive-spk/hiveSpk.types';
import parseDate from './parseDate';
import parseToken from './parseToken';
Expand Down Expand Up @@ -295,14 +294,21 @@ export const groomingEngineHistory = (transaction: HistoryItem): CoinActivity |
return result;
};

export const groomingWalletData = async (user, globalProps, userCurrency) => {
export const groomingWalletTabData = async ({
user,
globalProps,
quotes,
userCurrency,
isRefresh,
}) => {
const walletData = {};

if (!user) {
return walletData;
}

const userdata = await getAccount(get(user, 'name'));
// TODO: use passed account data if not refreshing
const userdata = isRefresh ? await getAccount(get(user, 'name')) : user;

// const { accounts } = state;
// if (!accounts) {
Expand All @@ -326,8 +332,15 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => {
walletData.savingBalance = parseToken(userdata.savings_balance);
walletData.savingBalanceHbd = parseToken(userdata.savings_hbd_balance);

// TOOD: use base and quote from account.globalProps redux
const feedHistory = await getFeedHistory();
// use base and quote from account.globalProps redux
const feedHistory = isRefresh
? await getFeedHistory()
: {
current_median_history: {
base: globalProps.base,
quote: globalProps.quote,
},
};
const base = parseToken(feedHistory.current_median_history.base);
const quote = parseToken(feedHistory.current_median_history.quote);

Expand All @@ -344,9 +357,11 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => {

walletData.estimatedValue = totalHive * pricePerHive + totalHbd;

// TODO: cache data in redux or fetch once on wallet startup
const ppHbd = await getCurrencyTokenRate(userCurrency, 'hbd');
const ppHive = await getCurrencyTokenRate(userCurrency, 'hive');
// if refresh not required, use cached quotes
const ppHbd = !isRefresh
? quotes.hive_dollar.price
: await getCurrencyTokenRate(userCurrency, 'hbd');
const ppHive = !isRefresh ? quotes.hive.price : await getCurrencyTokenRate(userCurrency, 'hive');

walletData.estimatedHiveValue = (walletData.balance + walletData.savingBalance) * ppHive;
walletData.estimatedHbdValue = totalHbd * ppHbd;
Expand All @@ -357,32 +372,6 @@ export const groomingWalletData = async (user, globalProps, userCurrency) => {
const timeDiff = Math.abs(parseDate(userdata.next_vesting_withdrawal) - new Date());
walletData.nextVestingWithdrawal = Math.round(timeDiff / (1000 * 3600));

// TOOD: transfer history can be separated from here
const op = utils.operationOrders;
const ops = [
op.transfer, // HIVE
op.author_reward, // HBD, HP
op.curation_reward, // HP
op.transfer_to_vesting, // HIVE, HP
op.withdraw_vesting, // HIVE, HP
op.interest, // HP
op.transfer_to_savings, // HIVE, HBD
op.transfer_from_savings, // HIVE, HBD
op.fill_convert_request, // HBD
op.fill_order, // HIVE, HBD
op.claim_reward_balance, // HP
op.sps_fund, // HBD
op.comment_benefactor_reward, // HP
op.return_vesting_delegation, // HP
];

const history = await getAccountHistory(get(user, 'name'), ops);

const transfers = history.filter((tx) => transferTypes.includes(get(tx[1], 'op[0]', false)));

transfers.sort(compare);

walletData.transactions = transfers;
return walletData;
};

Expand Down