Skip to content

Commit

Permalink
fix(mobile): update staking data on mobile (#15371)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nodonisko authored Nov 13, 2024
1 parent e4ef6ae commit 1fe405d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 1 deletion.
3 changes: 3 additions & 0 deletions suite-native/app/src/initActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
createImportedDeviceThunk,
initBlockchainThunk,
initDevices,
initStakeDataThunk,
periodicFetchFiatRatesThunk,
} from '@suite-common/wallet-core';
import { initAnalyticsThunk } from '@suite-native/analytics';
Expand Down Expand Up @@ -37,6 +38,8 @@ export const applicationInit = createThunk(

dispatch(periodicCheckTokenDefinitionsThunk());

dispatch(initStakeDataThunk());

dispatch(
periodicFetchFiatRatesThunk({
rateType: 'current',
Expand Down
1 change: 1 addition & 0 deletions suite-native/module-staking-management/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"dependencies": {
"@react-navigation/native": "6.1.18",
"@reduxjs/toolkit": "1.9.5",
"@suite-common/wallet-core": "workspace:*",
"@suite-native/atoms": "workspace:*",
"@suite-native/formatters": "workspace:*",
Expand Down
7 changes: 7 additions & 0 deletions suite-native/module-staking-management/redux.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { AsyncThunkAction } from '@reduxjs/toolkit';

declare module 'redux' {
export interface Dispatch {
<TThunk extends AsyncThunkAction<any, any, any>>(thunk: TThunk): ReturnType<TThunk>;
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,47 @@
import { useDispatch } from 'react-redux';
import { RefreshControl } from 'react-native';
import { useMemo, useState, useCallback } from 'react';

import { RouteProp, useRoute } from '@react-navigation/native';

import { RootStackParamList, RootStackRoutes, Screen } from '@suite-native/navigation';
import { initStakeDataThunk } from '@suite-common/wallet-core';
import { useNativeStyles } from '@trezor/styles';

import { StakingDetailScreenHeader } from '../components/StakingDetailScreenHeader';
import { StakingInfo } from '../components/StakingInfo';

const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms));

export const StakingDetailScreen = () => {
const route = useRoute<RouteProp<RootStackParamList, RootStackRoutes.StakingDetail>>();
const { accountKey } = route.params;
const [isRefreshing, setIsRefreshing] = useState(false);
const { utils } = useNativeStyles();

const dispatch = useDispatch();

const handleRefresh = useCallback(async () => {
setIsRefreshing(true);
await dispatch(initStakeDataThunk());
// sleep little bit because it's too fast
await sleep(1000);
setIsRefreshing(false);
}, [dispatch]);

const refreshControl = useMemo(
() => (
<RefreshControl
refreshing={isRefreshing}
onRefresh={handleRefresh}
colors={[utils.colors.backgroundPrimaryDefault]}
/>
),
[isRefreshing, handleRefresh, utils.colors],
);

return (
<Screen screenHeader={<StakingDetailScreenHeader />}>
<Screen screenHeader={<StakingDetailScreenHeader />} refreshControl={refreshControl}>
<StakingInfo accountKey={accountKey} />
</Screen>
);
Expand Down
3 changes: 3 additions & 0 deletions suite-native/state/src/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
prepareDeviceReducer,
prepareDiscoveryReducer,
prepareFiatRatesReducer,
prepareStakeReducer,
prepareTransactionsReducer,
} from '@suite-common/wallet-core';
import { appSettingsReducer, appSettingsPersistWhitelist } from '@suite-native/settings';
Expand Down Expand Up @@ -46,6 +47,7 @@ const deviceReducer = prepareDeviceReducer(extraDependencies);
const discoveryReducer = prepareDiscoveryReducer(extraDependencies);
const tokenDefinitionsReducer = prepareTokenDefinitionsReducer(extraDependencies);
const sendFormReducer = sendFormSlice.prepareReducer(extraDependencies);
const stakeReducer = prepareStakeReducer(extraDependencies);

export const prepareRootReducers = async () => {
const appSettingsPersistedReducer = await preparePersistReducer({
Expand All @@ -68,6 +70,7 @@ export const prepareRootReducers = async () => {
discovery: discoveryReducer,
send: sendFormReducer,
fees: feesReducer,
stake: stakeReducer,
});

const walletPersistedReducer = await preparePersistReducer({
Expand Down
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10358,6 +10358,7 @@ __metadata:
resolution: "@suite-native/module-staking-management@workspace:suite-native/module-staking-management"
dependencies:
"@react-navigation/native": "npm:6.1.18"
"@reduxjs/toolkit": "npm:1.9.5"
"@suite-common/wallet-core": "workspace:*"
"@suite-native/atoms": "workspace:*"
"@suite-native/formatters": "workspace:*"
Expand Down

0 comments on commit 1fe405d

Please sign in to comment.