Skip to content

Commit c5b1781

Browse files
committed
feat: scroll to order with tx hash
1 parent fef14cd commit c5b1781

File tree

7 files changed

+86
-34
lines changed

7 files changed

+86
-34
lines changed

web-marketplace/src/components/molecules/DenomIcon/DenomIcon.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const DenomIcon = ({
4242
<GravUsdcIcon sx={iconSx} className={className} />
4343
)}
4444
{baseDenom === AXELAR_USDC_DENOM &&
45-
// On mainnet, AXELAR_USDC_DENOM and USDC_DENOM baseDenom have the same value: uusd
45+
// On mainnet, AXELAR_USDC_DENOM and USDC_DENOM have the same value: uusd
4646
// so we also use the bank denom to check whether it's USDC.axl (IBC) or native USDC
4747
ibcDenom && <AxlUsdcIcon sx={iconSx} className={className} />}
4848
{baseDenom === EEUR_DENOM && (

web-marketplace/src/components/organisms/Order/Order.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const Order = ({ orderData, allowedDenoms, className }: OrderProps) => {
7272
const pricePerCredits = +displayTotalPrice / +credits.credits;
7373

7474
return (
75-
<>
75+
<div id={blockchainDetails.blockchainRecord}>
7676
<Card
7777
className={cn(
7878
'bg-grey-100 border-[1px] border-bc-neutral-300',
@@ -212,6 +212,6 @@ export const Order = ({ orderData, allowedDenoms, className }: OrderProps) => {
212212
}}
213213
/>
214214
)}
215-
</>
215+
</div>
216216
);
217217
};

web-marketplace/src/config/allowedBaseDenoms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const EVMOS_DENOM = 'atevmos';
1010
export const USD_DENOM = 'usd';
1111
export const USDC_DENOM = 'uusdc';
1212

13-
export const USD_DENOMS = [GRAVITY_USDC_DENOM, AXELAR_USDC_DENOM];
13+
export const USD_DENOMS = [GRAVITY_USDC_DENOM, AXELAR_USDC_DENOM, USDC_DENOM];
1414
export const EUR_DENOMS = [EEUR_DENOM];
1515
export const UPPERCASE_DENOM = [
1616
REGEN_DENOM,

web-marketplace/src/lib/queries/react-query/ecocredit/marketplace/getSellOrdersExtendedQuery/getSellOrdersExtendedQuery.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ export const getSellOrdersExtendedQuery = ({
5656
query: denomTracesQuery,
5757
reactQueryClient,
5858
});
59-
console.log('ibcDenomHashes', ibcDenomHashes);
60-
console.log('denomTraces', denomTraces);
6159

6260
// get prices to compute AskUsdAmount
6361
const simplePriceData =

web-marketplace/src/pages/BuyCredits/BuyCredits.utils.tsx

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,16 @@ import { UseFormSetValue } from 'react-hook-form';
22
import { i18n } from '@lingui/core';
33
import { msg, plural, Trans } from '@lingui/macro';
44
import { QueryAllowedDenomsResponse } from '@regen-network/api/lib/generated/regen/ecocredit/marketplace/v1/query';
5-
import { USD_DENOM } from 'config/allowedBaseDenoms';
5+
import {
6+
AXELAR_USDC_DENOM,
7+
EEUR_DENOM,
8+
EVMOS_DENOM,
9+
GRAVITY_USDC_DENOM,
10+
REGEN_DENOM,
11+
USD_DENOM,
12+
USDC_DENOM,
13+
} from 'config/allowedBaseDenoms';
14+
import { IBC_DENOM_PREFIX } from 'utils/ibc/getDenomTrace';
615

716
import { getFormattedNumber } from 'web-components/src/utils/format';
817

@@ -373,3 +382,27 @@ export function resetCurrencyAndCredits(
373382
activeStep,
374383
);
375384
}
385+
386+
export const getCryptoCurrencyIconSrc = (
387+
baseDenom: string,
388+
bankDenom: string,
389+
) => {
390+
const ibcDenom = bankDenom?.includes(IBC_DENOM_PREFIX);
391+
392+
let href = '';
393+
if (baseDenom === GRAVITY_USDC_DENOM)
394+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/usdc.grv.png';
395+
// On mainnet, AXELAR_USDC_DENOM and USDC_DENOM base denoms have the same value: uusd
396+
// so we also use the bank denom to check whether it's USDC.axl (IBC) or native USDC
397+
if (baseDenom === AXELAR_USDC_DENOM && ibcDenom)
398+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/usdc.axl.png';
399+
if (baseDenom === USDC_DENOM && !ibcDenom)
400+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/uusdc.png';
401+
if (baseDenom === EEUR_DENOM)
402+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/eeur.png';
403+
if (baseDenom === REGEN_DENOM)
404+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/regen.png';
405+
if (baseDenom === EVMOS_DENOM)
406+
href = 'https://regen-registry.s3.us-east-1.amazonaws.com/evmos.png';
407+
return href;
408+
};

web-marketplace/src/pages/BuyCredits/hooks/usePurchase.ts

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ import { useMsgClient } from 'hooks';
4040

4141
import { EMAIL_RECEIPT, PAYMENT_OPTIONS } from '../BuyCredits.constants';
4242
import { BuyCreditsSchemaTypes, PaymentOptionsType } from '../BuyCredits.types';
43-
import { getCardItems, getSteps } from '../BuyCredits.utils';
43+
import {
44+
getCardItems,
45+
getCryptoCurrencyIconSrc,
46+
getSteps,
47+
} from '../BuyCredits.utils';
4448
import { useFetchRetirementForPurchase } from './useFetchRetirementForPurchase';
4549

4650
type UsePurchaseParams = {
@@ -308,6 +312,37 @@ export const usePurchase = ({
308312
const _txHash = deliverTxResponse?.transactionHash;
309313
setTxHash(_txHash);
310314

315+
// Send purchase confirmation if email provided
316+
if (email && token) {
317+
const currencyIconSrc = getCryptoCurrencyIconSrc(
318+
currency.askBaseDenom,
319+
currency.askDenom,
320+
);
321+
const amountLabel = retiring
322+
? _(msg`amount retired`)
323+
: _(msg`amount tradable`);
324+
325+
await postData({
326+
url: `${apiUri}/marketplace/v1/confirm-crypto-order`,
327+
data: {
328+
email,
329+
currencyAmount,
330+
currencyIconSrc,
331+
displayDenom,
332+
projectName: project?.name,
333+
amountLabel,
334+
creditsAmount,
335+
txHref: getHashUrl(_txHash),
336+
txHash: truncate(_txHash),
337+
orderHref: `${
338+
window.location.origin
339+
}/dashboard/admin/my-orders#${_txHash?.toLowerCase()}`,
340+
},
341+
token,
342+
retryCsrfRequest,
343+
});
344+
}
345+
311346
// In case of retirement, it's handled in useFetchRetirementForPurchase
312347
if (!retiring) {
313348
setProcessingModalAtom(atom => void (atom.open = false));
@@ -339,31 +374,7 @@ export const usePurchase = ({
339374

340375
// Reset BuyCredits forms
341376
handleSuccess();
342-
343-
// Send purchase confirmation if email provided
344-
if (email && token) {
345-
let currencyIconSrc;
346-
await postData({
347-
url: `${apiUri}/marketplace/v1/confirm-crypto-order`,
348-
data: {
349-
email,
350-
currencyAmount,
351-
currencyIconSrc,
352-
displayDenom,
353-
projectName,
354-
amountLabel: retiring
355-
? _(msg`amount retired`)
356-
: _(msg`amount tradable`),
357-
creditsAmount,
358-
txHref: getHashUrl(_txHash),
359-
txHash: truncate(_txHash),
360-
},
361-
token,
362-
retryCsrfRequest,
363-
});
364-
}
365-
366-
navigate(`/profile/portfolio`);
377+
navigate(`/dashboard/portfolio`);
367378
}
368379
},
369380
},

web-marketplace/src/pages/Orders/Orders.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useEffect } from 'react';
2+
import { useLocation } from 'react-router-dom';
13
import { useQuery } from '@tanstack/react-query';
24

35
import { Flex } from 'web-components/src/components/box';
@@ -11,8 +13,9 @@ import { Order } from 'components/organisms/Order/Order';
1113
import { useOrders } from './hooks/useOrders';
1214

1315
export const Orders = () => {
14-
const { marketplaceClient } = useLedger();
16+
const location = useLocation();
1517

18+
const { marketplaceClient } = useLedger();
1619
const { orders, isLoading } = useOrders();
1720

1821
const { data: allowedDenomsData } = useQuery(
@@ -23,6 +26,13 @@ export const Orders = () => {
2326
);
2427
const allowedDenoms = allowedDenomsData?.allowedDenoms;
2528

29+
useEffect(() => {
30+
if (!isLoading) {
31+
const element = document.getElementById(location.hash.substring(1));
32+
if (element) element.scrollIntoView({ behavior: 'smooth' });
33+
}
34+
}, [isLoading, location.hash]);
35+
2636
return (
2737
<div className="flex flex-col justify-start items-center lg:items-start lg:flex-row lg:justify-evenly mx-auto">
2838
<Flex

0 commit comments

Comments
 (0)