Skip to content

Commit

Permalink
[DEV-634] Execution fee in spf (#731)
Browse files Browse the repository at this point in the history
* add execution fee asset into settings

* remove unnecessary

* replace swap action form with operation form

* remove old deps

* fix ergo swap fees display

* fix warnings

* fix cardano swap info

* fix OperationSettings.tsx

* update ido notification

* update deps and fix params

* Spf modal (#739)

* add amplitude and firstlaunch / session start events

* update analytics

* add events

* update event

* update analytics

* add redeem close confirm / swap close confirm

* fix after review

* update ci

* update request modal

* add spf modal

* add spf modal all states

* add claim spf notification

* update names & add polling & add request

* some fixes

* fix spf modal

* update spf status view

* fix modal styles

* update filter fns

* spf modal fixes

* fix spf links

* remove claim button from mobile devices

* new spf button logic

* some fixes

* add polling to reward

* add polling disabling on last stage

* ClaimSpfButton.tsx

* update paddings

* spf design fixes

* fix spf screens

* fix notification z-index

* fix build analytics methods

* update urls and comment amplitude analytics

* update version

* remove ido notification

---------

Co-authored-by: deadit <stdeadit@gmail.com>

* update spf id

* fix nothing to claim state links

* add to variable to CurrencyConverter.ts

* enable cardano update screen

* update version

* Update links to pp and tos (#740)

* update links

* fix claim spf styles

---------

Co-authored-by: ridel1e <ridellee@gmail.com>

* update cardano sdk and remove and remove cardano update page

* fix CurrencyConverter.ts

* remove old files

* add new ergo execution

* fix swap info content

* update confirmations

* add swap validators

* update libs and rename pool actions

* fix warnings

* add walletSwap switch

* add swap operation

* fix cardano swap info

* fix cardano swap validators

* add remove liquidity fee switcher

* switch logger

* add spf fee remove liquidity

* fix warnings

* fix fees order

* remove old redeem validator fee

* add validators to cardano network

* add deposit validators

* add native deposit max button click

* fix warnings and add maxLiquidity spf button

* add deposit operation switcher

* fix streams

* add spf deposit operation

---------

Co-authored-by: ridel1e <ridellee@gmail.com>
Co-authored-by: yb <43601702+yasha-black@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 27, 2023
1 parent 02fc01c commit a30997d
Show file tree
Hide file tree
Showing 90 changed files with 2,667 additions and 841 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ergo-dex-frontend",
"version": "3.2.3",
"version": "3.3.2",
"private": false,
"scripts": {
"start": "HTTPS=true react-app-rewired start",
Expand All @@ -22,9 +22,9 @@
"@babel/plugin-syntax-typescript": "^7.16.7",
"@babel/preset-env": "^7.15.6",
"@emurgo/cardano-serialization-lib-nodejs": "^11.0.5",
"@ergolabs/cardano-dex-sdk": "^0.0.69",
"@ergolabs/ergo-dex-sdk": "^1.9.50",
"@ergolabs/ergo-sdk": "^0.5.5",
"@ergolabs/cardano-dex-sdk": "^0.0.70",
"@ergolabs/ergo-dex-sdk": "^1.9.52",
"@ergolabs/ergo-sdk": "^0.5.6",
"@ergolabs/ui-kit": "^2.4.21",
"@rehooks/local-storage": "2.4.0",
"@sentry/react": "^6.16.1",
Expand Down
8 changes: 4 additions & 4 deletions src/applicationConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ export const applicationConfig: ApplicationConfig = {
cardanoMaintenance: false,
defaultTokenListUrl:
'https://raw.githubusercontent.com/ergolabs/default-token-list/master/src/tokens',
cardanoUpdate: {
title: 'Under Maintenance',
content: 'We are migrating the protocol to Vasil Hard Fork testnet.',
},
// cardanoUpdate: {
// title: 'Under Maintenance',
// content: 'We are migrating the protocol to Vasil Hard Fork testnet.',
// },
reCaptchaKey: '6LfCKZIiAAAAACypYW5pGlgZNTcwse1njmQMIUUL',
requestRetryCount: 3,
networksSettings: {
Expand Down
4 changes: 4 additions & 0 deletions src/common/analytics/@types/userProperties.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export type userProperties = {
set?: Record<string, any>;
setOnce?: Record<string, any>;
};
2 changes: 2 additions & 0 deletions src/common/constants/erg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ export const MIN_NITRO = 1.2;

export const UI_FEE = 0;
export const UI_FEE_BIGINT = 0n;

export const NEW_MIN_BOX_VALUE = 250000n;
89 changes: 63 additions & 26 deletions src/common/services/CurrencyConverter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ const getRatioFromGraph = (
};

interface SnapshotFunction {
(from: Currency | Currency[]): Currency;
(from: Currency | Currency[], to?: AssetInfo): Currency;
}

interface RateFunction {
(from: AssetInfo): Observable<Ratio>;
(from: AssetInfo, to?: AssetInfo): Observable<Ratio>;
}

export type CurrencyConverter = ((
from: Currency | Currency[],
to?: AssetInfo,
) => Observable<Currency>) & {
snapshot: SnapshotFunction;
rate: RateFunction;
Expand All @@ -58,46 +59,60 @@ export const makeCurrencyConverter = (

const emptyConvenientAssetCurrency = new Currency(0n, convenientAsset);

const createRateStream = (fromAsset: AssetInfo): Observable<Ratio> => {
const toHash = (from: AssetInfo, to?: AssetInfo): string =>
to ? `${from.id}-${to.id}` : from.id;

const createRateStream = (
fromAsset: AssetInfo,
to?: AssetInfo,
): Observable<Ratio> => {
return combineLatest([
assetGraph$,
networkAssetToConvenientAssetRatio$,
]).pipe(
debounceTime(100),
map(([graph, networkAssetRatio]) => {
if (fromAsset.id === networkAssetRatio.baseAsset.id) {
if (
fromAsset.id === networkAssetRatio.baseAsset.id &&
(!to || to.id === networkAssetRatio.quoteAsset.id)
) {
return networkAssetRatio;
}

const toNetworkAssetRatio: Ratio | undefined = getRatioFromGraph(
graph,
fromAsset,
networkAssetRatio.baseAsset,
to || networkAssetRatio.baseAsset,
);

if (!toNetworkAssetRatio) {
return new Ratio('0', fromAsset, networkAssetRatio.quoteAsset);
}
if (to) {
return toNetworkAssetRatio;
}
return toNetworkAssetRatio.cross(networkAssetRatio);
}),
tap((ratio) => ratioSnapshotCache.set(fromAsset.id, ratio)),
tap((ratio) => ratioSnapshotCache.set(toHash(fromAsset, to), ratio)),
publishReplay(1),
refCount(),
);
};

const rate = (from: AssetInfo): Observable<Ratio> => {
if (!ratioStreamCache.has(from.id)) {
ratioStreamCache.set(from.id, createRateStream(from));
const rate = (from: AssetInfo, to?: AssetInfo): Observable<Ratio> => {
const hash = toHash(from, to);

if (!ratioStreamCache.has(hash)) {
ratioStreamCache.set(hash, createRateStream(from, to));
}
return ratioStreamCache.get(from.id)!;
return ratioStreamCache.get(hash)!;
};

const convert: CurrencyConverter = ((
from: Currency | Currency[],
to?: AssetInfo,
): Observable<Currency> => {
if (from instanceof Currency) {
return rate(from.asset).pipe(
return rate(from.asset, to).pipe(
map((convenientAssetRate) => convenientAssetRate.toQuoteCurrency(from)),
);
}
Expand All @@ -108,7 +123,7 @@ export const makeCurrencyConverter = (

return combineLatest(
from.map((i) =>
rate(i.asset).pipe(
rate(i.asset, to).pipe(
map((convenientAssetRate) => convenientAssetRate.toQuoteCurrency(i)),
),
),
Expand All @@ -122,22 +137,44 @@ export const makeCurrencyConverter = (
);
}) as any;

convert.snapshot = (from: Currency | Currency[]): Currency => {
if (from instanceof Currency && ratioSnapshotCache.has(from.asset.id)) {
return ratioSnapshotCache.get(from.asset.id)!.toQuoteCurrency(from);
const convertSnapshotWithSingleCurrency = (
from: Currency,
to?: AssetInfo,
): Currency => {
const hash = toHash(from.asset, to);

if (ratioSnapshotCache.has(hash)) {
return ratioSnapshotCache.get(hash)!.toQuoteCurrency(from);
}
if (from instanceof Array) {
return from.reduce((acc, item) => {
if (ratioSnapshotCache.has(item.asset.id)) {
return acc.plus(
ratioSnapshotCache.get(item.asset.id)!.toQuoteCurrency(item),
);
}
return acc;
}, emptyConvenientAssetCurrency);
return to ? new Currency(0n, to) : emptyConvenientAssetCurrency;
};

const convertSnapshotWithMultipleCurrencies = (
from: Currency[],
to?: AssetInfo,
): Currency => {
if (from.some((i) => !ratioSnapshotCache.has(toHash(i.asset, to)))) {
return to ? new Currency(0n, to) : emptyConvenientAssetCurrency;
}
return from.reduce<Currency>(
(sum, i) => {
return sum.plus(
ratioSnapshotCache.get(toHash(i.asset, to))!.toQuoteCurrency(i),
);
},
to ? new Currency(0n, to) : emptyConvenientAssetCurrency,
);
};

return emptyConvenientAssetCurrency;
convert.snapshot = (
from: Currency | Currency[],
to?: AssetInfo,
): Currency => {
if (from instanceof Array) {
return convertSnapshotWithMultipleCurrencies(from, to);
} else {
return convertSnapshotWithSingleCurrency(from, to);
}
};

convert.rate = rate;
Expand Down
4 changes: 3 additions & 1 deletion src/components/ConvenientAssetView/ConvenientAssetView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { formatToUSD } from '../../services/number';
export interface ConvenientAssetViewProps {
readonly value: Currency | Currency[] | undefined;
readonly prefix?: string;
readonly hidePrefix?: boolean;
readonly defaultValue?: string;
readonly type?: 'abbr' | 'default';
}

export const ConvenientAssetView: FC<ConvenientAssetViewProps> = ({
value,
prefix,
hidePrefix,
type,
}) => {
const [selectedNetwork] = useSelectedNetwork();
Expand All @@ -37,7 +39,7 @@ export const ConvenientAssetView: FC<ConvenientAssetViewProps> = ({
{isConvenientValueLoading ? (
<LoadingOutlined />
) : value && convenientValue?.toString() !== '0' ? (
`${prefix || '~'}${
`${hidePrefix ? '' : prefix || '~'}${
convenientValue
? convenientValue.asset.ticker === 'ADA'
? convenientValue.toCurrencyString()
Expand Down
Loading

0 comments on commit a30997d

Please sign in to comment.