Skip to content

Commit

Permalink
Merge pull request #363 from ergolabs/dev
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
yasha-black authored Feb 2, 2022
2 parents e54ebc7 + 04a30cb commit 0609a07
Show file tree
Hide file tree
Showing 179 changed files with 5,319 additions and 1,611 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"@babel/core": "^7.15.5",
"@babel/preset-env": "^7.15.6",
"@craco/craco": "^6.3.0",
"@ergolabs/ergo-dex-sdk": "1.2.2",
"@ergolabs/ergo-sdk": "^0.1.16",
"@ergolabs/ergo-dex-sdk": "^1.3.11",
"@ergolabs/ergo-sdk": "^0.1.27",
"@rehooks/local-storage": "2.4.0",
"@sentry/react": "^6.16.1",
"@sentry/tracing": "^6.16.1",
Expand All @@ -38,10 +38,12 @@
"@types/react": "^17.0.17",
"@types/react-dom": "^17.0.9",
"@types/react-router-dom": "^5.1.8",
"@types/recharts": "^1.8.23",
"antd": "^4.17.0-alpha.5",
"axios": "^0.24.0",
"bignumber.js": "^9.0.1",
"craco-less": "^1.20.0",
"decorator-cache-getter": "^1.0.0",
"eslint-plugin-react-hooks": "^4.2.0",
"fast-levenshtein": "^3.0.0",
"i18next": "^21.5.3",
Expand All @@ -55,10 +57,13 @@
"react": "^17.0.2",
"react-app-rewired": "^2.1.8",
"react-copy-to-clipboard": "^5.0.3",
"react-device-detect": "^2.1.2",
"react-dom": "^17.0.2",
"react-flip-numbers": "^3.0.5",
"react-i18next": "^11.14.3",
"react-router-dom": "^5.2.0",
"react-scripts": "4.0.3",
"recharts": "^2.1.8",
"rxjs": "^7.4.0",
"storybook-preset-craco": "^0.0.6",
"typescript": "^4.3.5",
Expand Down
40 changes: 2 additions & 38 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,17 @@
<meta name="theme-color" content="#000000"/>
<meta
name="description"
content="Web site created using create-react-app"
content="Provide liquidity, swap and exchange assets on top of Ergo and Cardano blockchains"
/>
<meta property="og:image" content="https://adapulse.io/wp-content/uploads/2021/06/2021-06-27-21.13.19-800x395.jpg">
<link rel="apple-touch-icon" href="%PUBLIC_URL%/apple-touch-icon.png"/>
<link rel="manifest" href="%PUBLIC_URL%/manifest.json"/>
<title>ErgoDEX</title>
<style>
#root {height: 100%}
</style>
<!-- <style>-->
<!-- body {-->
<!-- position: relative;-->
<!-- margin: 0;-->
<!-- }-->

<!-- .loader {-->
<!-- position: absolute;-->
<!-- z-index: 1000;-->
<!-- display: flex;-->
<!-- width: 100%;-->
<!-- height: 100vh;-->
<!-- align-items: center;-->
<!-- justify-content: center;-->
<!-- background: rebeccapurple;-->
<!-- }-->

<!-- .logo {-->

<!-- }-->

