Skip to content

Commit

Permalink
Merge branch 'develop' into feat/portfolio
Browse files Browse the repository at this point in the history
  • Loading branch information
SorinC6 authored Jun 26, 2024
2 parents 2ef9b8b + 6966520 commit 5434901
Show file tree
Hide file tree
Showing 20 changed files with 419 additions and 327 deletions.
2 changes: 1 addition & 1 deletion packages/yoroi-extension/app/api/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export default class CommonApi {
try {

const newAddress = await request.popFunc();
Logger.info(`${nameof(CommonApi)}::${nameof(this.createAddress)} success: ` + stringifyData(newAddress));
Logger.debug(`${nameof(CommonApi)}::${nameof(this.createAddress)} success: ` + stringifyData(newAddress));
return newAddress;
} catch (error) {
Logger.error(`${nameof(CommonApi)}::${nameof(this.createAddress)} error: ` + stringifyError(error));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import TextField from '../common/TextField';
import type { RemoteTokenInfo } from '../../api/ada/lib/state-fetch/types';
import LoadingSpinner from '../widgets/LoadingSpinner';
import { useState } from 'react';
import type { FormattedTokenValue } from '../../containers/swap/orders/OrdersPage';
import { WrongPassphraseError } from '../../api/ada/lib/cardanoCrypto/cryptoErrors';
import { stringifyError } from '../../utils/logging';
import { InfoTooltip } from '../widgets/InfoTooltip';
Expand All @@ -16,6 +15,7 @@ import type { TokenLookupKey } from '../../api/common/lib/MultiToken';
import type { TokenRow } from '../../api/ada/lib/storage/database/primitives/tables';
import { SelectedExplorer } from '../../domain/SelectedExplorer';
import type LocalizableError from '../../i18n/LocalizableError';
import type { FormattedTokenValue } from '../../containers/swap/orders/util';

type Props = {|
order: any,
Expand Down Expand Up @@ -102,9 +102,9 @@ export default function CancelSwapOrderDialog({
>
{transactionParams ? (
transactionParams.returnValues.map((v, index) => (
<>
<Box key={v.ticker}>
{index > 0 && ' +'} {v.formattedValue} {v.ticker}
</>
</Box>
))
) : (
<LoadingSpinner small />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import adaTokenImage from '../../assets/images/ada.inline.svg';
import defaultTokenImage from '../../assets/images/revamp/asset-default.inline.svg';
import Dialog from '../widgets/Dialog';
import Table from '../common/table/Table';
import { urlResolveForIpfsAndCorsproxy } from '../../coreUtils';
import type { RemoteTokenInfo } from '../../api/ada/lib/state-fetch/types';
import { PriceImpactColored, PriceImpactIcon } from './PriceImpact';
import { InfoTooltip } from '../widgets/InfoTooltip';
Expand All @@ -28,7 +27,7 @@ type Props = {|
onAssetSelected: any => void,
onClose: void => void,
defaultTokenInfo: RemoteTokenInfo,
getTokenInfo: string => Promise<RemoteTokenInfo>,
getTokenInfoBatch: Array<string> => { [string]: Promise<RemoteTokenInfo> },
|};

export default function SelectAssetDialog({
Expand All @@ -37,7 +36,7 @@ export default function SelectAssetDialog({
onAssetSelected,
onClose,
defaultTokenInfo,
getTokenInfo,
getTokenInfoBatch,
}: Props): React$Node {
const [searchTerm, setSearchTerm] = useState<string>('');

Expand All @@ -55,6 +54,9 @@ export default function SelectAssetDialog({
.includes(searchTerm.toLowerCase());
}) || [];

const metadataPromiseMap: { [string]: Promise<RemoteTokenInfo> } =
getTokenInfoBatch(filteredAssets.map(a => a.id))

return (
<Dialog
title={`Swap ${type}`}
Expand Down Expand Up @@ -127,7 +129,7 @@ export default function SelectAssetDialog({
type={type}
onAssetSelected={handleAssetSelected}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfo={id => metadataPromiseMap[id]}
/>
);
})}
Expand Down Expand Up @@ -187,7 +189,7 @@ export const AssetAndAmountRow = ({

const isFrom = type === 'from';

const { name = null, image = '', fingerprint: address, id, amount: assetAmount, ticker } = asset;
const { name = null, fingerprint: address, id, amount: assetAmount, ticker } = asset;
const priceNotChanged = Number(priceChange100.replace('-', '').replace('%', '')) === 0;
const priceIncreased = priceChange100 && priceChange100.charAt(0) !== '-';
const priceChange24h = priceChange100.replace('-', '') || '0%';
Expand All @@ -208,7 +210,7 @@ export const AssetAndAmountRow = ({
const imgSrc =
ticker === defaultTokenInfo.ticker
? adaTokenImage
: remoteTokenLogo ?? urlResolveForIpfsAndCorsproxy(image) ?? defaultTokenImage;
: remoteTokenLogo ?? defaultTokenImage;

const amount = displayAmount ?? assetAmount;

Expand Down
7 changes: 3 additions & 4 deletions packages/yoroi-extension/app/components/swap/SwapInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { Box, Typography } from '@mui/material';
import { ReactComponent as ChevronDownIcon } from '../../assets/images/revamp/icons/chevron-down.inline.svg';
import adaTokenImage from '../../assets/images/ada.inline.svg';
import defaultTokenImage from '../../assets/images/revamp/token-default.inline.svg';
import { urlResolveForIpfsAndCorsproxy } from '../../coreUtils';
import type { RemoteTokenInfo } from '../../api/ada/lib/state-fetch/types';
import type { State } from '../../containers/swap/context/swap-form/types';
import { useEffect, useState } from 'react';
Expand Down Expand Up @@ -38,10 +37,10 @@ export default function SwapInput({
focusState,
}: Props): Node {
const [remoteTokenLogo, setRemoteTokenLogo] = useState<?string>(null);
const { id, amount: quantity = undefined, image, ticker } = tokenInfo || {};
const { id, amount: quantity = undefined, ticker } = tokenInfo || {};

const handleChange = e => {
if (!disabled && value !== quantity) {
if (!disabled) {
handleAmountChange(e.target.value);
}
};
Expand All @@ -66,7 +65,7 @@ export default function SwapInput({
const imgSrc =
ticker === defaultTokenInfo.ticker
? adaTokenImage
: remoteTokenLogo ?? urlResolveForIpfsAndCorsproxy(image) ?? defaultTokenImage;
: remoteTokenLogo ?? defaultTokenImage;

return (
<Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type Props = {|
swapStore: SwapStore,
defaultTokenInfo: RemoteTokenInfo,
getTokenInfo: string => Promise<RemoteTokenInfo>,
getTokenInfoBatch: Array<string> => { [string]: Promise<RemoteTokenInfo> },
priceImpactState: ?PriceImpact,
|};

Expand All @@ -33,35 +34,21 @@ export const CreateSwapOrder = ({
swapStore,
defaultTokenInfo,
getTokenInfo,
getTokenInfoBatch,
priceImpactState,
}: Props): React$Node => {
const [openedDialog, setOpenedDialog] = useState('');
const [prevSelectedPoolId, setPrevSelectedPoolId] = useState<?string>(undefined);

const {
orderData: {
type: orderType,
selectedPoolCalculation,
},
// unsignedTxChanged,
sellTokenInfoChanged,
buyTokenInfoChanged,
} = useSwap();

const { onChangeLimitPrice } = useSwapForm();

const resetLimitPrice = () => {
onChangeLimitPrice('');
};

if (orderType === 'market') {
const selectedPoolId = selectedPoolCalculation?.pool.poolId;
if (selectedPoolId !== prevSelectedPoolId) {
setPrevSelectedPoolId(selectedPoolId);
resetLimitPrice();
}
}

return (
<>
<Box
Expand Down Expand Up @@ -115,23 +102,23 @@ export const CreateSwapOrder = ({
store={swapStore}
onClose={() => setOpenedDialog('')}
onTokenInfoChanged={val => {
resetLimitPrice();
onChangeLimitPrice();
sellTokenInfoChanged(val);
}}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
)}
{openedDialog === 'to' && (
<SelectBuyTokenFromList
store={swapStore}
onClose={() => setOpenedDialog('')}
onTokenInfoChanged={val => {
resetLimitPrice();
onChangeLimitPrice();
buyTokenInfoChanged(val);
}}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
)}
{openedDialog === 'slippage' && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ function SwapPage(props: StoresAndActionsProps): Node {
},
frontendFeeTiersChanged,
} = useSwap();
const { sellTokenInfo, buyTokenInfo } = useSwapForm();
const {
sellTokenInfo,
buyTokenInfo,
resetSwapForm,
sellQuantity,
buyQuantity,
} = useSwapForm();

const isMarketOrder = orderType === 'market';
const impact = isMarketOrder ? Number(selectedPoolCalculation?.prices.priceImpact ?? 0) : 0;
Expand All @@ -71,25 +77,30 @@ function SwapPage(props: StoresAndActionsProps): Node {
);

const swapFormCanContinue =
selectedPoolCalculation != null &&
sell.quantity !== '0' &&
buy.quantity !== '0' &&
isValidTickers;
selectedPoolCalculation != null
&& sell.quantity !== '0'
&& buy.quantity !== '0'
&& sellQuantity.error == null
&& buyQuantity.error == null
&& isValidTickers;

const confirmationCanContinue = userPasswordState.value !== '' && signRequest != null;

const isButtonLoader = orderStep === 1 && signRequest == null;

const isSwapEnabled =
(orderStep === 0 && swapFormCanContinue) || (orderStep === 1 && confirmationCanContinue);
(orderStep === 0 && swapFormCanContinue)
|| (orderStep === 1 && confirmationCanContinue);

const wallet = props.stores.wallets.selectedOrFail;
const network = wallet.getParent().getNetworkInfo();
const defaultTokenInfo = props.stores.tokenInfoStore.getDefaultTokenInfoSummary(
network.NetworkId
);
const getTokenInfoBatch: Array<string> => { [string]: Promise<RemoteTokenInfo> } = ids =>
props.stores.tokenInfoStore.fetchMissingAndGetLocalOrRemoteMetadata(network, ids);
const getTokenInfo: string => Promise<RemoteTokenInfo> = id =>
props.stores.tokenInfoStore.getLocalOrRemoteMetadata(network, id);
getTokenInfoBatch([id])[id].then(res => res ?? {});

const disclaimerFlag = props.stores.substores.ada.swapStore.swapDisclaimerAcceptanceFlag;

Expand Down Expand Up @@ -237,6 +248,7 @@ function SwapPage(props: StoresAndActionsProps): Node {
refreshWallet: () => props.stores.wallets.refreshWalletFromRemote(wallet),
});
setOrderStepValue(2);
resetSwapForm();
} catch (e) {
handleTransactionError(e);
} finally {
Expand Down Expand Up @@ -323,6 +335,7 @@ function SwapPage(props: StoresAndActionsProps): Node {
onSetNewSlippage={onSetNewSlippage}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
priceImpactState={priceImpactState}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type Props = {|
onClose(): void,
onTokenInfoChanged: * => void,
defaultTokenInfo: RemoteTokenInfo,
getTokenInfo: string => Promise<RemoteTokenInfo>,
getTokenInfoBatch: Array<string> => { [string]: Promise<RemoteTokenInfo> },
|};

export default function SelectBuyTokenFromList({ store, onClose, onTokenInfoChanged, defaultTokenInfo, getTokenInfo }: Props): Node {
export default function SelectBuyTokenFromList({ store, onClose, onTokenInfoChanged, defaultTokenInfo, getTokenInfoBatch }: Props): Node {
const {
sellQuantity: { isTouched: isSellTouched },
buyQuantity: { isTouched: isBuyTouched },
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function SelectBuyTokenFromList({ store, onClose, onTokenInfoChan
onAssetSelected={handleAssetSelected}
onClose={onClose}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type Props = {|
onClose(): void,
onTokenInfoChanged: * => void,
defaultTokenInfo: RemoteTokenInfo,
getTokenInfo: string => Promise<RemoteTokenInfo>,
getTokenInfoBatch: Array<string> => { [string]: Promise<RemoteTokenInfo> },
|};

export default function SelectSellTokenFromList({ store, onClose, onTokenInfoChanged, defaultTokenInfo, getTokenInfo }: Props): Node {
export default function SelectSellTokenFromList({ store, onClose, onTokenInfoChanged, defaultTokenInfo, getTokenInfoBatch }: Props): Node {
const { onlyVerifiedTokens } = useSwapTokensOnlyVerified();
const assets = store.assets;
const walletVerifiedAssets = useMemo(() => {
Expand Down Expand Up @@ -62,7 +62,7 @@ export default function SelectSellTokenFromList({ store, onClose, onTokenInfoCha
onAssetSelected={handleAssetSelected}
onClose={onClose}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
);
}
Loading

0 comments on commit 5434901

Please sign in to comment.