Skip to content

Commit

Permalink
Merge branch 'develop' into denis/yoext-1200/make-tests-great-again
Browse files Browse the repository at this point in the history
  • Loading branch information
Nebyt authored Jun 20, 2024
2 parents 265450f + d1dd8f4 commit 2844857
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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 +37,7 @@ export default function SelectAssetDialog({
onAssetSelected,
onClose,
defaultTokenInfo,
getTokenInfo,
getTokenInfoBatch,
}: Props): React$Node {
const [searchTerm, setSearchTerm] = useState<string>('');

Expand All @@ -55,6 +55,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 +130,7 @@ export default function SelectAssetDialog({
type={type}
onAssetSelected={handleAssetSelected}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfo={id => metadataPromiseMap[id]}
/>
);
})}
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,6 +34,7 @@ export const CreateSwapOrder = ({
swapStore,
defaultTokenInfo,
getTokenInfo,
getTokenInfoBatch,
priceImpactState,
}: Props): React$Node => {
const [openedDialog, setOpenedDialog] = useState('');
Expand Down Expand Up @@ -119,7 +121,7 @@ export const CreateSwapOrder = ({
sellTokenInfoChanged(val);
}}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
)}
{openedDialog === 'to' && (
Expand All @@ -131,7 +133,7 @@ export const CreateSwapOrder = ({
buyTokenInfoChanged(val);
}}
defaultTokenInfo={defaultTokenInfo}
getTokenInfo={getTokenInfo}
getTokenInfoBatch={getTokenInfoBatch}
/>
)}
{openedDialog === 'slippage' && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ function SwapPage(props: StoresAndActionsProps): Node {
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 @@ -323,6 +325,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}
/>
);
}
5 changes: 5 additions & 0 deletions packages/yoroi-extension/app/i18n/locales/hu-HU.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@
"buysell.dialog.currentBalance": "Current balance: {amount} ADA",
"buysell.dialog.disclaimer": "Disclaimer",
"buysell.dialog.disclaimerText": "Yoroi Wallet utilizes third-party web3 on-and-off ramp solutions for direct Fiat-ADA exchanges. By clicking \"Proceed,\" you acknowledge that you will be redirected to our partner's website, where you may need to accept their terms and conditions. Please note, the third party web3 solution may have limitations based on your location and financial institution.",
"buysell.dialog.error.dialog.title": "url generation",
"buysell.dialog.error.minimum": "Minimum {amount} ADA required",
"buysell.dialog.error.not.enough": "Not enough balance",
"buysell.dialog.fail.text": "This service is currently unavailable. Please try again later.",
"buysell.dialog.longloading.text": "We are redirecting you outside Yoroi. Please wait.",
"buysell.dialog.proceed": "PROCEED",
"buysell.dialog.provider": "Provider",
"buysell.dialog.providerFee": "Provider fee",
Expand Down Expand Up @@ -949,6 +952,8 @@
"wallet.transaction.type.stakeKeyRegistered": "Staking key registered",
"wallet.transaction.withdraw": "Withdraw",
"wallet.transaction.withdrawalsLabel": "Withdrawals",
"wallet.transactions.success.button.exchange": "Go to the exchange page",
"wallet.transactions.success.sell": "Transaction has been submitted",
"wallet.transfer.deregister.deregister": "Deregister",
"wallet.transfer.deregister.keep": "Keep registered",
"wallet.transfer.deregister.line1": "When withdrawing rewards, you also have the option to deregister the staking key",
Expand Down
5 changes: 5 additions & 0 deletions packages/yoroi-extension/app/i18n/locales/vi-VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@
"buysell.dialog.currentBalance": "Current balance: {amount} ADA",
"buysell.dialog.disclaimer": "Disclaimer",
"buysell.dialog.disclaimerText": "Yoroi Wallet utilizes third-party web3 on-and-off ramp solutions for direct Fiat-ADA exchanges. By clicking \"Proceed,\" you acknowledge that you will be redirected to our partner's website, where you may need to accept their terms and conditions. Please note, the third party web3 solution may have limitations based on your location and financial institution.",
"buysell.dialog.error.dialog.title": "url generation",
"buysell.dialog.error.minimum": "Minimum {amount} ADA required",
"buysell.dialog.error.not.enough": "Not enough balance",
"buysell.dialog.fail.text": "This service is currently unavailable. Please try again later.",
"buysell.dialog.longloading.text": "We are redirecting you outside Yoroi. Please wait.",
"buysell.dialog.proceed": "PROCEED",
"buysell.dialog.provider": "Provider",
"buysell.dialog.providerFee": "Provider fee",
Expand Down Expand Up @@ -949,6 +952,8 @@
"wallet.transaction.type.stakeKeyRegistered": "Đăng ký khóa đặt cược",
"wallet.transaction.withdraw": "Rút",
"wallet.transaction.withdrawalsLabel": "Rút",
"wallet.transactions.success.button.exchange": "Go to the exchange page",
"wallet.transactions.success.sell": "Transaction has been submitted",
"wallet.transfer.deregister.deregister": "Hủy đăng ký",
"wallet.transfer.deregister.keep": "Giữ đăng ký",
"wallet.transfer.deregister.line1": "Khi rút phần thưởng, bạn cũng có tùy chọn hủy đăng ký đặt cược",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ export default class TokenInfoStore<
return { name: undefined, ticker: undefined, decimals: undefined, logo: undefined };
}

fetchMissingAndGetLocalOrRemoteMetadata(network: $ReadOnly<NetworkRow>, tokenIds: Array<string>): { [string]: Promise<RemoteTokenInfo> } {
const fetchPromise = this.fetchMissingTokenInfo(network.NetworkId, tokenIds);
return tokenIds.reduce((res, id) => {
res[id] = fetchPromise.then(() => this.getLocalOrRemoteMetadata(network, id));
return res;
}, {});
}

fetchMissingTokenInfo: (networkId: number, tokenIds: Array<string>) => Promise<void> = async (
networkId,
tokenIds
Expand Down

0 comments on commit 2844857

Please sign in to comment.