<!-- .text {-->

<!-- }-->
<!-- </style>-->
</head>
<body>
<!--<div class="loader">-->
<!-- <svg width="98" height="92" viewBox="0 0 98 92" fill="none" xmlns="http://www.w3.org/2000/svg">-->
<!-- <path d="M27.4079 82.0442C22.7532 81.5355 18.3569 80.1847 14.3796 78.1512C16.9374 81.7194 20.3045 84.8125 24.4031 87.1382L24.4001 87.1428C28.5012 89.4686 32.9142 90.7862 37.3425 91.1759C33.568 88.8102 30.1833 85.7474 27.4079 82.0442ZM66.0327 14.5481C61.9795 14.5481 58.1046 15.2989 54.5443 16.6662C55.7483 17.5909 56.8931 18.5864 57.9725 19.647C59.287 20.939 60.5038 22.3278 61.6114 23.8C63.4587 24.0062 65.2863 24.3469 67.0777 24.8188C68.5557 25.208 70.009 25.6864 71.4295 26.2509C70.8564 22.5319 69.582 18.8554 67.5558 15.4031L67.5508 15.406C67.3833 15.1216 67.2124 14.8413 67.0376 14.5639C66.704 14.554 66.3689 14.5481 66.0327 14.5481ZM48.8065 19.5683C46.9626 20.7497 45.2519 22.1154 43.7018 23.6389L43.6213 23.7192C45.3543 23.8758 47.0851 24.1526 48.8014 24.5541C50.5205 24.1521 52.2546 23.8747 53.9902 23.718L53.9107 23.6389C52.3608 22.1154 50.6501 20.75 48.8065 19.5683ZM39.6402 19.647C40.7194 18.5864 41.8646 17.5912 43.0685 16.6662C39.5081 15.2987 35.6333 14.5481 31.5804 14.5481C31.2414 14.5481 30.9043 14.554 30.5683 14.5645C30.3962 14.8378 30.227 15.1144 30.0625 15.3947C28.0334 18.849 26.7573 22.529 26.1838 26.2509C27.6045 25.686 29.058 25.2074 30.5359 24.8182C32.3276 24.3466 34.155 24.0059 36.0019 23.7996C37.1089 22.3275 38.3257 20.939 39.6402 19.647ZM48.8065 13.0354C53.0057 10.8841 57.6733 9.49449 62.619 9.05373C58.737 5.20507 53.9537 2.49315 48.8054 1.06033C43.6527 2.4949 38.8676 5.20653 34.9865 9.05316C39.9352 9.49362 44.6052 10.8833 48.8065 13.0354ZM30.2617 35.0803C30.7677 33.4137 31.3915 31.7969 32.1226 30.2393L32.0167 30.2664C29.8984 30.8243 27.8396 31.5971 25.8763 32.5748C25.9963 34.7372 26.3448 36.878 26.9125 38.9612L26.9424 39.0681C27.945 37.6728 29.0523 36.3392 30.2617 35.0803ZM43.6234 67.4564L43.702 67.5346C45.2521 69.0581 46.9629 70.4235 48.8068 71.6052C50.6505 70.4235 52.3614 69.0581 53.9109 67.5346L53.9899 67.4564C52.2564 67.2992 50.5249 67.0224 48.8077 66.6207C47.0899 67.0224 45.3573 67.2998 43.6234 67.4564ZM39.6402 71.5265C38.3263 70.2349 37.1104 68.847 36.0033 67.3753C34.1562 67.1697 32.3282 66.829 30.5365 66.3573C29.0592 65.9682 27.6063 65.4895 26.1868 64.9257C26.7608 68.643 28.0358 72.3191 30.0631 75.7699L30.069 75.7908C30.2314 76.0671 30.3976 76.3395 30.5674 76.609C30.9039 76.6192 31.2414 76.6251 31.5804 76.6251C35.6336 76.6251 39.5081 75.8748 43.0685 74.5073C41.8646 73.5821 40.7194 72.5869 39.6402 71.5265ZM32.1234 60.9364C31.3925 59.3793 30.7692 57.763 30.2629 56.0977C29.0532 54.8381 27.9456 53.5042 26.9424 52.109L26.9127 52.2143C26.345 54.2973 25.9969 56.4378 25.8775 58.5999C27.8408 59.5782 29.8996 60.3518 32.0173 60.9089L32.1234 60.9364ZM54.5443 74.5073C58.1046 75.8748 61.9795 76.6251 66.0327 76.6251C66.3717 76.6251 66.7088 76.6196 67.0453 76.609C67.2175 76.3363 67.3857 76.0603 67.5499 75.7806L67.5502 75.78C69.579 72.3257 70.8552 68.646 71.4283 64.9245C70.0079 65.4889 68.5545 65.9676 67.0765 66.3567C65.2848 66.8284 63.4571 67.1691 61.6094 67.3747C60.5026 68.847 59.2861 70.2349 57.9723 71.5262C56.8931 72.5869 55.7483 73.5821 54.5443 74.5073ZM62.627 82.1204C58.7453 85.9688 53.9594 88.6807 48.8054 90.1153C43.6521 88.6807 38.8665 85.9682 34.9851 82.1204C39.9343 81.6806 44.6049 80.2906 48.8062 78.1381C53.0079 80.2906 57.6784 81.6802 62.627 82.1204ZM74.0787 75.6086C79.4173 74.2297 84.2042 71.5127 88.044 67.8432C89.354 62.7409 89.3552 57.3118 87.9045 52.0842C85.0417 56.0784 81.4811 59.3607 77.4827 61.8619C77.2771 66.5096 76.1656 71.1774 74.0787 75.6086ZM83.2343 78.1506C79.257 80.1847 74.8601 81.5355 70.205 82.0442C67.4288 85.7474 64.0436 88.8108 60.2688 91.1765C64.6977 90.7873 69.1115 89.4689 73.2132 87.1434L73.2102 87.1388C77.3088 84.813 80.6765 81.7198 83.2343 78.1506ZM94.7081 58.6062C96.5721 54.6467 97.6127 50.236 97.6127 45.5866C97.6127 40.9367 96.5715 36.5259 94.7075 32.5661C94.5092 36.962 93.5011 41.3739 91.6236 45.587C93.5011 49.7997 94.5092 54.2107 94.7081 58.6062ZM88.0423 23.3283C84.2024 19.6599 79.4167 16.9433 74.0783 15.5653C76.1659 19.9973 77.2777 24.6649 77.4833 29.3143C81.4817 31.815 85.042 35.0963 87.9042 39.0905C89.3552 33.8615 89.3531 28.4315 88.0423 23.3283ZM70.2124 9.12987C67.4374 5.42763 64.0519 2.36539 60.2754 0C64.7051 0.390293 69.1193 1.70935 73.2206 4.03681C77.3157 6.36048 80.6807 9.45336 83.2367 13.0237C79.2606 10.9906 74.8657 9.63976 70.2124 9.12987ZM21.3696 40.4169C20.9737 38.9647 20.6689 37.4891 20.4564 35.9985C17.4657 38.3456 14.8635 41.2689 12.8361 44.7197C12.6673 45.0073 12.5039 45.2967 12.3455 45.5872C12.5025 45.8754 12.6645 46.1624 12.8319 46.4477L12.8367 46.4448C14.8655 49.8985 17.4677 52.8239 20.4573 55.1724C20.6698 53.6833 20.9746 52.2088 21.3702 50.7588C21.8511 48.9948 22.4657 47.2656 23.2092 45.5881C22.4654 43.9102 21.8505 42.181 21.3696 40.4169ZM20.1296 29.3163C16.1337 31.8179 12.574 35.101 9.71061 39.0975C8.25813 33.8664 8.25902 28.4336 9.57112 23.3277C13.4107 19.6596 18.1964 16.9433 23.5344 15.5653C21.4465 19.9977 20.335 24.6666 20.1296 29.3163ZM65.4895 60.9358L65.5958 60.9083C67.7137 60.3512 69.7725 59.5768 71.7357 58.5988C71.6162 56.4372 71.2677 54.2968 70.7 52.2137L70.6698 52.1049C69.6677 53.4978 68.5613 54.83 67.3529 56.0878C66.8462 57.7569 66.2218 59.3761 65.4895 60.9358ZM77.1557 55.1722C76.9432 53.6827 76.6387 52.2085 76.2434 50.7584C75.7623 48.9939 75.1476 47.2654 74.4048 45.5878C75.1482 43.9097 75.7632 42.1814 76.2439 40.4175C76.6393 38.9671 76.9438 37.4929 77.1563 36.0037C80.1458 38.3522 82.7484 41.2777 84.7773 44.7311L84.7823 44.7285C84.949 45.0129 85.1106 45.2996 85.2675 45.5872C85.1108 45.8751 84.949 46.1618 84.7817 46.4472L84.7767 46.4442C82.7475 49.898 80.1452 52.8237 77.1557 55.1722ZM27.4087 9.12899C22.753 9.63801 18.3555 10.9889 14.3773 13.0235C16.9332 9.45366 20.298 6.36136 24.3924 4.03798C28.4952 1.71024 32.9106 0.390581 37.3413 0.000872389C33.5676 2.36537 30.1839 5.42734 27.4087 9.12899ZM20.129 61.861C20.3336 66.5096 21.4438 71.1762 23.5285 75.6068C18.1923 74.2279 13.4077 71.5116 9.56963 67.8444C8.25931 62.7415 8.25813 57.3126 9.70854 52.0848C12.5707 56.079 16.1311 59.3607 20.129 61.861ZM70.6712 39.0677L70.7008 38.9618C71.2689 36.8789 71.617 34.7387 71.737 32.5769C69.7734 31.5983 67.7146 30.8243 65.5964 30.2666L65.4905 30.2393C66.2212 31.7966 66.845 33.4126 67.3507 35.0785C68.5605 36.338 69.6683 37.672 70.6712 39.0677ZM5.98888 45.5872C4.1117 41.3739 3.10321 36.9614 2.90526 32.5655C1.04054 36.5253 0 40.9364 0 45.5866C0 50.2362 1.04054 54.6473 2.90496 58.6068C3.10351 54.2113 4.1117 49.8002 5.98888 45.5872Z" fill="url(#paint0_linear_1723_720)"/>-->
<!-- <defs>-->
<!-- <linearGradient id="paint0_linear_1723_720" x1="0" y1="0" x2="0" y2="91.1765" gradientUnits="userSpaceOnUse">-->
<!-- <stop stop-color="#FF8C00"/>-->
<!-- <stop offset="0.0001" stop-color="#FF8C00"/>-->
<!-- <stop offset="1" stop-color="#FF0080"/>-->
<!-- </linearGradient>-->
<!-- </defs>-->
<!-- </svg>-->
<!--</div>-->
<noscript>You should enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
Expand Down
50 changes: 37 additions & 13 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import './i18n';

