Skip to content

Commit e67f64c

Browse files
committed
fix: fixed missing max and custom button disabling when conversion is pending in money hub
1 parent c7f91eb commit e67f64c

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

app/components/UI/Money/components/MoneyConvertStablecoins/MoneyConvertStablecoins.test.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
import React from 'react';
22
import { render, fireEvent } from '@testing-library/react-native';
3+
import { useSelector } from 'react-redux';
34
import MoneyConvertStablecoins from './MoneyConvertStablecoins';
45
import { MoneyConvertStablecoinsTestIds } from './MoneyConvertStablecoins.testIds';
56
import { strings } from '../../../../../../locales/i18n';
67
import { AssetType } from '../../../../Views/confirmations/types/token';
78
import { ConvertTokenRowTestIds } from '../../../Earn/components/Musd/ConvertTokenRow';
9+
import {
10+
selectHasUnapprovedMusdConversion,
11+
selectHasInFlightMusdConversion,
12+
selectMusdConversionStatuses,
13+
} from '../../../Earn/selectors/musdConversionStatus';
14+
15+
jest.mock('react-redux', () => ({
16+
...jest.requireActual('react-redux'),
17+
useSelector: jest.fn(),
18+
}));
19+
20+
const mockUseSelector = useSelector as jest.Mock;
821

922
jest.mock('../../../../../component-library/base-components/TagBase', () => ({
1023
__esModule: true,
@@ -100,6 +113,12 @@ const defaultProps = {
100113
describe('MoneyConvertStablecoins', () => {
101114
beforeEach(() => {
102115
jest.clearAllMocks();
116+
mockUseSelector.mockImplementation((selector) => {
117+
if (selector === selectHasUnapprovedMusdConversion) return false;
118+
if (selector === selectHasInFlightMusdConversion) return false;
119+
if (selector === selectMusdConversionStatuses) return {};
120+
return undefined;
121+
});
103122
});
104123

105124
describe('with eligible tokens', () => {

app/components/UI/Money/components/MoneyConvertStablecoins/MoneyConvertStablecoins.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,13 @@ import ConvertTokenRow from '../../../Earn/components/Musd/ConvertTokenRow';
3030
import { AssetType } from '../../../../Views/confirmations/types/token';
3131
import { MoneyConvertStablecoinsTestIds } from './MoneyConvertStablecoins.testIds';
3232
import { CaipChainId } from '@metamask/utils';
33+
import { useSelector } from 'react-redux';
34+
import {
35+
createTokenChainKey,
36+
selectHasInFlightMusdConversion,
37+
selectHasUnapprovedMusdConversion,
38+
selectMusdConversionStatuses,
39+
} from '../../../Earn/selectors/musdConversionStatus';
3340

3441
interface MoneyConvertStablecoinsProps {
3542
tokens: AssetType[];
@@ -134,6 +141,33 @@ const MoneyConvertStablecoins = ({
134141
}: MoneyConvertStablecoinsProps) => {
135142
const hasTokens = tokens.length > 0;
136143

144+
const hasUnapprovedMusdConversion = useSelector(
145+
selectHasUnapprovedMusdConversion,
146+
);
147+
const hasInFlightMusdConversion = useSelector(
148+
selectHasInFlightMusdConversion,
149+
);
150+
151+
const conversionStatusesByTokenChainKey = useSelector(
152+
selectMusdConversionStatuses,
153+
);
154+
155+
const isConversionPending = (token: AssetType) => {
156+
const tokenAddress = token.address;
157+
const tokenChainId = token.chainId;
158+
159+
const tokenChainKey =
160+
tokenAddress && tokenChainId
161+
? createTokenChainKey(tokenAddress, tokenChainId)
162+
: undefined;
163+
164+
const txStatusInfo = tokenChainKey
165+
? conversionStatusesByTokenChainKey[tokenChainKey]
166+
: undefined;
167+
168+
return Boolean(txStatusInfo?.isPending);
169+
};
170+
137171
return (
138172
<Box testID={MoneyConvertStablecoinsTestIds.CONTAINER}>
139173
<Box twClassName="px-4 pt-3">
@@ -164,6 +198,10 @@ const MoneyConvertStablecoins = ({
164198
token={token}
165199
onMaxPress={onMaxPress}
166200
onEditPress={onEditPress}
201+
areActionsDisabled={
202+
hasUnapprovedMusdConversion || hasInFlightMusdConversion
203+
}
204+
isConversionPending={isConversionPending(token)}
167205
/>
168206
</Box>
169207
))}

0 commit comments

Comments
 (0)