Skip to content

Commit f882b48

Browse files
adderpositivetomasklim
authored andcommitted
fix(coinmarke): design fixes & improvements
fix(coinmarket): no offers/error - use label no methods available fix(coinmarket): fix franction buttons margin fix(coinmarket): select/modal overlap fix(coinmarket): detail transaction receiveAmount fix(coinmarket): loading invity data also on detail/transactions page fix(coinmarket): sell all fraction fix(coinmarket): fiat change updates fees fix(coinmarket): design of receive address fix(coinmarket): icon size in exchange select fix(coinmarket): exchange select bad value fix(coinmarket): send exchange value fix(coinmarket): sell - switching between fiat/crypto fix(coinmarket): sell form - composing on fraction buttons
1 parent 597483e commit f882b48

File tree

46 files changed

+534
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+534
-421
lines changed

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketBuyForm.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import type { BuyTrade, BuyTradeQuoteRequest } from 'invity-api';
55
import { isChanged } from '@suite-common/suite-utils';
66
import { formatAmount, getNetwork } from '@suite-common/wallet-utils';
77
import { useActions, useDispatch, useSelector } from 'src/hooks/suite';
8-
import { loadInvityData } from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
98
import invityAPI from 'src/services/suite/invityAPI';
109
import {
1110
createQuoteLink,
@@ -42,6 +41,7 @@ import { FORM_PAYMENT_METHOD_SELECT } from 'src/constants/wallet/coinmarket/form
4241
import { useCoinmarketSatsSwitcher } from 'src/hooks/wallet/coinmarket/form/useCoinmarketSatsSwitcher';
4342
import { Network } from '@suite-common/wallet-config';
4443
import { cryptoToNetworkSymbol } from 'src/utils/wallet/coinmarket/cryptoSymbolUtils';
44+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
4545

4646
const useCoinmarketBuyForm = ({
4747
selectedAccount,
@@ -162,7 +162,6 @@ const useCoinmarketBuyForm = ({
162162
quoteCryptoAmount: quotesByPaymentMethod?.[0]?.receiveStringAmount,
163163
quoteFiatAmount: quotesByPaymentMethod?.[0]?.fiatStringAmount,
164164
network,
165-
setIsSubmittingHelper,
166165
});
167166

168167
const getQuotesRequest = useCallback(
@@ -373,10 +372,7 @@ const useCoinmarketBuyForm = ({
373372
setCallInProgress(false);
374373
};
375374

376-
// hooks
377-
useEffect(() => {
378-
dispatch(loadInvityData());
379-
}, [dispatch]);
375+
useCoinmarketLoadData();
380376

381377
// call change handler on every change of text inputs with debounce
382378
useDebounce(

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketExchangeForm.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ import { selectFiatRatesByFiatRateKey } from '@suite-common/wallet-core';
1616
import { useActions, useDispatch, useSelector, useTranslation } from 'src/hooks/suite';
1717
import invityAPI from 'src/services/suite/invityAPI';
1818
import { saveQuoteRequest, saveQuotes } from 'src/actions/wallet/coinmarketExchangeActions';
19-
import {
20-
loadInvityData,
21-
saveComposedTransactionInfo,
22-
} from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
19+
import { saveComposedTransactionInfo } from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
2320
import {
2421
addIdsToQuotes,
2522
getComposeAddressPlaceholder,
@@ -66,6 +63,7 @@ import { useCoinmarketRecomposeAndSign } from 'src/hooks/wallet/useCoinmarketRec
6663
import { Network, networksCompatibility } from '@suite-common/wallet-config';
6764
import { SET_MODAL_CRYPTO_CURRENCY } from 'src/actions/wallet/constants/coinmarketCommonConstants';
6865
import useCoinmarketExchangeFormHelpers from 'src/hooks/wallet/coinmarket/form/useCoinmarketExchangeFormHelpers';
66+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
6967

7068
export const useCoinmarketExchangeForm = ({
7169
selectedAccount,
@@ -536,9 +534,7 @@ export const useCoinmarketExchangeForm = ({
536534
}
537535
}, [previousValues, values, handleChange, handleSubmit, isPageOffers]);
538536

539-
useEffect(() => {
540-
dispatch(loadInvityData());
541-
}, [dispatch]);
537+
useCoinmarketLoadData();
542538

543539
useEffect(() => {
544540
if (!composedLevels) return;

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSatsSwitcher.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ interface UseCoinmarketSatsSwitcherProps {
1212
quoteCryptoAmount: string | undefined;
1313
quoteFiatAmount: string | undefined;
1414
network: Network | null;
15-
setIsSubmittingHelper: (value: boolean) => void;
1615
}
1716

1817
/**
@@ -24,7 +23,6 @@ export const useCoinmarketSatsSwitcher = ({
2423
quoteCryptoAmount,
2524
quoteFiatAmount,
2625
network,
27-
setIsSubmittingHelper,
2826
}: UseCoinmarketSatsSwitcherProps) => {
2927
const { setValue, getValues } = methods;
3028
const { shouldSendInSats } = useBitcoinAmountUnit(account.symbol);
@@ -38,13 +36,13 @@ export const useCoinmarketSatsSwitcher = ({
3836
const amount = shouldSendInSats
3937
? amountToSatoshi(quoteCryptoAmount ?? '', networkDecimals)
4038
: quoteCryptoAmount;
39+
4140
setValue(FORM_CRYPTO_INPUT, amount);
4241
} else {
43-
setValue(FORM_FIAT_INPUT, coinmarketGetRoundedFiatAmount(quoteFiatAmount ?? ''));
42+
setValue(FORM_FIAT_INPUT, coinmarketGetRoundedFiatAmount(quoteFiatAmount));
4443
}
4544

4645
setValue('amountInCrypto', !amountInCrypto);
47-
setIsSubmittingHelper(true); // remove delay of sending request
4846
};
4947

5048
useDidUpdate(() => {

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellForm.ts

Lines changed: 6 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import { useCoinmarketSellFormHelpers } from 'src/hooks/wallet/coinmarket/form/u
5757
import { selectAccounts } from '@suite-common/wallet-core';
5858
import { Network } from '@suite-common/wallet-config';
5959
import { useCoinmarketSatsSwitcher } from 'src/hooks/wallet/coinmarket/form/useCoinmarketSatsSwitcher';
60+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
6061

6162
export const useCoinmarketSellForm = ({
6263
selectedAccount,
@@ -104,7 +105,6 @@ export const useCoinmarketSellForm = ({
104105
openCoinmarketSellConfirmModal,
105106
submitRequestForm,
106107
saveComposedTransactionInfo,
107-
loadInvityData,
108108
savePaymentMethods,
109109
} = useActions({
110110
goto: routerActions.goto,
@@ -247,7 +247,6 @@ export const useCoinmarketSellForm = ({
247247
quoteCryptoAmount: quotesByPaymentMethod?.[0]?.cryptoStringAmount,
248248
quoteFiatAmount: quotesByPaymentMethod?.[0]?.fiatStringAmount,
249249
network,
250-
setIsSubmittingHelper,
251250
});
252251

253252
const getQuotesRequest = useCallback(
@@ -610,10 +609,7 @@ export const useCoinmarketSellForm = ({
610609
}
611610
};
612611

613-
// hooks
614-
useEffect(() => {
615-
dispatch(loadInvityData());
616-
}, [dispatch, loadInvityData]);
612+
useCoinmarketLoadData();
617613

618614
useEffect(() => {
619615
if (!isChanged(defaultValues, values)) {
@@ -654,35 +650,10 @@ export const useCoinmarketSellForm = ({
654650
setState(initState);
655651
};
656652

657-
// used to prevent composing transaction on empty fields
658-
const shouldCompose =
659-
values?.cryptoInput !== '' ||
660-
values?.fiatInput !== '' ||
661-
values?.setMaxOutputId === 0 ||
662-
// check changing accounts
663-
initState?.formValues?.outputs[0].address !== values?.outputs?.[0]?.address;
664-
665-
if (
666-
initState &&
667-
initState?.account.descriptor !== state?.account.descriptor &&
668-
shouldCompose
669-
) {
653+
if (initState && initState?.account.descriptor !== state?.account.descriptor) {
670654
setStateAsync(initState);
671655
}
672-
}, [
673-
state,
674-
initState,
675-
account,
676-
network,
677-
device,
678-
accounts,
679-
chunkify,
680-
setValue,
681-
values,
682-
values?.cryptoInput,
683-
values?.fiatInput,
684-
values?.setMaxOutputId,
685-
]);
656+
}, [state, initState, account, network, device, accounts, chunkify, setValue]);
686657

687658
useEffect(() => {
688659
if (!composedLevels) return;
@@ -718,10 +689,10 @@ export const useCoinmarketSellForm = ({
718689

719690
useEffect(() => {
720691
// when draft doesn't exist, we need to bind actual default values - that happens when we've got sellInfo from Invity API server
721-
if (!isDraft && sellInfo) {
692+
if (!isDraft && sellInfo && !formState.isDirty) {
722693
reset(defaultValues);
723694
}
724-
}, [reset, sellInfo, defaultValues, isDraft, isPageOffers]);
695+
}, [reset, sellInfo, defaultValues, isDraft, isPageOffers, formState.isDirty]);
725696

726697
useDebounce(
727698
() => {

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketSellFormHelpers.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ export const useCoinmarketSellFormHelpers = ({
142142
setValue(FORM_CRYPTO_INPUT, cryptoInputValue, { shouldDirty: true });
143143
setValue('setMaxOutputId', undefined, { shouldDirty: true });
144144
onCryptoAmountChange(cryptoInputValue);
145+
146+
composeRequest(FORM_CRYPTO_INPUT);
145147
},
146148
[
149+
tokenData,
147150
account.formattedBalance,
148-
shouldSendInSats,
149151
network.decimals,
150-
onCryptoAmountChange,
151-
tokenData,
152+
shouldSendInSats,
152153
setValue,
154+
onCryptoAmountChange,
155+
composeRequest,
153156
],
154157
);
155158

packages/suite/src/hooks/wallet/coinmarket/form/useCoinmarketVerifyAccount.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const useCoinmarketVerifyAccount = ({
9696
const isDebug = useSelector(selectIsDebugModeActive);
9797
const device = useSelector(selectDevice);
9898
const dispatch = useDispatch();
99+
const [isMenuOpen, setIsMenuOpen] = useState<boolean | undefined>(undefined);
99100

100101
const methods = useForm<CoinmarketVerifyFormProps>({
101102
mode: 'onChange',
@@ -132,6 +133,7 @@ const useCoinmarketVerifyAccount = ({
132133

133134
const onChangeAccount = (account: CoinmarketVerifyFormAccountOptionProps) => {
134135
if (account.type === 'ADD_SUITE' && device) {
136+
setIsMenuOpen(true);
135137
dispatch(
136138
openModal({
137139
type: 'add-account',
@@ -144,6 +146,7 @@ const useCoinmarketVerifyAccount = ({
144146
return;
145147
}
146148

149+
setIsMenuOpen(undefined);
147150
selectAccountOption(account);
148151
};
149152

@@ -167,6 +170,7 @@ const useCoinmarketVerifyAccount = ({
167170
receiveNetwork,
168171
selectAccountOptions,
169172
selectedAccountOption,
173+
isMenuOpen,
170174
getTranslationIds,
171175
onChangeAccount,
172176
};

packages/suite/src/hooks/wallet/coinmarket/useCoinmarketDetail.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
CoinmarketTradeType,
1818
} from 'src/types/coinmarket/coinmarket';
1919
import { useServerEnvironment } from './useServerEnviroment';
20+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
2021

2122
const isBuyTrade = (trade: Trade): trade is TradeBuy => trade.tradeType === 'buy';
2223

@@ -96,6 +97,7 @@ export const useCoinmarketDetail = <T extends CoinmarketTradeType>({
9697
tradeType,
9798
});
9899

100+
useCoinmarketLoadData();
99101
useServerEnvironment();
100102
useCoinmarketWatchTrade({ account, trade });
101103

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useEffect } from 'react';
2+
import { loadInvityData } from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
3+
import { useDispatch } from 'src/hooks/suite';
4+
5+
export const useCoinmarketLoadData = () => {
6+
const dispatch = useDispatch();
7+
8+
useEffect(() => {
9+
dispatch(loadInvityData());
10+
}, [dispatch]);
11+
};

packages/suite/src/hooks/wallet/useCoinmarketExchangeForm.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import {
2323
saveQuoteRequest,
2424
saveQuotes,
2525
} from 'src/actions/wallet/coinmarketExchangeActions';
26-
import {
27-
loadInvityData,
28-
saveComposedTransactionInfo,
29-
} from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
26+
import { saveComposedTransactionInfo } from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
3027
import {
3128
ExchangeFormState,
3229
ExchangeFormContextValues,
@@ -60,6 +57,7 @@ import { selectLocalCurrency } from 'src/reducers/wallet/settingsReducer';
6057
import { TokenAddress } from '@suite-common/wallet-types';
6158
import { CoinmarketTradeExchangeType, UseCoinmarketProps } from 'src/types/coinmarket/coinmarket';
6259
import { BigNumber } from '@trezor/utils';
60+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
6361

6462
export const ExchangeFormContext = createContext<ExchangeFormContextValues | null>(null);
6563
ExchangeFormContext.displayName = 'CoinmarketExchangeContext';
@@ -105,9 +103,7 @@ export const useCoinmarketExchangeForm = ({
105103
const { symbol, networkType } = account;
106104
const { shouldSendInSats } = useBitcoinAmountUnit(symbol);
107105

108-
useEffect(() => {
109-
dispatch(loadInvityData());
110-
}, [dispatch]);
106+
useCoinmarketLoadData();
111107

112108
const coinFees = fees[symbol];
113109
const levels = getFeeLevels(networkType, coinFees);

packages/suite/src/hooks/wallet/useCoinmarketSellForm.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ import {
1919
saveQuoteRequest,
2020
saveQuotes,
2121
} from 'src/actions/wallet/coinmarketSellActions';
22-
import {
23-
loadInvityData,
24-
saveComposedTransactionInfo,
25-
} from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
22+
import { saveComposedTransactionInfo } from 'src/actions/wallet/coinmarket/coinmarketCommonActions';
2623
import {
2724
SellFormState,
2825
SellFormContextValues,
@@ -52,6 +49,7 @@ import { CoinmarketTradeSellType, UseCoinmarketProps } from 'src/types/coinmarke
5249
import { useCoinmarketSellFormDefaultValues } from 'src/hooks/wallet/useCoinmarketSellFormDefaultValues';
5350
import { useFees } from 'src/hooks/wallet/form/useFees';
5451
import { useCompose } from 'src/hooks/wallet/form/useCompose';
52+
import { useCoinmarketLoadData } from 'src/hooks/wallet/coinmarket/useCoinmarketLoadData';
5553

5654
export const SellFormContext = createContext<SellFormContextValues | null>(null);
5755
SellFormContext.displayName = 'CoinmarketSellContext';
@@ -83,9 +81,7 @@ export const useCoinmarketSellForm = ({
8381
}: UseCoinmarketProps): SellFormContextValues => {
8482
const dispatch = useDispatch();
8583

86-
useEffect(() => {
87-
dispatch(loadInvityData());
88-
}, [dispatch]);
84+
useCoinmarketLoadData();
8985

9086
const accounts = useSelector(state => state.wallet.accounts);
9187
const device = useSelector(selectDevice);

0 commit comments

Comments
 (0)