import { RustModule } from '@ergolabs/ergo-sdk';
import React, { Suspense, useEffect, useState } from 'react';
import { BrowserView, MobileView } from 'react-device-detect';
import { withTranslation } from 'react-i18next';
import { Redirect, Route, Router, Switch } from 'react-router-dom';

import { TABLET_BRAKE_POINT } from './common/constants/screen';
import { initializeApp } from './common/streams/appTick';
import Layout from './components/common/Layout/Layout';
import { MobilePlug } from './components/MobilePlug/MobilePlug';
import {
Expand All @@ -16,18 +17,18 @@ import {
} from './context';
import { globalHistory } from './createBrowserHistory';
import { ContextModalProvider } from './ergodex-cdk';
import { useWindowSize } from './hooks/useWindowSize';
import { AddLiquidity } from './pages/Pool/AddLiquidity/AddLiquidity';
import { LockLiquidity } from './pages/Pool/LockLiquidity/LockLiquidity';
import { Pool } from './pages/Pool/Pool';
import { PoolPosition } from './pages/Pool/PoolPosition/PoolPosition';
import { Remove } from './pages/Remove/Remove';
import { RelockLiquidity } from './pages/Pool/RelockLiquidity/RelockLiquidity';
import { RemoveLiquidity } from './pages/Pool/RemoveLiquidity/RemoveLiquidity';
import { WithdrawalLiquidity } from './pages/Pool/WithdrawalLiquidity/WithdrawalLiquidity';
import { PoolOverview } from './pages/PoolOverview/PoolOverview';
import { Swap } from './pages/Swap/Swap';

const NotFound = () => <Redirect to="/swap" />;

const Application = withTranslation()(() => {
const [windowWidth] = useWindowSize();

return (
<Router history={globalHistory}>
<AppLoadingProvider>
Expand All @@ -36,7 +37,7 @@ const Application = withTranslation()(() => {
<WalletAddressesProvider>
<ContextModalProvider>
<Layout>
{windowWidth > TABLET_BRAKE_POINT ? (
<BrowserView>
<Switch>
<Route path="/" exact>
<Redirect to="/swap" />
Expand All @@ -45,21 +46,41 @@ const Application = withTranslation()(() => {
<Route path="/pool" exact component={Pool} />
<Route path="/pool/add" exact component={AddLiquidity} />
<Route
path="/pool/add/:poolId"
path="/pool/:poolId/remove"
exact
component={RemoveLiquidity}
/>
<Route
path="/pool/:poolId/lock"
exact
component={LockLiquidity}
/>
<Route
path="/pool/:poolId/relock"
exact
component={RelockLiquidity}
/>
<Route
path="/pool/:poolId/withdrawal"
exact
component={WithdrawalLiquidity}
/>
<Route
path="/pool/:poolId/add"
exact
component={AddLiquidity}
/>
<Route
path="/pool/:poolId"
exact
component={PoolPosition}
component={PoolOverview}
/>
<Route path="/remove/:poolId" exact component={Remove} />
<Route component={NotFound} />
</Switch>
) : (
</BrowserView>
<MobileView>
<MobilePlug />
)}
</MobileView>
</Layout>
</ContextModalProvider>
</WalletAddressesProvider>
Expand All @@ -74,7 +95,10 @@ export const ApplicationInitializer: React.FC = () => {
const [isRustModuleLoaded, setIsRustModuleLoaded] = useState(false);

useEffect(() => {
RustModule.load().then(() => setIsRustModuleLoaded(true));
RustModule.load().then(() => {
initializeApp();
setIsRustModuleLoaded(true);
});
}, []);

if (!isRustModuleLoaded) {
Expand Down
31 changes: 31 additions & 0 deletions src/api/ammPools.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { PoolId } from '@ergolabs/ergo-dex-sdk';
import { map, Observable, publishReplay, refCount, switchMap } from 'rxjs';

import { AmmPool } from '../common/models/AmmPool';
import { selectedNetwork$ } from '../network/network';

export const ammPools$ = selectedNetwork$.pipe(
switchMap((network) => network.ammPools$),
publishReplay(1),
refCount(),
);

export const getAmmPoolById = (
ammPoolId: PoolId,
): Observable<AmmPool | undefined> =>
ammPools$.pipe(
map((pools) => pools.find((position) => position.id === ammPoolId)),
);

const byAssetPair = (xId: string, yId: string) => (p: AmmPool) =>
(p.x.asset.id === xId || p.y.asset.id === xId) &&
(p.x.asset.id === yId || p.y.asset.id === yId);
export const getAmmPoolsByAssetPair = (
xId: string,
yId: string,
): Observable<AmmPool[]> =>
ammPools$.pipe(
map((pools) => pools.filter(byAssetPair(xId, yId))),
publishReplay(1),
refCount(),
);
14 changes: 14 additions & 0 deletions src/api/assetBalance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { publishReplay, refCount, switchMap } from 'rxjs';

import { useObservable } from '../common/hooks/useObservable';
import { Balance } from '../common/models/Balance';
import { selectedNetwork$ } from '../network/network';

export const assetBalance$ = selectedNetwork$.pipe(
switchMap((network) => network.assetBalance$),
publishReplay(1),
refCount(),
);

export const useAssetsBalance = (): [Balance, boolean, Error] =>
useObservable(assetBalance$, [], new Balance([]));
26 changes: 26 additions & 0 deletions src/api/explorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
from,
interval,
map,
Observable,
publishReplay,
refCount,
startWith,
switchMap,
} from 'rxjs';

import { explorer } from '../services/explorer';

const UPDATE_TIME = 1000 * 10;

// @ts-ignore
export const ergoExplorerContext$: Observable<{
height: number;
lastBlockId: string;
}> = interval(UPDATE_TIME).pipe(
startWith(undefined),
switchMap(() => from(explorer.getNetworkContext())),
map((ctx) => ctx),
publishReplay(1),
refCount(),
);
10 changes: 10 additions & 0 deletions src/api/locks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { map, publishReplay, refCount, switchMap } from 'rxjs';

import { selectedNetwork$ } from '../network/network';

export const locks$ = selectedNetwork$.pipe(
switchMap((network) => network.locks$),
map((locks) => locks.filter((l) => l.active)),
publishReplay(1),
refCount(),
);
9 changes: 9 additions & 0 deletions src/api/networkAssetBalance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { publishReplay, refCount, switchMap } from 'rxjs';

import { selectedNetwork$ } from '../network/network';

export const networkAssetBalance$ = selectedNetwork$.pipe(
switchMap((network) => network.networkAssetBalance$),
publishReplay(1),
refCount(),
);
33 changes: 33 additions & 0 deletions src/api/positions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { map, Observable, of, publishReplay, refCount, switchMap } from 'rxjs';

import { AmmPool } from '../common/models/AmmPool';
import { Position } from '../common/models/Position';
import { selectedNetwork$ } from '../network/network';
import { ammPools$ } from './ammPools';

export const positions$ = selectedNetwork$.pipe(
switchMap((network) => network.positions$),
publishReplay(1),
refCount(),
);
positions$.subscribe();

export const getPositionByAmmPoolId = (
ammPoolId: string,
): Observable<Position | undefined> =>
positions$.pipe(
switchMap((positions) => {
const position = positions.find((p) => p.pool.id === ammPoolId);

if (position) {
return of(position);
}
return ammPools$.pipe(
map<AmmPool[], Position | undefined>((ammPools) => {
const pool = ammPools.find((p) => p.id === ammPoolId);

return pool ? Position.noop(pool) : undefined;
}),
);
}),
);
31 changes: 31 additions & 0 deletions src/applicationConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
interface ApplicationConfig {
readonly api: string;
readonly social: {
readonly twitter: string;
readonly telegram: string;
readonly discord: string;
readonly medium: string;
readonly reddit: string;
};
readonly support: {
readonly discord: string;
readonly telegram: string;
};
readonly applicationTick: number;
}

export const applicationConfig: ApplicationConfig = {
api: 'https://api.ergodex.io/v1/',
social: {
twitter: 'https://twitter.com/ErgoDex',
telegram: 'https://t.me/ergodex_community',
discord: 'https://discord.com/invite/6MFFG4Fn4Y',
medium: 'https://ergodex.medium.com/',
reddit: 'https://www.reddit.com/r/ergodex/',
},
support: {
discord: 'https://discord.gg/Jya72kjDfq',
telegram: 'https://t.me/ergodex_community',
},
applicationTick: 10 * 1000,
};
3 changes: 3 additions & 0 deletions src/assets/icons/block-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions src/assets/icons/checked-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 0609a07

Please sign in to comment.