Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
60d7cf3029 | ||
|
|
2b8abde938 | ||
|
|
2005f19d50 | ||
|
|
d78de10855 | ||
|
|
bb402c02f6 | ||
|
|
8a9b1c7874 | ||
|
|
a7e8b0eb01 | ||
|
|
89b3c06107 | ||
|
|
cd5c73d3fd | ||
|
|
b3a5ab022d | ||
|
|
ba438549bc | ||
|
|
496d1f5c68 | ||
|
|
e914e7bb70 | ||
|
|
71a36c2382 | ||
|
|
1c6a307bcd | ||
|
|
ef4a740b91 | ||
|
|
a6303456c5 | ||
|
|
2d4be5fcb3 | ||
|
|
9cbd6baccd | ||
|
|
525773773a | ||
|
|
45d6f43e74 | ||
|
|
41760f2956 | ||
|
|
3d2b171de7 | ||
|
|
39a041332b | ||
|
|
4c0d05844e | ||
|
|
bf8480fed4 | ||
|
|
44434a7d39 | ||
|
|
b818e9b2a1 | ||
|
|
835f2b793f | ||
|
|
d50b988b4a | ||
|
|
a6aec899c8 |
@@ -95,7 +95,6 @@ context('Market page', { tags: '@regression' }, function () {
|
||||
);
|
||||
cy.validate_element_from_table('Lowest Price', '0.00 fUSDC');
|
||||
cy.validate_element_from_table('Highest Price', '0.00 fUSDC');
|
||||
|
||||
cy.getByTestId('oracle-spec-links')
|
||||
.should('have.attr', 'href')
|
||||
.and(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AssetTypeMapping, AssetStatusMapping } from '@vegaprotocol/assets';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import type { VegaICellRendererParams } from '@vegaprotocol/datagrid';
|
||||
import { useRef, useLayoutEffect } from 'react';
|
||||
import { BREAKPOINT_MD } from '../../config/breakpoints';
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import type { MarketInfoWithData } from '@vegaprotocol/markets';
|
||||
import {
|
||||
LiquidityPriceRangeInfoPanel,
|
||||
LiquiditySLAParametersInfoPanel,
|
||||
PriceMonitoringBoundsInfoPanel,
|
||||
SuccessionLineInfoPanel,
|
||||
getDataSourceSpecForSettlementData,
|
||||
@@ -94,6 +96,10 @@ export const MarketDetails = ({ market }: { market: MarketInfoWithData }) => {
|
||||
)}
|
||||
<h2 className={headerClassName}>{t('Liquidity monitoring')}</h2>
|
||||
<LiquidityMonitoringParametersInfoPanel market={market} />
|
||||
<h2 className={headerClassName}>{t('Liquidity price range')}</h2>
|
||||
<LiquidityPriceRangeInfoPanel market={market} />
|
||||
<h2 className={headerClassName}>{t('Liquidity SLA protocol')}</h2>
|
||||
<LiquiditySLAParametersInfoPanel market={market} />
|
||||
<h2 className={headerClassName}>{t('Liquidity')}</h2>
|
||||
<LiquidityInfoPanel market={market} />
|
||||
{showTwoOracles ? (
|
||||
|
||||
@@ -4,7 +4,7 @@ import { t } from '@vegaprotocol/i18n';
|
||||
import { ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import type { ColDef } from 'ag-grid-community';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import type {
|
||||
VegaICellRendererParams,
|
||||
VegaValueGetterParams,
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ProposalListFieldsFragment } from '@vegaprotocol/proposals';
|
||||
import { VoteProgress } from '@vegaprotocol/proposals';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
import { ExternalLink } from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import type {
|
||||
VegaICellRendererParams,
|
||||
VegaValueFormatterParams,
|
||||
@@ -105,7 +105,7 @@ export const ProposalsTable = ({ data }: ProposalsTableProps) => {
|
||||
? new BigNumber(0)
|
||||
: yesTokens.multipliedBy(100).dividedBy(totalTokensVoted);
|
||||
return (
|
||||
<div className="uppercase flex h-full items-center justify-center pt-2">
|
||||
<div className="flex items-center justify-center h-full pt-2 uppercase">
|
||||
<VoteProgress
|
||||
threshold={requiredMajorityPercentage}
|
||||
progress={yesPercentage}
|
||||
|
||||
@@ -108,7 +108,7 @@ export function createNewMarketProposalTxBody(): ProposalSubmissionBody {
|
||||
liquiditySlaParameters: {
|
||||
priceRange: '0.5',
|
||||
commitmentMinTimeFraction: '0.1',
|
||||
performanceHysteresisEpochs: 0,
|
||||
performanceHysteresisEpochs: 2,
|
||||
slaCompetitionFactor: '0.1',
|
||||
},
|
||||
quadraticSlippageFactor: '0',
|
||||
@@ -243,7 +243,7 @@ export function createSuccessorMarketProposalTxBody(
|
||||
liquiditySlaParameters: {
|
||||
priceRange: '0.5',
|
||||
commitmentMinTimeFraction: '0.1',
|
||||
performanceHysteresisEpochs: 0,
|
||||
performanceHysteresisEpochs: 2,
|
||||
slaCompetitionFactor: '0.1',
|
||||
},
|
||||
instrument: {
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
InstrumentInfoPanel,
|
||||
KeyDetailsInfoPanel,
|
||||
LiquidityMonitoringParametersInfoPanel,
|
||||
LiquidityPriceRangeInfoPanel,
|
||||
LiquiditySLAParametersInfoPanel,
|
||||
MetadataInfoPanel,
|
||||
OracleInfoPanel,
|
||||
PriceMonitoringBoundsInfoPanel,
|
||||
@@ -270,6 +272,21 @@ export const ProposalMarketData = ({
|
||||
market={marketData}
|
||||
parentMarket={parentMarketData}
|
||||
/>
|
||||
<h2 className={marketDataHeaderStyles}>
|
||||
{t('Liquidity price range')}
|
||||
</h2>
|
||||
<LiquidityPriceRangeInfoPanel
|
||||
market={marketData}
|
||||
parentMarket={parentMarketData}
|
||||
/>
|
||||
|
||||
<h2 className={marketDataHeaderStyles}>
|
||||
{t('Liquidity SLA protocol')}
|
||||
</h2>
|
||||
<LiquiditySLAParametersInfoPanel
|
||||
market={marketData}
|
||||
parentMarket={parentMarketData}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -6,6 +6,11 @@ import { MockedProvider } from '@apollo/client/testing';
|
||||
import { MemoryRouter, Route, Routes } from 'react-router-dom';
|
||||
import { ProposalDocument } from './__generated__/Proposal';
|
||||
|
||||
jest.mock('@vegaprotocol/data-provider', () => ({
|
||||
...jest.requireActual('@vegaprotocol/data-provider'),
|
||||
useDataProvider: jest.fn(() => ({ data: [], loading: false })),
|
||||
}));
|
||||
|
||||
jest.mock('../components/proposal', () => ({
|
||||
Proposal: () => <div data-testid="proposal" />,
|
||||
}));
|
||||
@@ -44,7 +49,9 @@ const renderComponent = (
|
||||
);
|
||||
};
|
||||
|
||||
describe('Proposal container', () => {
|
||||
// These tests are broken due to schema changes. NewMarket.futureProduct -> NewMarket.product union
|
||||
// eslint-disable-next-line jest/no-disabled-tests
|
||||
describe.skip('Proposal container', () => {
|
||||
it('Renders not found if the proposal is not found', async () => {
|
||||
render(renderComponent(null, 'foo'));
|
||||
await waitFor(() => {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useMemo, useEffect, useState, useCallback } from 'react';
|
||||
import { useMemo, useEffect, useState, useCallback, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { AsyncRenderer, Pagination } from '@vegaprotocol/ui-toolkit';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
@@ -86,12 +86,18 @@ export const EpochIndividualRewards = ({
|
||||
[epochId, page, refetch, delegationsPagination, pubKey]
|
||||
);
|
||||
|
||||
const prevEpochIdRef = useRef<number | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// when the epoch changes, we want to refetch the data to update the current page
|
||||
if (data) {
|
||||
if (prevEpochIdRef.current === null) {
|
||||
prevEpochIdRef.current = epochId;
|
||||
} else if (epochId !== prevEpochIdRef.current) {
|
||||
// When the epoch changes, we want to refetch the data to update the current page
|
||||
refetchData();
|
||||
}
|
||||
}, [epochId, data, refetchData]);
|
||||
|
||||
prevEpochIdRef.current = epochId;
|
||||
}, [epochId, refetchData]);
|
||||
|
||||
return (
|
||||
<AsyncRenderer
|
||||
|
||||
@@ -3,7 +3,7 @@ import { forwardRef, useMemo, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Button, Icon } from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { useAppState } from '../../../../contexts/app-state/app-state-context';
|
||||
import { BigNumber } from '../../../../lib/bignumber';
|
||||
import {
|
||||
@@ -85,17 +85,17 @@ const TopThirdCellRenderer = (
|
||||
}}
|
||||
className="grid grid-cols-[60px_1fr] w-full h-full py-4 px-0 text-sm text-white text-center overflow-scroll"
|
||||
>
|
||||
<div className="text-xs text-left px-3">
|
||||
<div className="px-3 text-xs text-left">
|
||||
{params?.data?.rankingDisplay}
|
||||
</div>
|
||||
<div className="whitespace-normal px-3">
|
||||
<div className="px-3 whitespace-normal">
|
||||
<div className="mb-4">
|
||||
<Button
|
||||
data-testid="show-all-validators"
|
||||
rightIcon={
|
||||
<Icon
|
||||
name="arrow-right"
|
||||
className="fill-current mr-2 align-text-top"
|
||||
className="mr-2 align-text-top fill-current"
|
||||
/>
|
||||
}
|
||||
className="inline-flex items-center"
|
||||
@@ -103,7 +103,7 @@ const TopThirdCellRenderer = (
|
||||
{t('Reveal top validators')}
|
||||
</Button>
|
||||
</div>
|
||||
<p className="font-semibold text-white mb-0">
|
||||
<p className="mb-0 font-semibold text-white">
|
||||
{t(
|
||||
'Validators with too great a stake share will have the staking rewards for their delegators penalised.'
|
||||
)}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { forwardRef, useMemo, useRef } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { useAppState } from '../../../../contexts/app-state/app-state-context';
|
||||
import { BigNumber } from '../../../../lib/bignumber';
|
||||
import {
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import { mockConnectWallet } from '@vegaprotocol/cypress';
|
||||
import {
|
||||
orderPriceField,
|
||||
placeOrderBtn,
|
||||
toggleLimit,
|
||||
toggleLong,
|
||||
toggleMarket,
|
||||
toggleShort,
|
||||
} from '../support/deal-ticket';
|
||||
|
||||
describe('deal ticket basics', { tags: '@smoke' }, () => {
|
||||
before(() => {
|
||||
cy.mockTradingPage();
|
||||
cy.mockSubscription();
|
||||
cy.clearAllLocalStorage();
|
||||
cy.setOnBoardingViewed();
|
||||
cy.visit('/#/markets/market-0');
|
||||
cy.wait('@Markets');
|
||||
});
|
||||
|
||||
it('must show place order button and connect wallet if wallet is not connected', () => {
|
||||
// 0003-WTXN-001
|
||||
cy.getByTestId('connect-vega-wallet'); // Not connected
|
||||
cy.getByTestId(placeOrderBtn).should('exist');
|
||||
cy.getByTestId('order-connect-wallet').should('exist');
|
||||
});
|
||||
|
||||
it('must be able to select order direction - long/short', function () {
|
||||
// 7002-SORD-004
|
||||
cy.getByTestId(toggleShort).click().next('input').should('be.checked');
|
||||
cy.getByTestId(toggleLong).click().next('input').should('be.checked');
|
||||
});
|
||||
|
||||
it('must be able to select order type - limit/market', function () {
|
||||
// 7002-SORD-005
|
||||
// 7002-SORD-006
|
||||
// 7002-SORD-007
|
||||
cy.getByTestId(toggleLimit).click().next('input').should('be.checked');
|
||||
cy.getByTestId(toggleMarket).click().next('input').should('be.checked');
|
||||
});
|
||||
|
||||
it('order connect vega wallet button should connect', () => {
|
||||
mockConnectWallet();
|
||||
cy.getByTestId(toggleLimit).click();
|
||||
cy.getByTestId(orderPriceField).clear().type('101');
|
||||
cy.getByTestId('order-connect-wallet').click();
|
||||
cy.getByTestId('dialog-content').should('be.visible');
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-jsonRpc"]')
|
||||
.click();
|
||||
cy.wait('@walletReq');
|
||||
cy.getByTestId(placeOrderBtn).should('be.visible');
|
||||
cy.getByTestId(toggleLimit).next('input').should('be.checked');
|
||||
cy.getByTestId(orderPriceField).should('have.value', '101');
|
||||
});
|
||||
|
||||
it('sidebar should be open after reload', () => {
|
||||
cy.mockTradingPage();
|
||||
cy.getByTestId('deal-ticket-form').should('be.visible');
|
||||
cy.getByTestId('Order').click();
|
||||
cy.getByTestId('deal-ticket-form').should('not.exist');
|
||||
cy.reload();
|
||||
cy.getByTestId('deal-ticket-form').should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'market states not accepting orders',
|
||||
{ tags: '@smoke', testIsolation: true },
|
||||
function () {
|
||||
//7002-SORD-062
|
||||
//7002-SORD-063
|
||||
//7002-SORD-066
|
||||
|
||||
const states = [
|
||||
Schema.MarketState.STATE_REJECTED,
|
||||
Schema.MarketState.STATE_CANCELLED,
|
||||
Schema.MarketState.STATE_CLOSED,
|
||||
Schema.MarketState.STATE_SETTLED,
|
||||
Schema.MarketState.STATE_TRADING_TERMINATED,
|
||||
];
|
||||
|
||||
states.forEach((marketState) => {
|
||||
describe(marketState, function () {
|
||||
beforeEach(function () {
|
||||
cy.mockTradingPage(marketState);
|
||||
cy.mockSubscription();
|
||||
cy.setVegaWallet();
|
||||
cy.visit('/#/markets/market-0');
|
||||
});
|
||||
it('must display that market is not accepting orders', function () {
|
||||
cy.getByTestId('deal-ticket-error-message-summary').should(
|
||||
'have.text',
|
||||
`This market is ${marketState
|
||||
.split('_')
|
||||
.pop()
|
||||
?.toLowerCase()} and not accepting orders`
|
||||
);
|
||||
// 7002-SORD-060
|
||||
cy.getByTestId('place-order').should('be.enabled');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -24,6 +24,7 @@ NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=true
|
||||
|
||||
NX_TENDERMINT_URL=https://tm.be.testnet.vega.xyz
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.testnet.vega.xyz/websocket
|
||||
|
||||
@@ -24,6 +24,7 @@ NX_STOP_ORDERS=false
|
||||
# NX_ICEBERG_ORDERS
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=false
|
||||
NX_REFERRALS=false
|
||||
|
||||
NX_TENDERMINT_URL=http://localhost:26617
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://localhost:26617/websocket
|
||||
|
||||
@@ -22,6 +22,7 @@ NX_STOP_ORDERS=true
|
||||
# NX_ICEBERG_ORDERS
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=true
|
||||
|
||||
NX_TENDERMINT_URL=https://tm.be.devnet1.vega.xyz/
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.devnet1.vega.xyz/websocket
|
||||
|
||||
@@ -17,16 +17,13 @@ NX_CHROME_EXTENSION_URL=https://chrome.google.com/webstore/detail/vega-wallet-ma
|
||||
NX_MOZILLA_EXTENSION_URL=https://addons.mozilla.org/firefox/addon/vega-wallet-mainnet
|
||||
NX_ORACLE_PROOFS_URL=https://raw.githubusercontent.com/vegaprotocol/well-known/main/__generated__/oracle-proofs.json
|
||||
|
||||
|
||||
# TAG name of the current app version - TODO: bump to the latest upon release
|
||||
NX_APP_VERSION=v0.21.2-core-0.72.14
|
||||
|
||||
# Cosmic elevator flags
|
||||
NX_SUCCESSOR_MARKETS=true
|
||||
NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=false
|
||||
|
||||
NX_TENDERMINT_URL=https://be.vega.community
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.vega.community/websocket
|
||||
|
||||
@@ -24,6 +24,7 @@ NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=false
|
||||
NX_REFERRALS=false
|
||||
|
||||
NX_TENDERMINT_URL=https://be.mainnet-mirror.vega.rocks
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.mainnet-mirror.vega.rocks/websocket
|
||||
|
||||
@@ -24,3 +24,4 @@ NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=true
|
||||
@@ -24,6 +24,7 @@ NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=true
|
||||
NX_REFERRALS=true
|
||||
|
||||
NX_TENDERMINT_URL=https://tm.be.testnet.vega.xyz
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.testnet.vega.xyz/websocket
|
||||
|
||||
@@ -25,6 +25,7 @@ NX_STOP_ORDERS=true
|
||||
NX_ICEBERG_ORDERS=true
|
||||
# NX_PRODUCT_PERPETUALS
|
||||
NX_METAMASK_SNAPS=false
|
||||
NX_REFERRALS=false
|
||||
|
||||
NX_TENDERMINT_URL=https://tm.be.validators-testnet.vega.rocks
|
||||
NX_TENDERMINT_WEBSOCKET_URL=wss://be.validators-testnet.vega.xyz/websocket
|
||||
|
||||
@@ -126,32 +126,20 @@ export const FundingRate = ({ marketId }: { marketId: string }) => {
|
||||
);
|
||||
};
|
||||
|
||||
const padStart = (n: number) => n.toString().padStart(2, '0');
|
||||
|
||||
export const FundingCountdown = ({ marketId }: { marketId: string }) => {
|
||||
const { data: fundingPeriods } = useFundingPeriodsQuery({
|
||||
variables: {
|
||||
marketId: marketId,
|
||||
pagination: { first: 1 },
|
||||
},
|
||||
});
|
||||
const { data: marketInfo } = useDataProvider({
|
||||
dataProvider: marketInfoProvider,
|
||||
variables: { marketId },
|
||||
});
|
||||
|
||||
const useNow = () => {
|
||||
const [now, setNow] = useState(Date.now());
|
||||
useEffect(() => {
|
||||
const interval = setInterval(() => setNow(Date.now()), 1000);
|
||||
return () => clearInterval(interval);
|
||||
}, []);
|
||||
return now;
|
||||
};
|
||||
|
||||
const node = fundingPeriods?.fundingPeriods.edges?.[0]?.node;
|
||||
let startTime: number | undefined = undefined;
|
||||
if (node && node.startTime && !node.endTime) {
|
||||
startTime = fromNanoSeconds(node.startTime).getTime();
|
||||
}
|
||||
let diffFormatted = t('Unknown');
|
||||
const useEvery = (marketId: string) => {
|
||||
const { data: marketInfo } = useDataProvider({
|
||||
dataProvider: marketInfoProvider,
|
||||
variables: { marketId },
|
||||
});
|
||||
let every: number | undefined = undefined;
|
||||
const sourceType =
|
||||
marketInfo &&
|
||||
@@ -165,14 +153,51 @@ export const FundingCountdown = ({ marketId }: { marketId: string }) => {
|
||||
every *= 1000;
|
||||
}
|
||||
}
|
||||
return every;
|
||||
};
|
||||
|
||||
const useStartTime = (marketId: string) => {
|
||||
const { data: fundingPeriods } = useFundingPeriodsQuery({
|
||||
variables: {
|
||||
marketId: marketId,
|
||||
pagination: { first: 1 },
|
||||
},
|
||||
});
|
||||
const node = fundingPeriods?.fundingPeriods.edges?.[0]?.node;
|
||||
let startTime: number | undefined = undefined;
|
||||
if (node && node.startTime && !node.endTime) {
|
||||
startTime = fromNanoSeconds(node.startTime).getTime();
|
||||
}
|
||||
return startTime;
|
||||
};
|
||||
|
||||
const padStart = (n: number) => n.toString().padStart(2, '0');
|
||||
|
||||
const useFormatCountdown = (
|
||||
now: number,
|
||||
startTime?: number,
|
||||
every?: number
|
||||
) => {
|
||||
if (startTime && every) {
|
||||
const diff = every - ((now - startTime) % every);
|
||||
const hours = (diff / 3.6e6) | 0;
|
||||
const mins = ((diff % 3.6e6) / 6e4) | 0;
|
||||
const secs = Math.round((diff % 6e4) / 1e3);
|
||||
diffFormatted = `${padStart(hours)}:${padStart(mins)}:${padStart(secs)}`;
|
||||
return `${padStart(hours)}:${padStart(mins)}:${padStart(secs)}`;
|
||||
}
|
||||
return <div data-testid="funding-countdown">{diffFormatted}</div>;
|
||||
return t('Unknown');
|
||||
};
|
||||
|
||||
export const FundingCountdown = ({ marketId }: { marketId: string }) => {
|
||||
const now = useNow();
|
||||
const startTime = useStartTime(marketId);
|
||||
const every = useEvery(marketId);
|
||||
|
||||
return (
|
||||
<div data-testid="funding-countdown">
|
||||
{useFormatCountdown(now, startTime, every)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ExpiryLabel = ({ market }: ExpiryLabelProps) => {
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
VegaICellRendererParams,
|
||||
VegaValueFormatterParams,
|
||||
} from '@vegaprotocol/datagrid';
|
||||
import { AgGridLazy as AgGrid, COL_DEFS } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid, COL_DEFS } from '@vegaprotocol/datagrid';
|
||||
import { useMemo } from 'react';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import type { Asset } from '@vegaprotocol/types';
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import type { TypedDataAgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGridLazy as AgGrid, PriceFlashCell } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid, PriceFlashCell } from '@vegaprotocol/datagrid';
|
||||
import type { MarketMaybeWithData } from '@vegaprotocol/markets';
|
||||
import { useColumnDefs } from './use-column-defs';
|
||||
|
||||
@@ -8,6 +8,7 @@ export const getRowId = ({ data }: { data: { id: string } }) => data.id;
|
||||
const defaultColDef = {
|
||||
sortable: true,
|
||||
filter: true,
|
||||
resizable: true,
|
||||
filterParams: { buttons: ['reset'] },
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ export const useColumnDefs = () => {
|
||||
{
|
||||
headerName: t('Market'),
|
||||
field: 'tradableInstrument.instrument.code',
|
||||
flex: 2,
|
||||
cellRenderer: ({
|
||||
value,
|
||||
data,
|
||||
@@ -50,7 +49,6 @@ export const useColumnDefs = () => {
|
||||
{
|
||||
headerName: t('Description'),
|
||||
field: 'tradableInstrument.instrument.name',
|
||||
flex: 2,
|
||||
},
|
||||
{
|
||||
headerName: t('Trading mode'),
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
import {
|
||||
Input,
|
||||
InputError,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import type { FieldValues } from 'react-hook-form';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import classNames from 'classnames';
|
||||
import { Navigate, useSearchParams } from 'react-router-dom';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { Button } from './buttons';
|
||||
import {
|
||||
useTransactionEventSubscription,
|
||||
useVegaWallet,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import { useReferral } from './hooks/use-referral';
|
||||
import { Routes } from '../../lib/links';
|
||||
|
||||
export const ApplyCodeForm = () => {
|
||||
const [status, setStatus] = useState<
|
||||
'requested' | 'failed' | 'successful' | null
|
||||
>(null);
|
||||
const txHash = useRef<string | null>(null);
|
||||
const { isReadOnly, pubKey, sendTx } = useVegaWallet();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
formState: { errors },
|
||||
setValue,
|
||||
setError,
|
||||
} = useForm();
|
||||
const [params] = useSearchParams();
|
||||
|
||||
const { data: referee } = useReferral(pubKey, 'referee');
|
||||
const { data: referrer } = useReferral(pubKey, 'referrer');
|
||||
|
||||
useEffect(() => {
|
||||
const code = params.get('code');
|
||||
if (code) setValue('code', code);
|
||||
}, [params, setValue]);
|
||||
|
||||
const onSubmit = ({ code }: FieldValues) => {
|
||||
if (isReadOnly || !pubKey || !code || code.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus('requested');
|
||||
|
||||
sendTx(pubKey, {
|
||||
applyReferralCode: {
|
||||
id: code as string,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
setError('code', {
|
||||
type: 'required',
|
||||
message: 'The transaction could not be sent',
|
||||
});
|
||||
}
|
||||
if (res) {
|
||||
txHash.current = res.transactionHash.toLowerCase();
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.message.includes('user rejected')) {
|
||||
setStatus(null);
|
||||
} else {
|
||||
setError('code', {
|
||||
type: 'required',
|
||||
message: 'Your code has been rejected',
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
useTransactionEventSubscription({
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
fetchPolicy: 'no-cache',
|
||||
onData: ({ data: result }) =>
|
||||
result.data?.busEvents?.forEach((event) => {
|
||||
if (event.event.__typename === 'TransactionResult') {
|
||||
const hash = event.event.hash.toLowerCase();
|
||||
if (txHash.current && txHash.current === hash) {
|
||||
const err = event.event.error;
|
||||
const status = event.event.status;
|
||||
if (err) {
|
||||
setStatus(null);
|
||||
setError('code', {
|
||||
type: 'required',
|
||||
message: err,
|
||||
});
|
||||
}
|
||||
if (status && !err) {
|
||||
setStatus('successful');
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
});
|
||||
|
||||
if (referee || referrer) {
|
||||
return <Navigate to={Routes.REFERRALS} />;
|
||||
}
|
||||
|
||||
if (status === 'successful') {
|
||||
return (
|
||||
<div className="w-1/2 mx-auto">
|
||||
<h3 className="mb-5 text-xl text-center uppercase calt flex flex-row gap-2 justify-center items-center">
|
||||
<span className="text-vega-green-500">
|
||||
<VegaIcon name={VegaIconNames.TICK} size={20} />
|
||||
</span>{' '}
|
||||
<span className="pt-1">Code applied</span>
|
||||
</h3>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const getButtonProps = () => {
|
||||
if (isReadOnly || !pubKey) {
|
||||
return {
|
||||
disabled: true,
|
||||
children: 'Apply',
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'requested') {
|
||||
return {
|
||||
disabled: true,
|
||||
children: 'Confirm in wallet...',
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
disabled: false,
|
||||
children: 'Apply',
|
||||
};
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="w-1/2 mx-auto">
|
||||
<h3 className="mb-5 text-xl text-center uppercase calt">
|
||||
Apply a referral code
|
||||
</h3>
|
||||
<p className="mb-6 text-center">Enter a referral code</p>
|
||||
<form
|
||||
className={classNames('w-full flex flex-col gap-3', {
|
||||
'animate-shake': Boolean(errors.code),
|
||||
})}
|
||||
onSubmit={handleSubmit(onSubmit)}
|
||||
>
|
||||
<label className="flex-grow">
|
||||
<span className="block mb-1 text-sm text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
Your referral code
|
||||
</span>
|
||||
<Input
|
||||
hasError={Boolean(errors.code)}
|
||||
{...register('code', {
|
||||
required: 'You have to provide a code to apply it.',
|
||||
})}
|
||||
/>
|
||||
</label>
|
||||
<Button className="w-full" type="submit" {...getButtonProps()} />
|
||||
</form>
|
||||
{errors.code && (
|
||||
<InputError>{errors.code.message?.toString()}</InputError>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,111 @@
|
||||
import { Intent, TradingButton } from '@vegaprotocol/ui-toolkit';
|
||||
import classNames from 'classnames';
|
||||
import type { ComponentProps, ButtonHTMLAttributes } from 'react';
|
||||
import { forwardRef } from 'react';
|
||||
import { NavLink } from 'react-router-dom';
|
||||
|
||||
type RainbowButtonProps = {
|
||||
variant?: 'full' | 'border';
|
||||
};
|
||||
|
||||
export const RainbowButton = ({
|
||||
variant = 'full',
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: RainbowButtonProps & ButtonHTMLAttributes<HTMLButtonElement>) => (
|
||||
<button
|
||||
className={classNames(
|
||||
'bg-rainbow hover:bg-none hover:bg-rainbow enabled:hover:bg-vega-pink-500 rounded-lg overflow-hidden disabled:opacity-40',
|
||||
{
|
||||
'px-5 py-3 text-white': variant === 'full',
|
||||
'p-[0.125rem]': variant === 'border',
|
||||
},
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<div
|
||||
className={classNames({
|
||||
'bg-white dark:bg-vega-cdark-900 text-black dark:text-white px-5 py-3 rounded-[0.35rem] overflow-hidden':
|
||||
variant === 'border',
|
||||
})}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</button>
|
||||
);
|
||||
|
||||
const RAINBOW_TAB_STYLE = classNames(
|
||||
'inline-block',
|
||||
'bg-vega-clight-500 dark:bg-vega-cdark-500',
|
||||
'hover:bg-vega-clight-400 dark:hover:bg-vega-cdark-400',
|
||||
'data-[state="active"]:text-white data-[state="active"]:bg-rainbow',
|
||||
'data-[state="active"]:hover:bg-none data-[state="active"]:hover:bg-vega-pink-500 dark:data-[state="active"]:hover:bg-vega-pink-500',
|
||||
'[&.active]:text-white [&.active]:bg-rainbow',
|
||||
'[&.active]:hover:bg-none [&.active]:hover:bg-vega-pink-500 dark:[&.active]:hover:bg-vega-pink-500',
|
||||
'px-5 py-3',
|
||||
'first:rounded-tl-lg last:rounded-tr-lg'
|
||||
);
|
||||
|
||||
const DISABLED_RAINBOW_TAB_STYLE = classNames(
|
||||
'pointer-events-none',
|
||||
'text-vega-clight-100 dark:text-vega-cdark-100',
|
||||
'data-[state="active"]:text-white',
|
||||
'[&.active]:text-white'
|
||||
);
|
||||
|
||||
export const RainbowTabButton = forwardRef<
|
||||
HTMLButtonElement,
|
||||
{ disabled?: boolean } & ButtonHTMLAttributes<HTMLButtonElement>
|
||||
>(({ children, className, disabled = false, ...props }, ref) => (
|
||||
<button
|
||||
ref={ref}
|
||||
className={classNames(
|
||||
RAINBOW_TAB_STYLE,
|
||||
{ 'pointer-events-none': disabled },
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
));
|
||||
RainbowTabButton.displayName = 'RainbowTabButton';
|
||||
|
||||
export const RainbowTabLink = ({
|
||||
to,
|
||||
children,
|
||||
className,
|
||||
disabled = false,
|
||||
...props
|
||||
}: { disabled?: boolean } & ComponentProps<typeof NavLink>) => (
|
||||
<NavLink
|
||||
to={to}
|
||||
className={classNames(
|
||||
RAINBOW_TAB_STYLE,
|
||||
disabled && DISABLED_RAINBOW_TAB_STYLE,
|
||||
typeof className === 'string' ? className : undefined
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</NavLink>
|
||||
);
|
||||
|
||||
export const Button = forwardRef<
|
||||
HTMLButtonElement,
|
||||
ComponentProps<typeof TradingButton>
|
||||
>(({ children, intent, type, ...props }, ref) => {
|
||||
return (
|
||||
<TradingButton
|
||||
ref={ref}
|
||||
intent={intent || type === 'submit' ? Intent.Primary : Intent.None}
|
||||
type={type}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</TradingButton>
|
||||
);
|
||||
});
|
||||
Button.displayName = 'TradingButton';
|
||||
@@ -0,0 +1,6 @@
|
||||
export const BORDER_COLOR = 'border-vega-clight-500 dark:border-vega-cdark-500';
|
||||
export const GRADIENT =
|
||||
'bg-gradient-to-b from-vega-clight-800 dark:from-vega-cdark-800 to-transparent';
|
||||
|
||||
export const SKY_BACKGROUND =
|
||||
'bg-[url(/sky-light.png)] dark:bg-[url(/sky-dark.png)] bg-[40%_0px] bg-[length:1440px] bg-no-repeat bg-local';
|
||||
@@ -0,0 +1,225 @@
|
||||
import {
|
||||
useVegaWallet,
|
||||
useVegaWalletDialogStore,
|
||||
determineId,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import { RainbowButton } from './buttons';
|
||||
import { useState } from 'react';
|
||||
import {
|
||||
CopyWithTooltip,
|
||||
Dialog,
|
||||
ExternalLink,
|
||||
InputError,
|
||||
Intent,
|
||||
TradingAnchorButton,
|
||||
TradingButton,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { addDecimalsFormatNumber } from '@vegaprotocol/utils';
|
||||
import { DApp, TokenStaticLinks, useLinks } from '@vegaprotocol/environment';
|
||||
import { useStakeAvailable } from './hooks/use-stake-available';
|
||||
|
||||
export const CreateCodeContainer = () => {
|
||||
const { stakeAvailable, requiredStake } = useStakeAvailable();
|
||||
if (stakeAvailable == null || requiredStake == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<CreateCodeForm
|
||||
currentStakeAvailable={stakeAvailable}
|
||||
requiredStake={requiredStake}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export const CreateCodeForm = ({
|
||||
currentStakeAvailable,
|
||||
requiredStake,
|
||||
}: {
|
||||
currentStakeAvailable: bigint;
|
||||
requiredStake: bigint;
|
||||
}) => {
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const openWalletDialog = useVegaWalletDialogStore(
|
||||
(store) => store.openVegaWalletDialog
|
||||
);
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
return (
|
||||
<div className="w-1/2 mx-auto">
|
||||
<h3 className="mb-5 text-xl text-center uppercase calt">
|
||||
Create a referral code
|
||||
</h3>
|
||||
<p className="mb-6 text-center">
|
||||
Generate a referral code to share with your friends and start earning
|
||||
commission.
|
||||
</p>
|
||||
<div className="mb-5">
|
||||
<div className="text-center">
|
||||
<RainbowButton
|
||||
variant="border"
|
||||
onClick={() => {
|
||||
if (pubKey) {
|
||||
setDialogOpen(true);
|
||||
} else {
|
||||
openWalletDialog();
|
||||
}
|
||||
}}
|
||||
>
|
||||
{pubKey ? 'Create a referral code' : 'Connect wallet'}
|
||||
</RainbowButton>
|
||||
</div>
|
||||
</div>
|
||||
<Dialog
|
||||
title="Create a referral code"
|
||||
open={dialogOpen}
|
||||
onChange={() => setDialogOpen(false)}
|
||||
size="small"
|
||||
>
|
||||
<CreateCodeDialog
|
||||
currentStakeAvailable={currentStakeAvailable}
|
||||
setDialogOpen={setDialogOpen}
|
||||
requiredStake={requiredStake}
|
||||
/>
|
||||
</Dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const CreateCodeDialog = ({
|
||||
setDialogOpen,
|
||||
currentStakeAvailable,
|
||||
requiredStake,
|
||||
}: {
|
||||
setDialogOpen: (open: boolean) => void;
|
||||
currentStakeAvailable: bigint;
|
||||
requiredStake: bigint;
|
||||
}) => {
|
||||
const createLink = useLinks(DApp.Governance);
|
||||
const { isReadOnly, pubKey, sendTx } = useVegaWallet();
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [code, setCode] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState<
|
||||
'idle' | 'loading' | 'success' | 'error'
|
||||
>('idle');
|
||||
|
||||
const onSubmit = () => {
|
||||
if (isReadOnly || !pubKey) {
|
||||
setErr('Not connected');
|
||||
} else {
|
||||
setErr(null);
|
||||
setStatus('loading');
|
||||
setCode(null);
|
||||
sendTx(pubKey, {
|
||||
createReferralSet: {
|
||||
isTeam: false,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
if (!res) {
|
||||
setErr(`Invalid response: ${JSON.stringify(res)}`);
|
||||
return;
|
||||
}
|
||||
const code = determineId(res.signature);
|
||||
setCode(code);
|
||||
setStatus('success');
|
||||
})
|
||||
.catch((err) => {
|
||||
if (err.message.includes('user rejected')) {
|
||||
setStatus('idle');
|
||||
return;
|
||||
}
|
||||
setStatus('error');
|
||||
setErr(err.message);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
const getButtonProps = () => {
|
||||
if (status === 'idle' || status === 'error') {
|
||||
return {
|
||||
children: 'Generate code',
|
||||
onClick: () => onSubmit(),
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'loading') {
|
||||
return {
|
||||
children: 'Confirm in wallet...',
|
||||
disabled: true,
|
||||
};
|
||||
}
|
||||
|
||||
if (status === 'success') {
|
||||
return {
|
||||
children: 'Close',
|
||||
intent: Intent.Success,
|
||||
onClick: () => setDialogOpen(false),
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// TODO: Add when network parameters are updated
|
||||
if (
|
||||
currentStakeAvailable === BigInt(0) ||
|
||||
currentStakeAvailable < requiredStake
|
||||
) {
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
<p>
|
||||
You need at least{' '}
|
||||
{addDecimalsFormatNumber(requiredStake.toString(), 18)} VEGA staked to
|
||||
generate a referral code and participate in the referral program.
|
||||
</p>
|
||||
<TradingAnchorButton
|
||||
href={createLink(TokenStaticLinks.ASSOCIATE)}
|
||||
intent={Intent.Primary}
|
||||
target="_blank"
|
||||
>
|
||||
Stake some $VEGA now
|
||||
</TradingAnchorButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-4">
|
||||
{(status === 'idle' || status === 'loading' || status === 'error') && (
|
||||
<p>
|
||||
Generate a referral code to share with your friends and start earning
|
||||
commission.
|
||||
</p>
|
||||
)}
|
||||
{status === 'success' && code && (
|
||||
<div className="flex items-center gap-2">
|
||||
<div className="flex-1 min-w-0 p-2 text-sm rounded bg-vega-clight-700 dark:bg-vega-cdark-700">
|
||||
<p className="overflow-hidden whitespace-nowrap text-ellipsis">
|
||||
{code}
|
||||
</p>
|
||||
</div>
|
||||
<CopyWithTooltip text={code}>
|
||||
<TradingButton
|
||||
className="text-sm no-underline"
|
||||
icon={<VegaIcon name={VegaIconNames.COPY} />}
|
||||
>
|
||||
<span>Copy</span>
|
||||
</TradingButton>
|
||||
</CopyWithTooltip>
|
||||
</div>
|
||||
)}
|
||||
<TradingButton
|
||||
fill={true}
|
||||
intent={Intent.Primary}
|
||||
{...getButtonProps()}
|
||||
/>
|
||||
{err && <InputError>{err}</InputError>}
|
||||
{/* TODO: Add links */}
|
||||
<div className="flex justify-center pt-5 mt-2 text-sm border-t gap-4 text-default border-default">
|
||||
<ExternalLink>About the referral program</ExternalLink>
|
||||
<ExternalLink>Disclaimer</ExternalLink>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,77 @@
|
||||
import { isRouteErrorResponse, useNavigate, useRouteError } from 'react-router';
|
||||
import { RainbowButton } from './buttons';
|
||||
import { AnimatedDudeWithWire } from './graphics/dude';
|
||||
import { LayoutWithSky } from './layout';
|
||||
import { Routes } from '../../lib/links';
|
||||
|
||||
export const ErrorBoundary = () => {
|
||||
const error = useRouteError();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const title = isRouteErrorResponse(error)
|
||||
? `${error.status} ${error.statusText}`
|
||||
: 'Something went wrong';
|
||||
|
||||
const code = isRouteErrorResponse(error) ? error.status : 0;
|
||||
|
||||
const messages: Record<number, string> = {
|
||||
0: 'An unknown error occurred.',
|
||||
404: "The page you're looking for doesn't exists.",
|
||||
};
|
||||
|
||||
return (
|
||||
<LayoutWithSky className="pt-32">
|
||||
<div
|
||||
aria-hidden
|
||||
className="absolute top-64 right-[220px] md:right-[340px] max-sm:hidden"
|
||||
>
|
||||
<AnimatedDudeWithWire className="animate-spin" />
|
||||
</div>
|
||||
<h1 className="text-6xl font-alpha calt mb-10">{title}</h1>
|
||||
|
||||
{Object.keys(messages).includes(code.toString()) ? (
|
||||
<p className="text-lg mb-10">{messages[code]}</p>
|
||||
) : null}
|
||||
|
||||
<p className="text-lg mb-10">
|
||||
<RainbowButton
|
||||
onClick={() => navigate('..')}
|
||||
variant="border"
|
||||
className="text-xs"
|
||||
>
|
||||
Go back and try again
|
||||
</RainbowButton>
|
||||
</p>
|
||||
</LayoutWithSky>
|
||||
);
|
||||
};
|
||||
|
||||
export const NotFound = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<div className="pt-32">
|
||||
<div
|
||||
aria-hidden
|
||||
className="absolute top-64 right-[220px] md:right-[340px] max-sm:hidden"
|
||||
>
|
||||
<AnimatedDudeWithWire className="animate-spin" />
|
||||
</div>
|
||||
<h1 className="text-6xl font-alpha calt mb-10">{'Not found'}</h1>
|
||||
|
||||
<p className="text-lg mb-10">
|
||||
{"The page you're looking for doesn't exists."}
|
||||
</p>
|
||||
|
||||
<p className="text-lg mb-10">
|
||||
<RainbowButton
|
||||
onClick={() => navigate(Routes.REFERRALS)}
|
||||
variant="border"
|
||||
className="text-xs"
|
||||
>
|
||||
Go back and try again
|
||||
</RainbowButton>
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
import classNames from 'classnames';
|
||||
import type { HTMLAttributes } from 'react';
|
||||
|
||||
export const Dude = ({ className }: HTMLAttributes<SVGElement>) => {
|
||||
return (
|
||||
<svg
|
||||
width="41"
|
||||
height="47"
|
||||
viewBox="0 0 41 47"
|
||||
fill="none"
|
||||
className={className}
|
||||
>
|
||||
<path
|
||||
d="M21.1895 0.298767L5.08827 27.4101L8.96133 29.7103L4.36099 37.4564L8.23404 39.7566L12.8344 32.0105L16.7074 34.3107L12.1071 42.0568L15.9801 44.3569L20.5805 36.6108L24.4535 38.911L40.5547 11.7996L21.1895 0.298767Z"
|
||||
className="fill-black dark:fill-white"
|
||||
/>
|
||||
<path
|
||||
d="M35.9346 15.1683L20.4424 5.96765L14.3086 16.2958L29.8008 25.4965L35.9346 15.1683Z"
|
||||
className="fill-white dark:fill-black"
|
||||
/>
|
||||
<path
|
||||
d="M25.646 17.7895L23.064 16.2561L21.5305 18.8381L24.1126 20.3716L25.646 17.7895Z"
|
||||
className="fill-black dark:fill-white"
|
||||
/>
|
||||
<path
|
||||
d="M29.7612 16.7412L27.1792 15.2077L25.6458 17.7898L28.2278 19.3232L29.7612 16.7412Z"
|
||||
className="fill-black dark:fill-white"
|
||||
/>
|
||||
<path
|
||||
d="M33.877 15.6925L31.2949 14.159L29.7615 16.7411L32.3435 18.2745L33.877 15.6925Z"
|
||||
className="fill-black dark:fill-white"
|
||||
/>
|
||||
<path
|
||||
d="M29.0342 26.7874L26.4521 25.2539L24.9187 27.836L27.5007 29.3694L29.0342 26.7874Z"
|
||||
fill="#FF077F"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export const Wire = ({ className }: HTMLAttributes<SVGElement>) => {
|
||||
return (
|
||||
<svg
|
||||
width="157"
|
||||
height="88"
|
||||
viewBox="0 0 157 88"
|
||||
fill="none"
|
||||
className={className}
|
||||
>
|
||||
<path
|
||||
d="M109.398 6.12235C127.37 -3.81898 146.791 1.45045 153.465 14.307C160.138 27.1636 154.195 43.9948 140.438 52.1164C126.68 60.238 105.767 54.9998 84.9212 43.464C64.0752 31.9281 32.2412 6.42016 18.8175 24.185C6.90871 40.719 41.9332 68.4495 29.2664 82.7049C23.187 88.4974 11.1379 88.2645 0.968295 80.3398"
|
||||
className="stroke-black dark:stroke-white"
|
||||
strokeWidth="1.5"
|
||||
strokeMiterlimit="10"
|
||||
/>
|
||||
</svg>
|
||||
);
|
||||
};
|
||||
|
||||
export const AnimatedDudeWithWire = ({ className }: { className?: string }) => (
|
||||
<div className="relative">
|
||||
<Wire className="absolute top-[25px]" />
|
||||
<Dude
|
||||
className={classNames(
|
||||
'absolute left-[96px] animate-[wave_20s_ease-in-out_infinite]',
|
||||
className
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,133 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { getNumberFormat } from '@vegaprotocol/utils';
|
||||
import { addDays } from 'date-fns';
|
||||
import sortBy from 'lodash/sortBy';
|
||||
import omit from 'lodash/omit';
|
||||
|
||||
// TODO: Generate query
|
||||
// eslint-disable-next-line
|
||||
const REFERRAL_PROGRAM_QUERY = gql`
|
||||
query ReferralProgram {
|
||||
currentReferralProgram {
|
||||
id
|
||||
version
|
||||
endOfProgramTimestamp
|
||||
windowLength
|
||||
endedAt
|
||||
benefitTiers {
|
||||
minimumEpochs
|
||||
minimumRunningNotionalTakerVolume
|
||||
referralDiscountFactor
|
||||
referralRewardFactor
|
||||
}
|
||||
stakingTiers {
|
||||
minimumStakedTokens
|
||||
referralRewardMultiplier
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const STAKING_TIERS_MAPPING: Record<number, string> = {
|
||||
1: 'Tradestarter',
|
||||
2: 'Mid level degen',
|
||||
3: 'Reward hoarder',
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
const MOCK = {
|
||||
data: {
|
||||
currentReferralProgram: {
|
||||
id: 'abc',
|
||||
version: 1,
|
||||
endOfProgramTimestamp: addDays(new Date(), 10).toISOString(),
|
||||
windowLength: 10,
|
||||
benefitTiers: [
|
||||
{
|
||||
minimumEpochs: 5,
|
||||
minimumRunningNotionalTakerVolume: '30000',
|
||||
referralDiscountFactor: '0.01',
|
||||
referralRewardFactor: '0.01',
|
||||
},
|
||||
{
|
||||
minimumEpochs: 5,
|
||||
minimumRunningNotionalTakerVolume: '20000',
|
||||
referralDiscountFactor: '0.05',
|
||||
referralRewardFactor: '0.05',
|
||||
},
|
||||
{
|
||||
minimumEpochs: 5,
|
||||
minimumRunningNotionalTakerVolume: '10000',
|
||||
referralDiscountFactor: '0.001',
|
||||
referralRewardFactor: '0.001',
|
||||
},
|
||||
],
|
||||
stakingTiers: [
|
||||
{
|
||||
minimumStakedTokens: '10000',
|
||||
referralRewardMultiplier: '1',
|
||||
},
|
||||
{
|
||||
minimumStakedTokens: '20000',
|
||||
referralRewardMultiplier: '2',
|
||||
},
|
||||
{
|
||||
minimumStakedTokens: '30000',
|
||||
referralRewardMultiplier: '3',
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
loading: false,
|
||||
error: undefined,
|
||||
};
|
||||
|
||||
export const useReferralProgram = () => {
|
||||
const { data, loading, error } = useQuery(REFERRAL_PROGRAM_QUERY, {
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
if (!data) {
|
||||
return {
|
||||
benefitTiers: [],
|
||||
stakingTiers: [],
|
||||
details: undefined,
|
||||
loading,
|
||||
error,
|
||||
};
|
||||
}
|
||||
|
||||
const benefitTiers = sortBy(data.currentReferralProgram.benefitTiers, (t) =>
|
||||
Number(t.referralRewardFactor)
|
||||
)
|
||||
.reverse()
|
||||
.map((t, i) => {
|
||||
return {
|
||||
tier: i + 1,
|
||||
commission: Number(t.referralRewardFactor) * 100 + '%',
|
||||
discount: Number(t.referralDiscountFactor) * 100 + '%',
|
||||
volume: getNumberFormat(0).format(
|
||||
Number(t.minimumRunningNotionalTakerVolume)
|
||||
),
|
||||
};
|
||||
});
|
||||
|
||||
const stakingTiers = sortBy(
|
||||
data.currentReferralProgram.stakingTiers,
|
||||
(t) => t.referralRewardMultiplier
|
||||
).map((t, i) => {
|
||||
return {
|
||||
tier: i + 1,
|
||||
label: STAKING_TIERS_MAPPING[i + 1],
|
||||
...t,
|
||||
};
|
||||
});
|
||||
|
||||
return {
|
||||
benefitTiers,
|
||||
stakingTiers,
|
||||
details: omit(data.currentReferralProgram, 'benefitTiers', 'stakingTiers'),
|
||||
loading,
|
||||
error,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,114 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { removePaginationWrapper } from '@vegaprotocol/utils';
|
||||
|
||||
const REFERRER_QUERY = gql`
|
||||
query ReferralSets($partyId: ID!) {
|
||||
referralSets(referrer: $partyId) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
referrer
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const REFEREE_QUERY = gql`
|
||||
query ReferralSets($partyId: ID!) {
|
||||
referralSets(referee: $partyId) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
referrer
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const REFEREES_QUERY = gql`
|
||||
query ReferralSets($code: ID!) {
|
||||
referralSetReferees(id: $code) {
|
||||
edges {
|
||||
node {
|
||||
referralSetId
|
||||
refereeId
|
||||
joinedAt
|
||||
atEpoch
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
// TODO: generate types after perps work is merged
|
||||
export type ReferralData = {
|
||||
code: string;
|
||||
referees: Array<{
|
||||
refereeId: string;
|
||||
joinedAt: string;
|
||||
atEpoch: number;
|
||||
}>;
|
||||
};
|
||||
|
||||
export const useReferral = (
|
||||
pubKey: string | null,
|
||||
role: 'referrer' | 'referee'
|
||||
) => {
|
||||
const query = {
|
||||
referrer: REFERRER_QUERY,
|
||||
referee: REFEREE_QUERY,
|
||||
};
|
||||
|
||||
const {
|
||||
data: referralData,
|
||||
loading: referralLoading,
|
||||
error: referralError,
|
||||
} = useQuery(query[role], {
|
||||
variables: {
|
||||
partyId: pubKey,
|
||||
},
|
||||
skip: !pubKey,
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
// A user can only have 1 active referral program at a time
|
||||
const referral = referralData?.referralSets.edges.length
|
||||
? referralData.referralSets.edges[0].node
|
||||
: undefined;
|
||||
|
||||
const {
|
||||
data: refereesData,
|
||||
loading: refereesLoading,
|
||||
error: refereesError,
|
||||
} = useQuery(REFEREES_QUERY, {
|
||||
variables: {
|
||||
code: referral?.id,
|
||||
},
|
||||
skip: !referral?.id,
|
||||
fetchPolicy: 'cache-and-network',
|
||||
});
|
||||
|
||||
const referees = removePaginationWrapper(
|
||||
refereesData?.referralSetReferees.edges
|
||||
);
|
||||
|
||||
const data =
|
||||
referral && refereesData
|
||||
? {
|
||||
code: referral.id,
|
||||
referees,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
data: data as ReferralData | undefined,
|
||||
loading: referralLoading || refereesLoading,
|
||||
error: referralError || refereesError,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
|
||||
const STAKE_QUERY = gql`
|
||||
query CreateCode($partyId: ID!) {
|
||||
party(id: $partyId) {
|
||||
stakingSummary {
|
||||
currentStakeAvailable
|
||||
}
|
||||
}
|
||||
networkParameter(key: "referralProgram.minStakedVegaTokens") {
|
||||
value
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const useStakeAvailable = () => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data } = useQuery(STAKE_QUERY, {
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
// TODO: remove when network params available
|
||||
errorPolicy: 'ignore',
|
||||
});
|
||||
|
||||
return {
|
||||
stakeAvailable: data
|
||||
? BigInt(data.party?.stakingSummary.currentStakeAvailable || '0')
|
||||
: undefined,
|
||||
requiredStake: data
|
||||
? BigInt(data.networkParameter?.value || '0')
|
||||
: undefined,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,52 @@
|
||||
import { Table } from './table';
|
||||
|
||||
export const HowItWorksTable = () => (
|
||||
<Table
|
||||
className="bg-none bg-vega-clight-800 dark:bg-vega-cdark-800"
|
||||
noHeader
|
||||
noCollapse
|
||||
columns={[{ name: 'number', className: 'pr-0' }, { name: 'step' }]}
|
||||
data={[
|
||||
{
|
||||
number: (
|
||||
<span className="text-2xl calt text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
1
|
||||
</span>
|
||||
),
|
||||
step: 'Referrers generate a code assigned to their key via an on chain transaction',
|
||||
},
|
||||
{
|
||||
number: (
|
||||
<span className="text-2xl calt text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
2
|
||||
</span>
|
||||
),
|
||||
step: 'Anyone with the referral link can apply it to their key(s) of choice via an on chain transaction',
|
||||
},
|
||||
{
|
||||
number: (
|
||||
<span className="text-2xl calt text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
3
|
||||
</span>
|
||||
),
|
||||
step: 'Discounts are applied automatically during trading based on the key(s) used',
|
||||
},
|
||||
{
|
||||
number: (
|
||||
<span className="text-2xl calt text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
4
|
||||
</span>
|
||||
),
|
||||
step: 'Referrers earn commission based on a percentage of the taker fees their referees pay',
|
||||
},
|
||||
{
|
||||
number: (
|
||||
<span className="text-2xl calt text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
5
|
||||
</span>
|
||||
),
|
||||
step: 'The commission is taken from the infrastructure fee, maker fee, and liquidity provider fee, not from the referee',
|
||||
},
|
||||
]}
|
||||
></Table>
|
||||
);
|
||||
@@ -0,0 +1,31 @@
|
||||
import classNames from 'classnames';
|
||||
import { AnimatedDudeWithWire } from './graphics/dude';
|
||||
|
||||
export const LandingBanner = () => {
|
||||
return (
|
||||
<div className={classNames('relative mb-20')}>
|
||||
<div className="">
|
||||
<div
|
||||
aria-hidden
|
||||
className="absolute top-64 right-[220px] md:right-[340px] max-sm:hidden"
|
||||
>
|
||||
<AnimatedDudeWithWire />
|
||||
</div>
|
||||
<div className="pt-32 sm:w-[50%]">
|
||||
<h1 className="text-6xl font-alpha calt mb-10">
|
||||
Earn commission & stake rewards
|
||||
</h1>
|
||||
<p className="text-lg mb-10">
|
||||
Invite friends and earn commission in the form of Vega rewards from
|
||||
the trading fees they pay. Stake those rewards to earn multipliers
|
||||
on future rewards.
|
||||
</p>
|
||||
<p className="text-lg">
|
||||
Any friends that join using the code will receive discounts off
|
||||
trading fees.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
import classNames from 'classnames';
|
||||
import type { HTMLAttributes } from 'react';
|
||||
import { SKY_BACKGROUND } from './constants';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
|
||||
export const Layout = ({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: HTMLAttributes<HTMLDivElement>) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'max-w-[1440px]',
|
||||
'mx-auto px-16 md:px-32 pb-32',
|
||||
'relative z-0',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children || <Outlet />}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const LayoutWithSky = ({
|
||||
className,
|
||||
...props
|
||||
}: HTMLAttributes<HTMLDivElement>) => {
|
||||
return (
|
||||
<div className={classNames('h-full overflow-auto', SKY_BACKGROUND)}>
|
||||
<Layout className={className} {...props} />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,113 @@
|
||||
import { Tile } from './tile';
|
||||
import {
|
||||
CopyWithTooltip,
|
||||
Input,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { Button, RainbowButton } from './buttons';
|
||||
|
||||
import { useVegaWallet, useVegaWalletDialogStore } from '@vegaprotocol/wallet';
|
||||
import type { ReferralData } from './hooks/use-referral';
|
||||
import { useReferral } from './hooks/use-referral';
|
||||
import { CreateCodeContainer } from './create-code-form';
|
||||
import classNames from 'classnames';
|
||||
|
||||
const CodeTile = ({
|
||||
code,
|
||||
as,
|
||||
}: {
|
||||
code: string;
|
||||
as: 'referrer' | 'referee';
|
||||
}) => {
|
||||
return (
|
||||
<Tile variant="rainbow">
|
||||
<h3 className="mb-1 text-lg calt">Your referral code</h3>
|
||||
{as === 'referrer' && (
|
||||
<p className="mb-3 text-sm text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
Share this code with friends
|
||||
</p>
|
||||
)}
|
||||
<div className="flex gap-2">
|
||||
<Input size={1} readOnly value={code} />
|
||||
<CopyWithTooltip text={code}>
|
||||
<Button
|
||||
className="text-sm no-underline"
|
||||
icon={<VegaIcon name={VegaIconNames.COPY} />}
|
||||
>
|
||||
<span>Copy</span>
|
||||
</Button>
|
||||
</CopyWithTooltip>
|
||||
</div>
|
||||
</Tile>
|
||||
);
|
||||
};
|
||||
|
||||
export const ReferralStatistics = () => {
|
||||
const openWalletDialog = useVegaWalletDialogStore(
|
||||
(store) => store.openVegaWalletDialog
|
||||
);
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const { data: referee } = useReferral(pubKey, 'referee');
|
||||
const { data: referrer } = useReferral(pubKey, 'referrer');
|
||||
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<div className="text-center">
|
||||
<RainbowButton variant="border" onClick={() => openWalletDialog()}>
|
||||
Connect wallet
|
||||
</RainbowButton>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (referee?.code) {
|
||||
return <Statistics data={referee} as="referee" />;
|
||||
}
|
||||
|
||||
if (referrer?.code) {
|
||||
return <Statistics data={referrer} as="referrer" />;
|
||||
}
|
||||
|
||||
return <CreateCodeContainer />;
|
||||
};
|
||||
|
||||
const Statistics = ({
|
||||
data,
|
||||
as,
|
||||
}: {
|
||||
data: ReferralData;
|
||||
as: 'referrer' | 'referee';
|
||||
}) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames('grid grid-cols-1 grid-rows-1 gap-5 mx-auto', {
|
||||
'md:w-1/2': as === 'referee',
|
||||
'md:w-2/3': as === 'referrer',
|
||||
})}
|
||||
>
|
||||
<div
|
||||
className={classNames('grid grid-rows-1 gap-5', {
|
||||
'grid-cols-2': as === 'referrer',
|
||||
'grid-cols-1': as === 'referee',
|
||||
})}
|
||||
>
|
||||
{as === 'referrer' && data?.referees && (
|
||||
<Tile className="py-3 h-full">
|
||||
<div className="absolute top-1/2 left-1/2 translate-x-[-50%] translate-y-[-50%]">
|
||||
<h3 className="mb-1 text-6xl text-center">
|
||||
{data.referees.length}
|
||||
</h3>
|
||||
<p className="text-sm text-center text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
{data.referees.length === 1
|
||||
? 'Trader referred'
|
||||
: 'Total traders referred'}
|
||||
</p>
|
||||
</div>
|
||||
</Tile>
|
||||
)}
|
||||
<CodeTile code={data?.code} as={as} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,59 @@
|
||||
import {
|
||||
TradingAnchorButton,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { HowItWorksTable } from './how-it-works-table';
|
||||
import { LandingBanner } from './landing-banner';
|
||||
import { TiersContainer } from './tiers';
|
||||
import { RainbowTabLink } from './buttons';
|
||||
import { Outlet } from 'react-router-dom';
|
||||
import { Routes } from '../../lib/links';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useReferral } from './hooks/use-referral';
|
||||
|
||||
export const Referrals = () => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data: referee } = useReferral(pubKey, 'referee');
|
||||
const { data: referrer } = useReferral(pubKey, 'referrer');
|
||||
|
||||
return (
|
||||
<>
|
||||
<LandingBanner />
|
||||
<div>
|
||||
<div className="flex justify-center">
|
||||
<RainbowTabLink end to={Routes.REFERRALS}>
|
||||
Your referrals
|
||||
</RainbowTabLink>
|
||||
<RainbowTabLink
|
||||
disabled={Boolean(referee || referrer)}
|
||||
to={Routes.REFERRALS_APPLY_CODE}
|
||||
>
|
||||
Apply a code
|
||||
</RainbowTabLink>
|
||||
</div>
|
||||
<div className="py-16 border-t border-b border-vega-cdark-500">
|
||||
<Outlet />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TiersContainer />
|
||||
|
||||
<div className="mt-10 mb-5 text-center">
|
||||
<h2 className="text-2xl">How it works</h2>
|
||||
</div>
|
||||
<div className="md:w-[60%] mx-auto">
|
||||
<HowItWorksTable />
|
||||
<div className="mt-5">
|
||||
<TradingAnchorButton
|
||||
className="mx-auto w-max"
|
||||
href="https://docs.vega.xyz/"
|
||||
target="_blank"
|
||||
>
|
||||
Read the terms <VegaIcon name={VegaIconNames.OPEN_EXTERNAL} />
|
||||
</TradingAnchorButton>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,116 @@
|
||||
import { Tooltip, VegaIcon, VegaIconNames } from '@vegaprotocol/ui-toolkit';
|
||||
import classNames from 'classnames';
|
||||
import type { HTMLAttributes } from 'react';
|
||||
import { BORDER_COLOR, GRADIENT } from './constants';
|
||||
|
||||
type TableColumnDefinition = {
|
||||
displayName?: string;
|
||||
name: string;
|
||||
tooltip?: string;
|
||||
className?: string;
|
||||
};
|
||||
|
||||
type TableProps = {
|
||||
columns: TableColumnDefinition[];
|
||||
data: Record<TableColumnDefinition['name'] | 'className', React.ReactNode>[];
|
||||
noHeader?: boolean;
|
||||
noCollapse?: boolean;
|
||||
};
|
||||
|
||||
const INNER_BORDER_STYLE = `border-b ${BORDER_COLOR}`;
|
||||
|
||||
export const Table = ({
|
||||
columns,
|
||||
data,
|
||||
noHeader = false,
|
||||
noCollapse = false,
|
||||
className,
|
||||
...props
|
||||
}: TableProps & HTMLAttributes<HTMLTableElement>) => {
|
||||
const header = (
|
||||
<thead className={classNames({ 'max-md:hidden': !noCollapse })}>
|
||||
<tr>
|
||||
{columns.map(({ displayName, name, tooltip }) => (
|
||||
<th
|
||||
key={name}
|
||||
col-id={name}
|
||||
className={classNames(
|
||||
'px-5 py-3 text-sm text-vega-clight-100 dark:text-vega-cdark-100',
|
||||
INNER_BORDER_STYLE
|
||||
)}
|
||||
>
|
||||
<span className="flex flex-row gap-2 items-center">
|
||||
<span>{displayName}</span>
|
||||
{tooltip ? (
|
||||
<Tooltip description={tooltip}>
|
||||
<button className="text-vega-clight-400 dark:text-vega-cdark-400 no-underline decoration-transparent w-[12px] h-[12px] inline-flex">
|
||||
<VegaIcon size={12} name={VegaIconNames.INFO} />
|
||||
</button>
|
||||
</Tooltip>
|
||||
) : null}
|
||||
</span>
|
||||
</th>
|
||||
))}
|
||||
</tr>
|
||||
</thead>
|
||||
);
|
||||
return (
|
||||
<table
|
||||
className={classNames(
|
||||
'w-full',
|
||||
'border-separate border rounded-md border-spacing-0',
|
||||
BORDER_COLOR,
|
||||
GRADIENT,
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{!noHeader && header}
|
||||
<tbody>
|
||||
{data.map((d, i) => (
|
||||
<tr
|
||||
key={i}
|
||||
className={classNames(d['className'] as string, {
|
||||
'max-md:flex flex-col w-full': !noCollapse,
|
||||
})}
|
||||
>
|
||||
{columns.map(({ name, displayName, className }, j) => (
|
||||
<td
|
||||
className={classNames(
|
||||
'px-5 py-3 text-base',
|
||||
{
|
||||
'max-md:flex max-md:flex-col max-md:justify-between':
|
||||
!noCollapse,
|
||||
},
|
||||
INNER_BORDER_STYLE,
|
||||
{
|
||||
'border-none': i === data.length - 1 && noCollapse,
|
||||
'md:border-none': i === data.length - 1,
|
||||
'max-md:border-none':
|
||||
i === data.length - 1 && j === columns.length - 1,
|
||||
},
|
||||
className
|
||||
)}
|
||||
key={`${i}-${name}`}
|
||||
>
|
||||
{/** display column name in mobile view */}
|
||||
{!noCollapse &&
|
||||
!noHeader &&
|
||||
displayName &&
|
||||
displayName.length > 0 && (
|
||||
<span
|
||||
aria-hidden
|
||||
className="md:hidden font-mono text-xs px-0 text-vega-clight-100 dark:text-vega-cdark-100"
|
||||
>
|
||||
{displayName}
|
||||
</span>
|
||||
)}
|
||||
<span>{d[name]}</span>
|
||||
</td>
|
||||
))}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
import type { HTMLAttributes } from 'react';
|
||||
import classNames from 'classnames';
|
||||
|
||||
type TagProps = {
|
||||
color?: 'yellow' | 'green' | 'blue' | 'purple' | 'pink' | 'orange' | 'none';
|
||||
};
|
||||
export const Tag = ({
|
||||
color = 'none',
|
||||
children,
|
||||
className,
|
||||
...props
|
||||
}: TagProps & HTMLAttributes<HTMLDivElement>) => (
|
||||
<div
|
||||
className={classNames(
|
||||
'mt-3 w-max border rounded-[1rem] py-[0.125rem] px-2 text-xs',
|
||||
{
|
||||
'border-vega-yellow-500 text-vega-yellow-500': color === 'yellow',
|
||||
'border-vega-green-500 text-vega-green-500': color === 'green',
|
||||
'border-vega-blue-500 text-vega-blue-500': color === 'blue',
|
||||
'border-vega-purple-500 text-vega-purple-500': color === 'purple',
|
||||
'border-vega-pink-500 text-vega-pink-500': color === 'pink',
|
||||
'border-vega-orange-500 text-vega-orange-500': color === 'orange',
|
||||
'border-vega-clight-100 text-vega-clight-100 dark:border-vega-cdark-100 dark:text-vega-cdark-100':
|
||||
color === 'none',
|
||||
},
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
@@ -0,0 +1,172 @@
|
||||
import { getDateTimeFormat } from '@vegaprotocol/utils';
|
||||
import { useReferralProgram } from './hooks/use-referral-program';
|
||||
import { Table } from './table';
|
||||
import classNames from 'classnames';
|
||||
import { BORDER_COLOR, GRADIENT } from './constants';
|
||||
import { Tag } from './tag';
|
||||
import type { ComponentProps } from 'react';
|
||||
|
||||
const Loading = ({ variant }: { variant: 'large' | 'inline' }) => (
|
||||
<div
|
||||
className={classNames(
|
||||
'bg-vega-clight-800 dark:bg-vega-cdark-800 rounded-lg animate-pulse',
|
||||
{
|
||||
'w-full h-20': variant === 'large',
|
||||
}
|
||||
)}
|
||||
></div>
|
||||
);
|
||||
|
||||
const StakingTier = ({
|
||||
tier,
|
||||
label,
|
||||
referralRewardMultiplier,
|
||||
minimumStakedTokens,
|
||||
}: {
|
||||
tier: number;
|
||||
label: string;
|
||||
referralRewardMultiplier: string;
|
||||
minimumStakedTokens: string;
|
||||
}) => {
|
||||
const color: Record<number, ComponentProps<typeof Tag>['color']> = {
|
||||
1: 'green',
|
||||
2: 'blue',
|
||||
3: 'pink',
|
||||
};
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'overflow-hidden',
|
||||
'border rounded-md w-full',
|
||||
BORDER_COLOR
|
||||
)}
|
||||
>
|
||||
<div aria-hidden>
|
||||
{tier < 4 && (
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
<img
|
||||
src={`/${tier}x.png`}
|
||||
alt={`${referralRewardMultiplier}x multiplier`}
|
||||
width={768}
|
||||
height={400}
|
||||
className="w-full"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className={classNames('p-3', GRADIENT)}>
|
||||
<h3 className="mb-3 text-xl">{label}</h3>
|
||||
<p className="text-base text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
Stake a minimum of {minimumStakedTokens} $VEGA tokens
|
||||
</p>
|
||||
<Tag color={color[tier]}>
|
||||
Reward multiplier {referralRewardMultiplier}x
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const TiersContainer = () => {
|
||||
const { benefitTiers, stakingTiers, details, loading } = useReferralProgram();
|
||||
|
||||
const ends = details?.endOfProgramTimestamp
|
||||
? getDateTimeFormat().format(new Date(details.endOfProgramTimestamp))
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="flex flex-row items-baseline justify-between mt-10 mb-5">
|
||||
<h2 className="text-2xl">Referral tiers</h2>
|
||||
{ends && (
|
||||
<span className="text-base">
|
||||
<span className="text-vega-clight-200 dark:text-vega-cdark-200">
|
||||
Program ends:
|
||||
</span>{' '}
|
||||
{ends}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<div className="mb-20">
|
||||
{loading || !benefitTiers || benefitTiers.length === 0 ? (
|
||||
<Loading variant="large" />
|
||||
) : (
|
||||
<TiersTable data={benefitTiers} />
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div className="flex flex-row items-baseline justify-between mb-5">
|
||||
<h2 className="text-2xl">Staking multipliers</h2>
|
||||
</div>
|
||||
<div className="flex flex-col mb-20 justify-items-stretch md:flex-row gap-5">
|
||||
{loading || !stakingTiers || stakingTiers.length === 0 ? (
|
||||
<>
|
||||
<Loading variant="large" />
|
||||
<Loading variant="large" />
|
||||
<Loading variant="large" />
|
||||
</>
|
||||
) : (
|
||||
<StakingTiers data={stakingTiers} />
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const StakingTiers = ({
|
||||
data,
|
||||
}: {
|
||||
data: ReturnType<typeof useReferralProgram>['stakingTiers'];
|
||||
}) => (
|
||||
<>
|
||||
{data.map(
|
||||
({ tier, label, referralRewardMultiplier, minimumStakedTokens }, i) => (
|
||||
<StakingTier
|
||||
key={i}
|
||||
tier={tier}
|
||||
label={label}
|
||||
referralRewardMultiplier={referralRewardMultiplier}
|
||||
minimumStakedTokens={minimumStakedTokens}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
</>
|
||||
);
|
||||
|
||||
const TiersTable = ({
|
||||
data,
|
||||
}: {
|
||||
data: Array<{
|
||||
tier: number;
|
||||
commission: string;
|
||||
discount: string;
|
||||
volume: string;
|
||||
}>;
|
||||
}) => {
|
||||
return (
|
||||
<Table
|
||||
columns={[
|
||||
{ name: 'tier', displayName: 'Tier' },
|
||||
{
|
||||
name: 'commission',
|
||||
displayName: 'Referrer commission',
|
||||
tooltip: 'A percentage of commission earned by the referrer',
|
||||
},
|
||||
{ name: 'discount', displayName: 'Referrer trading discount' },
|
||||
{ name: 'volume', displayName: 'Min. trading volume' },
|
||||
]}
|
||||
data={data.map((d) => ({
|
||||
...d,
|
||||
className: classNames({
|
||||
'from-vega-pink-400 dark:from-vega-pink-600 to-20% bg-highlight':
|
||||
d.tier === 1,
|
||||
'from-vega-purple-400 dark:from-vega-purple-600 to-20% bg-highlight':
|
||||
d.tier === 2,
|
||||
'from-vega-blue-400 dark:from-vega-blue-600 to-20% bg-highlight':
|
||||
d.tier === 3,
|
||||
'from-vega-orange-400 dark:from-vega-orange-600 to-20% bg-highlight':
|
||||
d.tier > 3,
|
||||
}),
|
||||
}))}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
import classNames from 'classnames';
|
||||
import type { HTMLAttributes } from 'react';
|
||||
import { BORDER_COLOR, GRADIENT } from './constants';
|
||||
|
||||
type TileProps = {
|
||||
variant?: 'rainbow' | 'default';
|
||||
};
|
||||
|
||||
export const Tile = ({
|
||||
variant = 'default',
|
||||
className,
|
||||
children,
|
||||
}: TileProps & HTMLAttributes<HTMLDivElement>) => {
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
{
|
||||
'bg-rainbow p-[0.125rem]': variant === 'rainbow',
|
||||
[`border-2 ${BORDER_COLOR} p-0`]: variant === 'default',
|
||||
},
|
||||
'rounded-lg overflow-hidden relative'
|
||||
)}
|
||||
>
|
||||
<div
|
||||
className={classNames(
|
||||
{
|
||||
'bg-white dark:bg-vega-cdark-900 text-black dark:text-white rounded-[0.35rem] overflow-hidden':
|
||||
variant === 'rainbow',
|
||||
},
|
||||
'p-6',
|
||||
GRADIENT,
|
||||
className
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -9,5 +9,11 @@ export const AnnouncementBanner = () => {
|
||||
return null;
|
||||
}
|
||||
|
||||
return <Banner app="console" configUrl={ANNOUNCEMENTS_CONFIG_URL} />;
|
||||
return (
|
||||
<Banner
|
||||
app="console"
|
||||
configUrl={ANNOUNCEMENTS_CONFIG_URL}
|
||||
background="url('/banner-bg.jpg')"
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -1,2 +1 @@
|
||||
export * from './announcement-banner';
|
||||
export * from './upgrade-banner';
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
import { useMemo, useState } from 'react';
|
||||
import { gt, prerelease } from 'semver';
|
||||
import {
|
||||
ReleasesFeed,
|
||||
useEnvironment,
|
||||
useReleases,
|
||||
Networks,
|
||||
} from '@vegaprotocol/environment';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import {
|
||||
CopyWithTooltip,
|
||||
ExternalLink,
|
||||
Intent,
|
||||
NotificationBanner,
|
||||
VegaIcon,
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
// v0.20.12-core-0.71.4 -> v0.20.12
|
||||
// we need to strip the "core" suffix in order to determine whether a release
|
||||
// is a pre-release (candidate); example: v.0.21.0-beta.1-core-0.71.4
|
||||
const parseTagName = (tagName: string) => tagName.replace(/-core-[\d.]+$/i, '');
|
||||
|
||||
type UpgradeBannerProps = {
|
||||
showVersionChange: boolean;
|
||||
};
|
||||
export const UpgradeBanner = ({ showVersionChange }: UpgradeBannerProps) => {
|
||||
const [visible, setVisible] = useState(true);
|
||||
const { data } = useReleases(ReleasesFeed.FrontEnd);
|
||||
const { APP_VERSION, VEGA_ENV, VEGA_NETWORKS } = useEnvironment();
|
||||
|
||||
const CANONICAL_URL = VEGA_NETWORKS[VEGA_ENV] || 'https://console.vega.xyz';
|
||||
|
||||
const newest = useMemo(() => {
|
||||
if (!APP_VERSION || !data) return undefined;
|
||||
const newer = data.filter((r) => gt(r.tagName, APP_VERSION));
|
||||
const valid =
|
||||
// filter pre-releases on mainnet
|
||||
VEGA_ENV === Networks.MAINNET
|
||||
? newer?.filter((r) => !prerelease(parseTagName(r.tagName)))
|
||||
: newer;
|
||||
return valid.sort((a, b) => (gt(a.tagName, b.tagName) ? -1 : 1))[0];
|
||||
}, [APP_VERSION, VEGA_ENV, data]);
|
||||
|
||||
if (!visible || !newest) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<NotificationBanner
|
||||
intent={Intent.Warning}
|
||||
onClose={() => {
|
||||
setVisible(false);
|
||||
}}
|
||||
>
|
||||
<div className="uppercase mb-1">
|
||||
<ExternalLink href={CANONICAL_URL}>
|
||||
{t('Upgrade to the latest version of Console')}
|
||||
</ExternalLink>
|
||||
</div>
|
||||
<div data-testid="bookmark-message">
|
||||
<a
|
||||
className="underline"
|
||||
href={newest.htmlUrl}
|
||||
rel="noreferrer nofollow noopener"
|
||||
target="_blank"
|
||||
>
|
||||
{t("View what's changed")}
|
||||
</a>{' '}
|
||||
{t(' or bookmark')}{' '}
|
||||
<a className="underline" href={CANONICAL_URL}>
|
||||
{t('console.vega.xyz')}
|
||||
</a>{' '}
|
||||
<CopyWithTooltip text={CANONICAL_URL}>
|
||||
<button title={t('Copy %s', CANONICAL_URL)}>
|
||||
<span className="sr-only">{t('Copy %s', CANONICAL_URL)}</span>
|
||||
<VegaIcon size={14} name={VegaIconNames.COPY} />
|
||||
</button>
|
||||
</CopyWithTooltip>{' '}
|
||||
{'to always see the latest version.'}
|
||||
</div>
|
||||
</NotificationBanner>
|
||||
);
|
||||
};
|
||||
@@ -38,7 +38,7 @@ export const FundingContainer = ({ marketId }: { marketId: string }) => {
|
||||
if (edge.node.endTime) {
|
||||
acc?.push({
|
||||
endTime: fromNanoSeconds(edge.node.endTime),
|
||||
fundingRate: Number(edge.node.fundingRate),
|
||||
fundingRate: Number(edge.node.fundingRate) * 100,
|
||||
});
|
||||
}
|
||||
return acc;
|
||||
@@ -51,5 +51,11 @@ export const FundingContainer = ({ marketId }: { marketId: string }) => {
|
||||
if (!data || !values?.rows.length) {
|
||||
return <Splash> {t('No funding history data')}</Splash>;
|
||||
}
|
||||
return <LineChart data={values} theme={theme} />;
|
||||
return (
|
||||
<LineChart
|
||||
data={values}
|
||||
theme={theme}
|
||||
priceFormat={(fundingRate) => `${fundingRate.toFixed(4)}%`}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -53,7 +53,7 @@ export const HeaderStat = ({
|
||||
<div data-testid="item-header" id={id}>
|
||||
{heading}
|
||||
</div>
|
||||
<Tooltip description={description}>
|
||||
<Tooltip description={description} underline>
|
||||
<div
|
||||
data-testid="item-value"
|
||||
aria-labelledby={id}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { MarketSelector } from '../../components/market-selector/market-selector
|
||||
import { MarketHeaderStats } from '../../client-pages/market/market-header-stats';
|
||||
import { useMarket, useMarketList } from '@vegaprotocol/markets';
|
||||
import { useState } from 'react';
|
||||
import { MarketProductPill } from '@vegaprotocol/datagrid';
|
||||
import { ProductTypeShortName } from '@vegaprotocol/types';
|
||||
|
||||
export const MarketHeader = () => {
|
||||
const { marketId } = useParams();
|
||||
@@ -28,11 +28,13 @@ export const MarketHeader = () => {
|
||||
<HeaderTitle>
|
||||
<span>
|
||||
{data.tradableInstrument.instrument.code}
|
||||
<MarketProductPill
|
||||
productType={
|
||||
data.tradableInstrument.instrument.product.__typename
|
||||
}
|
||||
/>
|
||||
<span className="ml-2 text-xs uppercase text-muted">
|
||||
{' '}
|
||||
{data.tradableInstrument.instrument.product.__typename &&
|
||||
ProductTypeShortName[
|
||||
data.tradableInstrument.instrument.product.__typename
|
||||
]}{' '}
|
||||
</span>
|
||||
</span>
|
||||
<VegaIcon name={VegaIconNames.CHEVRON_DOWN} size={14} />
|
||||
</HeaderTitle>
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import { Navbar } from './navbar';
|
||||
import { useGlobalStore } from '../../stores';
|
||||
import { ENV, FLAGS } from '@vegaprotocol/environment';
|
||||
|
||||
jest.mock('@vegaprotocol/proposals', () => ({
|
||||
ProtocolUpgradeCountdown: () => null,
|
||||
@@ -47,6 +48,14 @@ describe('Navbar', () => {
|
||||
|
||||
beforeAll(() => {
|
||||
useGlobalStore.setState({ marketId });
|
||||
const mockedFLAGS = jest.mocked(FLAGS);
|
||||
mockedFLAGS.REFERRALS = true;
|
||||
const mockedENV = jest.mocked(ENV);
|
||||
mockedENV.VEGA_TOKEN_URL = 'governance';
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('should be properly rendered', () => {
|
||||
@@ -57,6 +66,7 @@ describe('Navbar', () => {
|
||||
['/markets/all', 'Markets'],
|
||||
[`/markets/${marketId}`, 'Trading'],
|
||||
['/portfolio', 'Portfolio'],
|
||||
['/referrals', 'Referrals'],
|
||||
[expect.stringContaining('governance'), 'Governance'],
|
||||
];
|
||||
|
||||
@@ -89,6 +99,7 @@ describe('Navbar', () => {
|
||||
['/markets/all', 'Markets'],
|
||||
[`/markets/${marketId}`, 'Trading'],
|
||||
['/portfolio', 'Portfolio'],
|
||||
['/referrals', 'Referrals'],
|
||||
[expect.stringContaining('governance'), 'Governance'],
|
||||
];
|
||||
const links = menu.getAllByRole('link');
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Networks,
|
||||
DApp,
|
||||
useLinks,
|
||||
FLAGS,
|
||||
} from '@vegaprotocol/environment';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import { useGlobalStore } from '../../stores';
|
||||
@@ -140,10 +141,6 @@ const NavbarMenu = ({ onClick }: { onClick: () => void }) => {
|
||||
const { VEGA_ENV, VEGA_NETWORKS, GITHUB_FEEDBACK_URL } = useEnvironment();
|
||||
const marketId = useGlobalStore((store) => store.marketId);
|
||||
|
||||
// If we have a stored marketId make Trade link go to that market
|
||||
// otherwise always go to /markets/all
|
||||
const tradingPath = marketId ? Links.MARKET(marketId) : Links.MARKETS();
|
||||
|
||||
return (
|
||||
<div className="lg:flex lg:h-full gap-3">
|
||||
<NavbarList>
|
||||
@@ -174,7 +171,7 @@ const NavbarMenu = ({ onClick }: { onClick: () => void }) => {
|
||||
</NavbarLink>
|
||||
</NavbarItem>
|
||||
<NavbarItem>
|
||||
<NavbarLink to={tradingPath} onClick={onClick}>
|
||||
<NavbarLink to={Links.MARKET(marketId || '')} onClick={onClick}>
|
||||
{t('Trading')}
|
||||
</NavbarLink>
|
||||
</NavbarItem>
|
||||
@@ -183,6 +180,13 @@ const NavbarMenu = ({ onClick }: { onClick: () => void }) => {
|
||||
{t('Portfolio')}
|
||||
</NavbarLink>
|
||||
</NavbarItem>
|
||||
{FLAGS.REFERRALS && (
|
||||
<NavbarItem>
|
||||
<NavbarLink to={Links.REFERRALS()} onClick={onClick}>
|
||||
{t('Referrals')}
|
||||
</NavbarLink>
|
||||
</NavbarItem>
|
||||
)}
|
||||
<NavbarItem>
|
||||
<NavbarLinkExternal to={useLinks(DApp.Governance)()}>
|
||||
{t('Governance')}
|
||||
|
||||
@@ -55,7 +55,6 @@ const MarketSidebarButtons = () => {
|
||||
|
||||
return (
|
||||
<>
|
||||
<SidebarDivider />
|
||||
<SidebarButton
|
||||
view={ViewType.Order}
|
||||
icon={VegaIconNames.TICKET}
|
||||
@@ -72,6 +71,33 @@ const MarketSidebarButtons = () => {
|
||||
);
|
||||
};
|
||||
|
||||
const AssetSidebarButtons = () => {
|
||||
const currentRouteId = useGetCurrentRouteId();
|
||||
|
||||
return (
|
||||
<>
|
||||
<SidebarButton
|
||||
view={ViewType.Deposit}
|
||||
icon={VegaIconNames.DEPOSIT}
|
||||
tooltip={t('Deposit')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
<SidebarButton
|
||||
view={ViewType.Withdraw}
|
||||
icon={VegaIconNames.WITHDRAW}
|
||||
tooltip={t('Withdraw')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
<SidebarButton
|
||||
view={ViewType.Transfer}
|
||||
icon={VegaIconNames.TRANSFER}
|
||||
tooltip={t('Transfer')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const Sidebar = () => {
|
||||
const currentRouteId = useGetCurrentRouteId();
|
||||
const navClasses = 'flex lg:flex-col items-center gap-2 lg:gap-4 p-1';
|
||||
@@ -80,41 +106,34 @@ export const Sidebar = () => {
|
||||
return (
|
||||
<div className="flex h-full p-1 lg:flex-col gap-2" data-testid="sidebar">
|
||||
<nav className={navClasses}>
|
||||
{/* sidebar options that always show */}
|
||||
<SidebarButton
|
||||
view={ViewType.Deposit}
|
||||
icon={VegaIconNames.DEPOSIT}
|
||||
tooltip={t('Deposit')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
<SidebarButton
|
||||
view={ViewType.Withdraw}
|
||||
icon={VegaIconNames.WITHDRAW}
|
||||
tooltip={t('Withdraw')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
<SidebarButton
|
||||
view={ViewType.Transfer}
|
||||
icon={VegaIconNames.TRANSFER}
|
||||
tooltip={t('Transfer')}
|
||||
routeId={currentRouteId}
|
||||
/>
|
||||
{/* buttons for specific routes */}
|
||||
<Routes>
|
||||
<Route path="markets/all" element={<AssetSidebarButtons />} />
|
||||
<Route path="portfolio">
|
||||
<Route
|
||||
// Show deposit/withdraw/transfer sidebar options only on portflio dashboard (index)
|
||||
index={true}
|
||||
element={<AssetSidebarButtons />}
|
||||
/>
|
||||
</Route>
|
||||
<Route
|
||||
path="markets/all"
|
||||
// render nothing for markets/all, otherwise markets/:marketId will match with markets/all
|
||||
element={null}
|
||||
path="markets/:marketId"
|
||||
element={
|
||||
<>
|
||||
<AssetSidebarButtons />
|
||||
<SidebarDivider />
|
||||
<MarketSidebarButtons />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
<Route
|
||||
// render nothing for portfolio
|
||||
path="portfolio"
|
||||
element={null}
|
||||
/>
|
||||
<Route path="markets/:marketId" element={<MarketSidebarButtons />} />
|
||||
<Route
|
||||
path="liquidity/:marketId"
|
||||
element={<MarketSidebarButtons />}
|
||||
element={
|
||||
<>
|
||||
<AssetSidebarButtons />
|
||||
<SidebarDivider />
|
||||
<MarketSidebarButtons />
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</Routes>
|
||||
</nav>
|
||||
|
||||
@@ -27,8 +27,8 @@ const GetStartedButton = ({ step }: { step: OnboardingStep }) => {
|
||||
const dismiss = useOnboardingStore((store) => store.dismiss);
|
||||
const setDialogOpen = useOnboardingStore((store) => store.setDialogOpen);
|
||||
const marketId = useGlobalStore((store) => store.marketId);
|
||||
const openVegaWalletDialog = useVegaWalletDialogStore(
|
||||
(store) => store.openVegaWalletDialog
|
||||
const setWalletDialogOpen = useOnboardingStore(
|
||||
(store) => store.setWalletDialogOpen
|
||||
);
|
||||
const setViews = useSidebar((store) => store.setViews);
|
||||
|
||||
@@ -40,7 +40,7 @@ const GetStartedButton = ({ step }: { step: OnboardingStep }) => {
|
||||
|
||||
if (step <= OnboardingStep.ONBOARDING_CONNECT_STEP) {
|
||||
return (
|
||||
<TradingButton {...buttonProps} onClick={() => openVegaWalletDialog()}>
|
||||
<TradingButton {...buttonProps} onClick={() => setWalletDialogOpen(true)}>
|
||||
{t('Connect')}
|
||||
</TradingButton>
|
||||
);
|
||||
@@ -71,7 +71,7 @@ const GetStartedButton = ({ step }: { step: OnboardingStep }) => {
|
||||
}
|
||||
|
||||
return (
|
||||
<TradingButton {...buttonProps} onClick={() => openVegaWalletDialog()}>
|
||||
<TradingButton {...buttonProps} onClick={() => setWalletDialogOpen(true)}>
|
||||
{t('Get started')}
|
||||
</TradingButton>
|
||||
);
|
||||
|
||||
@@ -12,16 +12,20 @@ import { useGlobalStore } from '../../stores';
|
||||
const ONBOARDING_STORAGE_KEY = 'vega_onboarding';
|
||||
export const useOnboardingStore = create<{
|
||||
dialogOpen: boolean;
|
||||
walletDialogOpen: boolean;
|
||||
dismissed: boolean;
|
||||
dismiss: () => void;
|
||||
setDialogOpen: (isOpen: boolean) => void;
|
||||
setWalletDialogOpen: (isOpen: boolean) => void;
|
||||
}>()(
|
||||
persist(
|
||||
(set) => ({
|
||||
dialogOpen: true,
|
||||
walletDialogOpen: false,
|
||||
dismissed: false,
|
||||
dismiss: () => set({ dismissed: true }),
|
||||
setDialogOpen: (isOpen) => set({ dialogOpen: isOpen }),
|
||||
setWalletDialogOpen: (isOpen) => set({ walletDialogOpen: isOpen }),
|
||||
}),
|
||||
{
|
||||
name: ONBOARDING_STORAGE_KEY,
|
||||
|
||||
@@ -3,30 +3,54 @@ import { t } from '@vegaprotocol/i18n';
|
||||
import { useEnvironment } from '@vegaprotocol/environment';
|
||||
import { WelcomeDialogContent } from './welcome-dialog-content';
|
||||
import { useOnboardingStore } from './use-get-onboarding-step';
|
||||
import { VegaConnectDialog } from '@vegaprotocol/wallet';
|
||||
import { Connectors } from '../../lib/vega-connectors';
|
||||
import { RiskMessage } from './risk-message';
|
||||
|
||||
export const WelcomeDialog = () => {
|
||||
const { VEGA_ENV } = useEnvironment();
|
||||
const dismissed = useOnboardingStore((store) => store.dismissed);
|
||||
const dialogOpen = useOnboardingStore((store) => store.dialogOpen);
|
||||
const dismiss = useOnboardingStore((store) => store.dismiss);
|
||||
const walletDialogOpen = useOnboardingStore(
|
||||
(store) => store.walletDialogOpen
|
||||
);
|
||||
const setWalletDialogOpen = useOnboardingStore(
|
||||
(store) => store.setWalletDialogOpen
|
||||
);
|
||||
|
||||
const content = walletDialogOpen ? (
|
||||
<VegaConnectDialog
|
||||
connectors={Connectors}
|
||||
riskMessage={<RiskMessage />}
|
||||
onClose={() => setWalletDialogOpen(false)}
|
||||
contentOnly
|
||||
/>
|
||||
) : (
|
||||
<WelcomeDialogContent />
|
||||
);
|
||||
|
||||
const onClose = walletDialogOpen ? () => setWalletDialogOpen(false) : dismiss;
|
||||
|
||||
const title = walletDialogOpen ? null : (
|
||||
<span className="font-alpha calt" data-testid="welcome-title">
|
||||
{t('Console')}{' '}
|
||||
<span className="text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
{VEGA_ENV}
|
||||
</span>
|
||||
</span>
|
||||
);
|
||||
|
||||
return (
|
||||
<Dialog
|
||||
open={dismissed ? false : dialogOpen}
|
||||
title={
|
||||
<span className="font-alpha calt" data-testid="welcome-title">
|
||||
{t('Console')}{' '}
|
||||
<span className="text-vega-clight-100 dark:text-vega-cdark-100">
|
||||
{VEGA_ENV}
|
||||
</span>
|
||||
</span>
|
||||
}
|
||||
title={title}
|
||||
size="medium"
|
||||
onChange={() => dismiss()}
|
||||
onChange={onClose}
|
||||
intent={Intent.None}
|
||||
dataTestId="welcome-dialog"
|
||||
>
|
||||
<WelcomeDialogContent />
|
||||
{content}
|
||||
</Dialog>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -13,6 +13,10 @@ export const Routes = {
|
||||
DEPOSIT: '/portfolio/assets/deposit',
|
||||
WITHDRAW: '/portfolio/assets/withdraw',
|
||||
TRANSFER: '/portfolio/assets/transfer',
|
||||
REFERRALS: '/referrals',
|
||||
REFERRALS_APPLY_CODE: '/referrals/apply-code',
|
||||
REFERRALS_CREATE_CODE: '/referrals/create-code',
|
||||
TEAMS: '/teams',
|
||||
} as const;
|
||||
|
||||
type ConsoleLinks = {
|
||||
@@ -32,4 +36,8 @@ export const Links: ConsoleLinks = {
|
||||
DEPOSIT: () => Routes.DEPOSIT,
|
||||
WITHDRAW: () => Routes.WITHDRAW,
|
||||
TRANSFER: () => Routes.TRANSFER,
|
||||
REFERRALS: () => Routes.REFERRALS,
|
||||
REFERRALS_APPLY_CODE: () => Routes.REFERRALS_APPLY_CODE,
|
||||
REFERRALS_CREATE_CODE: () => Routes.REFERRALS_CREATE_CODE,
|
||||
TEAMS: () => Routes.TEAMS,
|
||||
};
|
||||
|
||||
@@ -38,7 +38,7 @@ import { AppLoader, DynamicLoader } from '../components/app-loader';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import { activeOrdersProvider } from '@vegaprotocol/orders';
|
||||
import { useTelemetryApproval } from '../lib/hooks/use-telemetry-approval';
|
||||
import { AnnouncementBanner, UpgradeBanner } from '../components/banner';
|
||||
import { AnnouncementBanner } from '../components/banner';
|
||||
import { Navbar } from '../components/navbar';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
@@ -115,7 +115,6 @@ function AppBody({ Component }: AppProps) {
|
||||
/>
|
||||
<ProtocolUpgradeInProgressNotification />
|
||||
<ViewingBanner />
|
||||
<UpgradeBanner showVersionChange={true} />
|
||||
</div>
|
||||
<div data-testid={`pathname-${location.pathname}`}>
|
||||
<Component />
|
||||
|
||||
@@ -4,33 +4,24 @@ export default function Document() {
|
||||
return (
|
||||
<>
|
||||
<Head>
|
||||
{/*
|
||||
{/*
|
||||
meta tags
|
||||
- next advised against using _document for this, so they exist in our
|
||||
- next advised against using _document for this, so they exist in our
|
||||
- single page index.page.tsx
|
||||
*/}
|
||||
|
||||
{/* icons */}
|
||||
<link
|
||||
rel="icon"
|
||||
type="image/x-icon"
|
||||
href="https://static.vega.xyz/favicon.ico"
|
||||
/>
|
||||
<link
|
||||
rel="apple-touch-icon"
|
||||
content="https://static.vega.xyz/favicon.ico"
|
||||
/>
|
||||
|
||||
{/* fonts */}
|
||||
{/* preload fonts */}
|
||||
<link
|
||||
rel="preload"
|
||||
href="https://static.vega.xyz/AlphaLyrae-Medium.woff2"
|
||||
href="/AlphaLyrae-Medium.woff2"
|
||||
as="font"
|
||||
type="font/woff2"
|
||||
/>
|
||||
|
||||
{/* styles */}
|
||||
<link rel="stylesheet" href="https://static.vega.xyz/fonts.css" />
|
||||
{/* icons */}
|
||||
<link rel="icon" type="image/x-icon" href="/favicon.ico" />
|
||||
<link rel="apple-touch-icon" content="/favicon.ico" />
|
||||
|
||||
{/* eslint-disable-next-line @next/next/no-css-tags */}
|
||||
<link rel="stylesheet" href="/preloader.css" media="all" />
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@ import { Deposit } from '../client-pages/deposit';
|
||||
import { Withdraw } from '../client-pages/withdraw';
|
||||
import { Transfer } from '../client-pages/transfer';
|
||||
import { Routes } from '../lib/links';
|
||||
import { LayoutWithSky } from '../client-pages/referrals/layout';
|
||||
import { Referrals } from '../client-pages/referrals/referrals';
|
||||
import { ReferralStatistics } from '../client-pages/referrals/referral-statistics';
|
||||
import { ApplyCodeForm } from '../client-pages/referrals/apply-code-form';
|
||||
import { CreateCodeContainer } from '../client-pages/referrals/create-code-form';
|
||||
import { NotFound as ReferralNotFound } from '../client-pages/referrals/error-boundary';
|
||||
import { compact } from 'lodash';
|
||||
import { FLAGS } from '@vegaprotocol/environment';
|
||||
|
||||
// These must remain dynamically imported as pennant cannot be compiled by nextjs due to ESM
|
||||
// Using dynamic imports is a workaround for this until pennant is published as ESM
|
||||
@@ -26,8 +34,8 @@ const NotFound = () => (
|
||||
</Splash>
|
||||
);
|
||||
|
||||
export const routerConfig: RouteObject[] = [
|
||||
// Pages that dont use the LayoutWithSidebar must come first
|
||||
export const routerConfig: RouteObject[] = compact([
|
||||
// Pages that don't use the LayoutWithSidebar must come first
|
||||
// to ensure they are matched before the catch all route '/*'
|
||||
{
|
||||
path: 'disclaimer',
|
||||
@@ -35,7 +43,36 @@ export const routerConfig: RouteObject[] = [
|
||||
id: Routes.DISCLAIMER,
|
||||
children: [{ index: true, element: <Disclaimer /> }],
|
||||
},
|
||||
|
||||
// Referrals routing (the pages should be available if the feature flag is on)
|
||||
FLAGS.REFERRALS
|
||||
? {
|
||||
path: Routes.REFERRALS,
|
||||
element: <LayoutWithSky />,
|
||||
children: [
|
||||
{
|
||||
element: <Referrals />,
|
||||
children: [
|
||||
{
|
||||
index: true,
|
||||
element: <ReferralStatistics />,
|
||||
},
|
||||
{
|
||||
path: Routes.REFERRALS_CREATE_CODE,
|
||||
element: <CreateCodeContainer />,
|
||||
},
|
||||
{
|
||||
path: Routes.REFERRALS_APPLY_CODE,
|
||||
element: <ApplyCodeForm />,
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
path: '*',
|
||||
element: <ReferralNotFound />,
|
||||
},
|
||||
],
|
||||
}
|
||||
: undefined,
|
||||
// All other pages will use the sidebar
|
||||
{
|
||||
path: '/*',
|
||||
@@ -93,7 +130,6 @@ export const routerConfig: RouteObject[] = [
|
||||
element: <Liquidity />,
|
||||
id: Routes.LIQUIDITY,
|
||||
},
|
||||
|
||||
// NotFound page is here so its caught within parent '/*' route
|
||||
{
|
||||
path: '*',
|
||||
@@ -101,7 +137,7 @@ export const routerConfig: RouteObject[] = [
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
]);
|
||||
|
||||
export const ClientRouter = () => {
|
||||
const routes = useRoutes(routerConfig);
|
||||
|
||||
@@ -19,17 +19,11 @@ export default function Index() {
|
||||
<meta name="og:url" content="https://console.vega.xyz/" />
|
||||
<meta name="og:title" content="Vega Protocol - Console" />
|
||||
<meta name="og:site_name" content="Vega Protocol - Console" />
|
||||
<meta name="og:image" content="https://static.vega.xyz/favicon.ico" />
|
||||
<meta
|
||||
name="twitter:card"
|
||||
content="https://static.vega.xyz/favicon.ico"
|
||||
/>
|
||||
<meta name="og:image" content="./favicon.ico" />
|
||||
<meta name="twitter:card" content="./favicon.ico" />
|
||||
<meta name="twitter:title" content="Vega Protocol - Console" />
|
||||
<meta name="twitter:description" content="Vega Protocol - Console" />
|
||||
<meta
|
||||
name="twitter:image"
|
||||
content="https://static.vega.xyz/favicon.ico"
|
||||
/>
|
||||
<meta name="twitter:image" content="./favicon.ico" />
|
||||
<meta name="twitter:image:alt" content="VEGA logo" />
|
||||
<meta name="twitter:site" content="@vegaprotocol" />
|
||||
</Head>
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
@import 'ag-grid-community/styles/ag-grid.css';
|
||||
@import 'ag-grid-community/styles/ag-theme-balham.css';
|
||||
|
||||
/** Load AlphaLyrae font */
|
||||
@font-face {
|
||||
font-family: AlphaLyrae;
|
||||
src: url('/AlphaLyrae-Medium.woff2') format('woff2'),
|
||||
url('/AlphaLyrae-Medium.woff') format('woff');
|
||||
}
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
@@ -103,8 +110,8 @@ html [data-theme='light'] {
|
||||
--pennant-color-depth-sell-fill: theme(colors.market.red.DEFAULT);
|
||||
--pennant-color-depth-sell-stroke: theme(colors.market.red.650);
|
||||
|
||||
--pennant-color-volume-buy: theme(colors.market.green.300);
|
||||
--pennant-color-volume-sell: theme(colors.market.red.300);
|
||||
--pennant-color-volume-buy: theme(colors.market.green.DEFAULT);
|
||||
--pennant-color-volume-sell: theme(colors.market.red.DEFAULT);
|
||||
}
|
||||
|
||||
html [data-theme='dark'] {
|
||||
@@ -125,7 +132,7 @@ html [data-theme='dark'] {
|
||||
--pennant-color-depth-sell-stroke: theme(colors.market.red.DEFAULT);
|
||||
|
||||
--pennant-color-volume-buy: theme(colors.market.green.600);
|
||||
--pennant-color-volume-sell: theme(colors.market.red.650);
|
||||
--pennant-color-volume-sell: theme(colors.market.red.DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
|
After Width: | Height: | Size: 614 KiB |
|
After Width: | Height: | Size: 572 KiB |
|
After Width: | Height: | Size: 574 KiB |
|
After Width: | Height: | Size: 101 KiB |
|
After Width: | Height: | Size: 7.2 KiB |
|
After Width: | Height: | Size: 947 KiB |
|
After Width: | Height: | Size: 947 KiB |
@@ -13,7 +13,37 @@ module.exports = {
|
||||
],
|
||||
darkMode: 'class',
|
||||
theme: {
|
||||
extend: theme,
|
||||
extend: {
|
||||
...theme,
|
||||
colors: {
|
||||
transparent: 'transparent',
|
||||
current: 'currentColor',
|
||||
...theme.colors,
|
||||
},
|
||||
backgroundImage: {
|
||||
...theme.backgroundImage,
|
||||
rainbow:
|
||||
'linear-gradient(103.47deg, #FF077F 1.68%, #8028FF 47.49%, #0075FF 100%)',
|
||||
'rainbow-shifted':
|
||||
'linear-gradient(103.47deg, #0075FF 1.68%, #8028FF 47.49%, #FF077F 100%)',
|
||||
highlight:
|
||||
'linear-gradient(170deg, var(--tw-gradient-from), transparent var(--tw-gradient-to-position))',
|
||||
},
|
||||
keyframes: {
|
||||
...theme.keyframes,
|
||||
shake: {
|
||||
'0%': { transform: 'translateX(0)' },
|
||||
'25%': { transform: 'translateX(5px)' },
|
||||
'50%': { transform: 'translateX(-5px)' },
|
||||
'75%': { transform: 'translateX(5px)' },
|
||||
'100%': { transform: 'translateX(0)' },
|
||||
},
|
||||
},
|
||||
animation: {
|
||||
...theme.animation,
|
||||
shake: 'shake 200ms linear',
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [vegaCustomClasses],
|
||||
};
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
entrypoint="${1:-nginx}"
|
||||
|
||||
if [[ "$entrypoint" = "nginx" ]]; then
|
||||
nginx -g 'daemon off;'
|
||||
elif [[ "$entrypoint" = "ipfs" ]]; then
|
||||
ipfs config profile apply server
|
||||
ipfs config --json Addresses.Gateway '"/ip4/127.0.0.1/tcp/80"'
|
||||
ipfs daemon
|
||||
elif [[ "-c" ]]; then
|
||||
shift
|
||||
/bin/sh -c "$@"
|
||||
fi
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
VegaIconNames,
|
||||
TooltipCellComponent,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import type {
|
||||
IGetRowsParams,
|
||||
IRowNode,
|
||||
|
||||
@@ -13,7 +13,7 @@ import type {
|
||||
VegaICellRendererParams,
|
||||
} from '@vegaprotocol/datagrid';
|
||||
import { ProgressBarCell } from '@vegaprotocol/datagrid';
|
||||
import { AgGridLazy as AgGrid, PriceCell } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid, PriceCell } from '@vegaprotocol/datagrid';
|
||||
import type { ColDef } from 'ag-grid-community';
|
||||
import { accountValuesComparator } from './accounts-table';
|
||||
import { MarginHealthChart } from './margin-health-chart';
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
export type AnnouncementBannerProps = {
|
||||
app: AppNameType;
|
||||
configUrl: string;
|
||||
background?: string;
|
||||
};
|
||||
|
||||
// run only if below the allowed maximum delay ~24.8 days (https://developer.mozilla.org/en-US/docs/Web/API/setTimeout#maximum_delay_value)
|
||||
@@ -36,6 +37,7 @@ const doesEndInTheFuture = (now: Date, data: Announcement) => {
|
||||
export const AnnouncementBanner = ({
|
||||
app,
|
||||
configUrl,
|
||||
background,
|
||||
}: AnnouncementBannerProps) => {
|
||||
const [isVisible, setVisible] = useState(false);
|
||||
const { data, reload } = useAnnouncement(app, configUrl);
|
||||
@@ -79,10 +81,10 @@ export const AnnouncementBanner = ({
|
||||
}
|
||||
|
||||
return (
|
||||
<Banner className="relative px-10">
|
||||
<Banner className="relative px-10" background={background}>
|
||||
<div
|
||||
data-testid="app-announcement"
|
||||
className="relative font-alpha flex gap-2 justify-center text-center text-lg text-white"
|
||||
className="relative flex justify-center text-lg text-center text-white font-alpha gap-2"
|
||||
>
|
||||
<span>{data.text}</span>{' '}
|
||||
{data.urlText && data.url && (
|
||||
@@ -90,7 +92,7 @@ export const AnnouncementBanner = ({
|
||||
)}
|
||||
</div>
|
||||
<button
|
||||
className="absolute right-0 top-0 p-4 w-10 h-full flex items-center justify-center text-white"
|
||||
className="absolute top-0 right-0 flex items-center justify-center w-10 h-full p-4 text-white"
|
||||
data-testid="app-announcement-close"
|
||||
onClick={() => {
|
||||
setVisible(false);
|
||||
|
||||
@@ -13,7 +13,7 @@ import { createLog } from './logging';
|
||||
import { getMarkets } from './get-markets';
|
||||
import { createWalletClient } from './wallet-client';
|
||||
import { createEthereumWallet } from './ethereum-wallet';
|
||||
import { ASSET_ID_FOR_MARKET } from './contants';
|
||||
import { ASSET_ID_FOR_MARKET } from './constants';
|
||||
|
||||
const log = createLog('create-market');
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { createLog } from './logging';
|
||||
import type { ProposalSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { getProposal } from './get-proposal';
|
||||
import { sendVegaTx } from './wallet-client';
|
||||
import { ASSET_ID_FOR_MARKET, ASSET_SYMBOL } from './contants';
|
||||
import { ASSET_ID_FOR_MARKET, ASSET_SYMBOL } from './constants';
|
||||
|
||||
const log = createLog('propose-market');
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export * from './lib/ag-grid/ag-grid-lazy';
|
||||
export * from './lib/ag-grid/ag-grid';
|
||||
|
||||
export * from './lib/column-definitions';
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { forwardRef, lazy } from 'react';
|
||||
import type { AgGridReactProps, AgGridReact } from 'ag-grid-react';
|
||||
|
||||
type Props = AgGridReactProps & {
|
||||
style?: React.CSSProperties;
|
||||
gridRef?: React.Ref<AgGridReact>;
|
||||
};
|
||||
|
||||
export const AgGridLazyInternal = lazy(() =>
|
||||
import('./ag-grid-lazy-themed').then((module) => ({
|
||||
default: module.AgGridThemed,
|
||||
}))
|
||||
);
|
||||
|
||||
export const AgGridLazy = forwardRef<AgGridReact, Props>((props, ref) => (
|
||||
<AgGridLazyInternal {...props} gridRef={ref} />
|
||||
));
|
||||
@@ -0,0 +1,12 @@
|
||||
import { forwardRef } from 'react';
|
||||
import type { AgGridReactProps, AgGridReact } from 'ag-grid-react';
|
||||
import { AgGridThemed } from './ag-grid-themed';
|
||||
|
||||
type Props = AgGridReactProps & {
|
||||
style?: React.CSSProperties;
|
||||
gridRef?: React.Ref<AgGridReact>;
|
||||
};
|
||||
|
||||
export const AgGrid = forwardRef<AgGridReact, Props>((props, ref) => (
|
||||
<AgGridThemed {...props} gridRef={ref} />
|
||||
));
|
||||
@@ -1,13 +1,12 @@
|
||||
import { act, render, waitFor } from '@testing-library/react';
|
||||
import {
|
||||
useDataGridEvents,
|
||||
GRID_EVENT_DEBOUNCE_TIME,
|
||||
} from './use-datagrid-events';
|
||||
import { AgGridThemed } from './ag-grid/ag-grid-lazy-themed';
|
||||
import { useDataGridEvents } from './use-datagrid-events';
|
||||
import { AgGridThemed } from './ag-grid/ag-grid-themed';
|
||||
import type { MutableRefObject } from 'react';
|
||||
import { useRef } from 'react';
|
||||
import type { AgGridReact } from 'ag-grid-react';
|
||||
|
||||
const GRID_EVENT_DEBOUNCE_TIME = 500;
|
||||
|
||||
const gridProps = {
|
||||
rowData: [{ id: 1 }],
|
||||
columnDefs: [
|
||||
|
||||
@@ -12,6 +12,7 @@ import { formatRange, formatValue } from '@vegaprotocol/utils';
|
||||
import { marketMarginDataProvider } from '@vegaprotocol/accounts';
|
||||
import { useDataProvider } from '@vegaprotocol/data-provider';
|
||||
import * as AccordionPrimitive from '@radix-ui/react-accordion';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
|
||||
import {
|
||||
MARGIN_DIFF_TOOLTIP_TEXT,
|
||||
@@ -37,14 +38,16 @@ export interface DealTicketFeeDetailsProps {
|
||||
assetSymbol: string;
|
||||
order: OrderSubmissionBody['orderSubmission'];
|
||||
market: Market;
|
||||
isMarketInAuction?: boolean;
|
||||
}
|
||||
|
||||
export const DealTicketFeeDetails = ({
|
||||
assetSymbol,
|
||||
order,
|
||||
market,
|
||||
isMarketInAuction,
|
||||
}: DealTicketFeeDetailsProps) => {
|
||||
const feeEstimate = useEstimateFees(order);
|
||||
const feeEstimate = useEstimateFees(order, isMarketInAuction);
|
||||
const asset = getAsset(market);
|
||||
const { decimals: assetDecimals, quantum } = asset;
|
||||
|
||||
@@ -63,7 +66,7 @@ export const DealTicketFeeDetails = ({
|
||||
<>
|
||||
<span>
|
||||
{t(
|
||||
`An estimate of the most you would be expected to pay in fees, in the market's settlement asset ${assetSymbol}.`
|
||||
`An estimate of the most you would be expected to pay in fees, in the market's settlement asset ${assetSymbol}. Fees estimated are "taker" fees and will only be payable if the order trades aggressively. Rebate equal to the maker portion will be paid to the trader if the order trades passively.`
|
||||
)}
|
||||
</span>
|
||||
<FeesBreakdown
|
||||
@@ -86,6 +89,7 @@ export interface DealTicketMarginDetailsProps {
|
||||
onMarketClick?: (marketId: string, metaKey?: boolean) => void;
|
||||
assetSymbol: string;
|
||||
positionEstimate: EstimatePositionQuery['estimatePosition'];
|
||||
side: Schema.Side;
|
||||
}
|
||||
|
||||
export const DealTicketMarginDetails = ({
|
||||
@@ -95,6 +99,7 @@ export const DealTicketMarginDetails = ({
|
||||
market,
|
||||
onMarketClick,
|
||||
positionEstimate,
|
||||
side,
|
||||
}: DealTicketMarginDetailsProps) => {
|
||||
const [breakdownDialog, setBreakdownDialog] = useState(false);
|
||||
const { pubKey: partyId } = useVegaWallet();
|
||||
@@ -163,10 +168,7 @@ export const DealTicketMarginDetails = ({
|
||||
: '0',
|
||||
assetDecimals
|
||||
)}
|
||||
formattedValue={formatRange(
|
||||
deductionFromCollateralBestCase > 0
|
||||
? deductionFromCollateralBestCase.toString()
|
||||
: '0',
|
||||
formattedValue={formatValue(
|
||||
deductionFromCollateralWorstCase > 0
|
||||
? deductionFromCollateralWorstCase.toString()
|
||||
: '0',
|
||||
@@ -185,8 +187,7 @@ export const DealTicketMarginDetails = ({
|
||||
marginEstimate?.worstCase.initialLevel,
|
||||
assetDecimals
|
||||
)}
|
||||
formattedValue={formatRange(
|
||||
marginEstimate?.bestCase.initialLevel,
|
||||
formattedValue={formatValue(
|
||||
marginEstimate?.worstCase.initialLevel,
|
||||
assetDecimals,
|
||||
quantum
|
||||
@@ -198,6 +199,7 @@ export const DealTicketMarginDetails = ({
|
||||
}
|
||||
|
||||
let liquidationPriceEstimate = emptyValue;
|
||||
let liquidationPriceEstimateRange = emptyValue;
|
||||
|
||||
if (liquidationEstimate) {
|
||||
const liquidationEstimateBestCaseIncludingBuyOrders = BigInt(
|
||||
@@ -207,8 +209,7 @@ export const DealTicketMarginDetails = ({
|
||||
liquidationEstimate.bestCase.including_sell_orders.replace(/\..*/, '')
|
||||
);
|
||||
const liquidationEstimateBestCase =
|
||||
liquidationEstimateBestCaseIncludingBuyOrders >
|
||||
liquidationEstimateBestCaseIncludingSellOrders
|
||||
side === Schema.Side.SIDE_BUY
|
||||
? liquidationEstimateBestCaseIncludingBuyOrders
|
||||
: liquidationEstimateBestCaseIncludingSellOrders;
|
||||
|
||||
@@ -219,14 +220,19 @@ export const DealTicketMarginDetails = ({
|
||||
liquidationEstimate.worstCase.including_sell_orders.replace(/\..*/, '')
|
||||
);
|
||||
const liquidationEstimateWorstCase =
|
||||
liquidationEstimateWorstCaseIncludingBuyOrders >
|
||||
liquidationEstimateWorstCaseIncludingSellOrders
|
||||
side === Schema.Side.SIDE_BUY
|
||||
? liquidationEstimateWorstCaseIncludingBuyOrders
|
||||
: liquidationEstimateWorstCaseIncludingSellOrders;
|
||||
|
||||
// The estimate order query API gives us the liquidation price in formatted by asset decimals.
|
||||
// We need to calculate it with asset decimals, but display it with market decimals precision until the API changes.
|
||||
liquidationPriceEstimate = formatRange(
|
||||
liquidationPriceEstimate = formatValue(
|
||||
liquidationEstimateWorstCase.toString(),
|
||||
assetDecimals,
|
||||
undefined,
|
||||
market.decimalPlaces
|
||||
);
|
||||
liquidationPriceEstimateRange = formatRange(
|
||||
(liquidationEstimateBestCase < liquidationEstimateWorstCase
|
||||
? liquidationEstimateBestCase
|
||||
: liquidationEstimateWorstCase
|
||||
@@ -249,7 +255,7 @@ export const DealTicketMarginDetails = ({
|
||||
const quoteName = getQuoteName(market);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<div className="flex flex-col w-full gap-2">
|
||||
<Accordion>
|
||||
<AccordionPanel
|
||||
itemId="margin"
|
||||
@@ -265,7 +271,7 @@ export const DealTicketMarginDetails = ({
|
||||
<div
|
||||
data-testid={`deal-ticket-fee-margin-required`}
|
||||
key={'value-dropdown'}
|
||||
className="flex items-center gap-2 justify-between w-full"
|
||||
className="flex items-center justify-between w-full gap-2"
|
||||
>
|
||||
<div className="flex items-center gap-1">
|
||||
<Tooltip description={MARGIN_DIFF_TOOLTIP_TEXT(assetSymbol)}>
|
||||
@@ -282,11 +288,9 @@ export const DealTicketMarginDetails = ({
|
||||
assetDecimals
|
||||
) ?? '-'
|
||||
}
|
||||
noUnderline
|
||||
>
|
||||
<div className="font-mono text-right">
|
||||
{formatRange(
|
||||
marginRequiredBestCase,
|
||||
{formatValue(
|
||||
marginRequiredWorstCase,
|
||||
assetDecimals,
|
||||
quantum
|
||||
@@ -298,7 +302,7 @@ export const DealTicketMarginDetails = ({
|
||||
</AccordionPrimitive.Trigger>
|
||||
}
|
||||
>
|
||||
<div className="flex flex-col gap-2 w-full">
|
||||
<div className="flex flex-col w-full gap-2">
|
||||
<KeyValue
|
||||
label={t('Total margin available')}
|
||||
indent
|
||||
@@ -344,7 +348,7 @@ export const DealTicketMarginDetails = ({
|
||||
{projectedMargin}
|
||||
<KeyValue
|
||||
label={t('Liquidation')}
|
||||
value={liquidationPriceEstimate}
|
||||
value={liquidationPriceEstimateRange}
|
||||
formattedValue={liquidationPriceEstimate}
|
||||
symbol={quoteName}
|
||||
labelDescription={LIQUIDATION_PRICE_ESTIMATE_TOOLTIP_TEXT}
|
||||
|
||||
@@ -23,6 +23,7 @@ import { OrdersDocument } from '@vegaprotocol/orders';
|
||||
import { formatForInput } from '@vegaprotocol/utils';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
import type { Market } from '@vegaprotocol/markets';
|
||||
import type { MarketData } from '@vegaprotocol/markets';
|
||||
|
||||
jest.mock('zustand');
|
||||
jest.mock('./deal-ticket-fee-details', () => ({
|
||||
@@ -40,18 +41,25 @@ const submit = jest.fn();
|
||||
|
||||
function generateJsx(
|
||||
mocks: MockedResponse[] = [],
|
||||
marketOverrides: PartialDeep<Market> = {}
|
||||
marketOverrides: PartialDeep<Market> = {},
|
||||
marketDataOverrides: Partial<MarketData> = {}
|
||||
) {
|
||||
const joinedMarket: Market = {
|
||||
...market,
|
||||
...marketOverrides,
|
||||
} as Market;
|
||||
|
||||
const joinedMarketData: MarketData = {
|
||||
...marketData,
|
||||
...marketDataOverrides,
|
||||
} as MarketData;
|
||||
|
||||
return (
|
||||
<MockedProvider mocks={[...mocks]}>
|
||||
<VegaWalletContext.Provider value={{ pubKey, isReadOnly: false } as any}>
|
||||
<DealTicket
|
||||
market={joinedMarket}
|
||||
marketData={marketData}
|
||||
marketData={joinedMarketData}
|
||||
marketPrice={marketPrice}
|
||||
submit={submit}
|
||||
onDeposit={jest.fn()}
|
||||
@@ -462,6 +470,10 @@ describe('DealTicket', () => {
|
||||
});
|
||||
|
||||
it('can edit deal ticket', async () => {
|
||||
// 7002-SORD-004
|
||||
// 7002-SORD-005
|
||||
// 7002-SORD-006
|
||||
// 7002-SORD-007
|
||||
render(generateJsx());
|
||||
|
||||
// BUY is selected by default
|
||||
@@ -483,11 +495,31 @@ describe('DealTicket', () => {
|
||||
|
||||
// Switch to limit order
|
||||
await userEvent.click(screen.getByTestId('order-type-Limit'));
|
||||
expect(screen.getByTestId('order-type-Limit').dataset.state).toEqual(
|
||||
'checked'
|
||||
);
|
||||
|
||||
// Check all TIF options shown
|
||||
expect(screen.getByTestId('order-tif').children).toHaveLength(
|
||||
Object.keys(Schema.OrderTimeInForce).length
|
||||
);
|
||||
// Switch to market order
|
||||
await userEvent.click(screen.getByTestId('order-type-Market'));
|
||||
expect(screen.getByTestId('order-type-Market').dataset.state).toEqual(
|
||||
'checked'
|
||||
);
|
||||
|
||||
// Switch to short order
|
||||
await userEvent.click(screen.getByTestId('order-side-SIDE_SELL'));
|
||||
expect(screen.getByTestId('order-side-SIDE_SELL').dataset.state).toEqual(
|
||||
'checked'
|
||||
);
|
||||
|
||||
// Switch to long order
|
||||
await userEvent.click(screen.getByTestId('order-side-SIDE_BUY'));
|
||||
expect(screen.getByTestId('order-side-SIDE_BUY').dataset.state).toEqual(
|
||||
'checked'
|
||||
);
|
||||
});
|
||||
|
||||
it('validates size field', async () => {
|
||||
@@ -654,4 +686,33 @@ describe('DealTicket', () => {
|
||||
new Date(screen.getByTestId<HTMLInputElement>(datePicker).value).getTime()
|
||||
).toEqual(now);
|
||||
});
|
||||
|
||||
describe('market states not accepting orders', () => {
|
||||
const states = [
|
||||
Schema.MarketState.STATE_REJECTED,
|
||||
Schema.MarketState.STATE_CANCELLED,
|
||||
Schema.MarketState.STATE_CLOSED,
|
||||
Schema.MarketState.STATE_SETTLED,
|
||||
Schema.MarketState.STATE_TRADING_TERMINATED,
|
||||
];
|
||||
|
||||
it.each(states)('handles state %s correctly', async (marketState) => {
|
||||
const marketOverrides = { state: marketState };
|
||||
const marketDataOverrides = { marketState: marketState };
|
||||
render(generateJsx([], marketOverrides, marketDataOverrides));
|
||||
|
||||
const text = `This market is ${marketState
|
||||
.split('_')
|
||||
.pop()
|
||||
?.toLowerCase()} and not accepting orders`;
|
||||
|
||||
await waitFor(() => {
|
||||
expect(
|
||||
screen.getByTestId('deal-ticket-error-message-summary')
|
||||
).toHaveTextContent(text);
|
||||
});
|
||||
|
||||
expect(screen.getByTestId('place-order')).toBeEnabled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -36,7 +36,12 @@ import {
|
||||
formatValue,
|
||||
} from '@vegaprotocol/utils';
|
||||
import { activeOrdersProvider } from '@vegaprotocol/orders';
|
||||
import { getAsset, getDerivedPrice, getQuoteName } from '@vegaprotocol/markets';
|
||||
import {
|
||||
getAsset,
|
||||
getDerivedPrice,
|
||||
getQuoteName,
|
||||
isMarketInAuction,
|
||||
} from '@vegaprotocol/markets';
|
||||
import {
|
||||
validateExpiration,
|
||||
validateMarketState,
|
||||
@@ -182,6 +187,7 @@ export const DealTicket = ({
|
||||
const iceberg = watch('iceberg');
|
||||
const peakSize = watch('peakSize');
|
||||
const expiresAt = watch('expiresAt');
|
||||
const postOnly = watch('postOnly');
|
||||
|
||||
useEffect(() => {
|
||||
const size = storedFormValues?.[dealTicketType]?.size;
|
||||
@@ -198,7 +204,7 @@ export const DealTicket = ({
|
||||
}, [storedFormValues, dealTicketType, rawPrice, setValue]);
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch((value, { name, type }) => {
|
||||
const subscription = watch((value) => {
|
||||
updateStoredFormValues(market.id, value);
|
||||
});
|
||||
return () => subscription.unsubscribe();
|
||||
@@ -211,6 +217,7 @@ export const DealTicket = ({
|
||||
size: rawSize,
|
||||
timeInForce,
|
||||
type,
|
||||
postOnly,
|
||||
},
|
||||
market.id,
|
||||
market.decimalPlaces,
|
||||
@@ -219,8 +226,7 @@ export const DealTicket = ({
|
||||
|
||||
const price =
|
||||
normalizedOrder &&
|
||||
marketPrice &&
|
||||
getDerivedPrice(normalizedOrder, marketPrice);
|
||||
getDerivedPrice(normalizedOrder, marketPrice ?? undefined);
|
||||
|
||||
const notionalSize = getNotionalSize(
|
||||
price,
|
||||
@@ -459,7 +465,7 @@ export const DealTicket = ({
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div className="mb-4 flex flex-col gap-2 w-full">
|
||||
<div className="flex flex-col w-full mb-4 gap-2">
|
||||
<KeyValue
|
||||
label={t('Notional')}
|
||||
value={formatValue(notionalSize, market.decimalPlaces)}
|
||||
@@ -473,6 +479,7 @@ export const DealTicket = ({
|
||||
}
|
||||
assetSymbol={assetSymbol}
|
||||
market={market}
|
||||
isMarketInAuction={isMarketInAuction(marketData.marketTradingMode)}
|
||||
/>
|
||||
</div>
|
||||
<Controller
|
||||
@@ -675,6 +682,7 @@ export const DealTicket = ({
|
||||
)}
|
||||
</Button>
|
||||
<DealTicketMarginDetails
|
||||
side={normalizedOrder.side}
|
||||
onMarketClick={onMarketClick}
|
||||
assetSymbol={asset.symbol}
|
||||
marginAccountBalance={marginAccountBalance}
|
||||
|
||||
@@ -47,7 +47,7 @@ export const KeyValue = ({
|
||||
<Tooltip description={labelDescription}>
|
||||
<div className="text-muted">{label}</div>
|
||||
</Tooltip>
|
||||
<Tooltip description={`${value ?? '-'} ${symbol || ''}`} noUnderline>
|
||||
<Tooltip description={`${value ?? '-'} ${symbol || ''}`}>
|
||||
{valueElement}
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useEstimateFees } from './use-estimate-fees';
|
||||
import { Side, OrderTimeInForce, OrderType } from '@vegaprotocol/types';
|
||||
|
||||
import type { EstimateFeesQuery } from './__generated__/EstimateOrder';
|
||||
|
||||
const data: EstimateFeesQuery = {
|
||||
estimateFees: {
|
||||
totalFeeAmount: '12',
|
||||
fees: {
|
||||
infrastructureFee: '2',
|
||||
liquidityFee: '4',
|
||||
makerFee: '6',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockUseEstimateFeesQuery = jest.fn((...args) => ({
|
||||
data,
|
||||
}));
|
||||
|
||||
jest.mock('./__generated__/EstimateOrder', () => ({
|
||||
...jest.requireActual('@vegaprotocol/data-provider'),
|
||||
useEstimateFeesQuery: jest.fn((...args) => mockUseEstimateFeesQuery(...args)),
|
||||
}));
|
||||
|
||||
jest.mock('@vegaprotocol/wallet', () => ({
|
||||
useVegaWallet: () => ({ pubKey: 'pubKey' }),
|
||||
}));
|
||||
|
||||
describe('useEstimateFees', () => {
|
||||
it('returns 0 as estimated values if order is postOnly', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useEstimateFees({
|
||||
marketId: 'marketId',
|
||||
side: Side.SIDE_BUY,
|
||||
size: '1',
|
||||
price: '1',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
postOnly: true,
|
||||
})
|
||||
);
|
||||
expect(result.current).toEqual({
|
||||
totalFeeAmount: '0',
|
||||
fees: {
|
||||
infrastructureFee: '0',
|
||||
liquidityFee: '0',
|
||||
makerFee: '0',
|
||||
},
|
||||
});
|
||||
expect(mockUseEstimateFeesQuery.mock.lastCall?.[0].skip).toBeTruthy();
|
||||
});
|
||||
|
||||
it('divide values by 2 if market is in auction', () => {
|
||||
const { result } = renderHook(() =>
|
||||
useEstimateFees(
|
||||
{
|
||||
marketId: 'marketId',
|
||||
side: Side.SIDE_BUY,
|
||||
size: '1',
|
||||
price: '1',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK,
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
},
|
||||
true
|
||||
)
|
||||
);
|
||||
expect(result.current).toEqual({
|
||||
totalFeeAmount: '6',
|
||||
fees: {
|
||||
infrastructureFee: '1',
|
||||
liquidityFee: '2',
|
||||
makerFee: '3',
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,13 +1,16 @@
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
|
||||
import type { EstimateFeesQuery } from './__generated__/EstimateOrder';
|
||||
import { useEstimateFeesQuery } from './__generated__/EstimateOrder';
|
||||
|
||||
export const useEstimateFees = (
|
||||
order?: OrderSubmissionBody['orderSubmission']
|
||||
) => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const divideByTwo = (n: string) => (BigInt(n) / BigInt(2)).toString();
|
||||
|
||||
export const useEstimateFees = (
|
||||
order?: OrderSubmissionBody['orderSubmission'],
|
||||
isMarketInAuction?: boolean
|
||||
): EstimateFeesQuery['estimateFees'] | undefined => {
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data } = useEstimateFeesQuery({
|
||||
variables: order && {
|
||||
marketId: order.marketId,
|
||||
@@ -19,7 +22,28 @@ export const useEstimateFees = (
|
||||
type: order.type,
|
||||
},
|
||||
fetchPolicy: 'no-cache',
|
||||
skip: !pubKey || !order?.size || !order?.price,
|
||||
skip: !pubKey || !order?.size || !order?.price || order.postOnly,
|
||||
});
|
||||
return data?.estimateFees;
|
||||
if (order?.postOnly) {
|
||||
return {
|
||||
totalFeeAmount: '0',
|
||||
fees: {
|
||||
infrastructureFee: '0',
|
||||
liquidityFee: '0',
|
||||
makerFee: '0',
|
||||
},
|
||||
};
|
||||
}
|
||||
return isMarketInAuction && data?.estimateFees
|
||||
? {
|
||||
totalFeeAmount: divideByTwo(data.estimateFees.totalFeeAmount),
|
||||
fees: {
|
||||
infrastructureFee: divideByTwo(
|
||||
data.estimateFees.fees.infrastructureFee
|
||||
),
|
||||
liquidityFee: divideByTwo(data.estimateFees.fees.liquidityFee),
|
||||
makerFee: divideByTwo(data.estimateFees.fees.makerFee),
|
||||
},
|
||||
}
|
||||
: data?.estimateFees;
|
||||
};
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
isNumeric,
|
||||
} from '@vegaprotocol/utils';
|
||||
import type { ColDef } from 'ag-grid-community';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import type {
|
||||
VegaICellRendererParams,
|
||||
VegaValueFormatterParams,
|
||||
|
||||
@@ -414,6 +414,9 @@ function compileFeatureFlags(): FeatureFlags {
|
||||
process.env['NX_METAMASK_SNAPS']
|
||||
) as string
|
||||
),
|
||||
REFERRALS: TRUTHY.includes(
|
||||
windowOrDefault('NX_REFERRALS', process.env['NX_REFERRALS']) as string
|
||||
),
|
||||
};
|
||||
const EXPLORER_FLAGS = {
|
||||
EXPLORER_ASSETS: TRUTHY.includes(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import trim from 'lodash/trim';
|
||||
import { useCallback } from 'react';
|
||||
import { Networks } from '../types';
|
||||
import { useEnvironment } from './use-environment';
|
||||
import { ENV, useEnvironment } from './use-environment';
|
||||
import { stripFullStops } from '@vegaprotocol/utils';
|
||||
|
||||
const VEGA_DOCS_URL =
|
||||
@@ -84,8 +84,7 @@ export const DocsLinks = VEGA_DOCS_URL
|
||||
: undefined;
|
||||
|
||||
export const useLinks = (dapp: DApp, network?: Net) => {
|
||||
const { VEGA_ENV, VEGA_EXPLORER_URL, VEGA_TOKEN_URL, VEGA_CONSOLE_URL } =
|
||||
useEnvironment();
|
||||
const { VEGA_ENV, VEGA_EXPLORER_URL, VEGA_TOKEN_URL, VEGA_CONSOLE_URL } = ENV;
|
||||
const fallback = {
|
||||
[DApp.Explorer]: VEGA_EXPLORER_URL,
|
||||
[DApp.Governance]: VEGA_TOKEN_URL,
|
||||
@@ -175,4 +174,5 @@ export const ExternalLinks = {
|
||||
export const TokenStaticLinks = {
|
||||
PROPOSAL_PAGE: ':tokenUrl/proposals/:proposalId',
|
||||
UPDATE_PROPOSAL_PAGE: ':tokenUrl/proposals/propose/update-market',
|
||||
ASSOCIATE: 'token/associate',
|
||||
};
|
||||
|
||||
@@ -23,6 +23,7 @@ export type CosmicElevatorFlags = Pick<
|
||||
| 'SUCCESSOR_MARKETS'
|
||||
| 'PRODUCT_PERPETUALS'
|
||||
| 'METAMASK_SNAPS'
|
||||
| 'REFERRALS'
|
||||
>;
|
||||
export type Configuration = z.infer<typeof tomlConfigSchema>;
|
||||
export const CUSTOM_NODE_KEY = 'custom' as const;
|
||||
|
||||
@@ -78,6 +78,7 @@ const COSMIC_ELEVATOR_FLAGS = {
|
||||
ICEBERG_ORDERS: z.optional(z.boolean()),
|
||||
PRODUCT_PERPETUALS: z.optional(z.boolean()),
|
||||
METAMASK_SNAPS: z.optional(z.boolean()),
|
||||
REFERRALS: z.optional(z.boolean()),
|
||||
};
|
||||
|
||||
const EXPLORER_FLAGS = {
|
||||
|
||||
@@ -15,7 +15,7 @@ import {
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import * as Schema from '@vegaprotocol/types';
|
||||
import {
|
||||
AgGridLazy as AgGrid,
|
||||
AgGrid,
|
||||
positiveClassNames,
|
||||
negativeClassNames,
|
||||
MarketNameCell,
|
||||
@@ -299,7 +299,7 @@ const FeesBreakdownTooltip = ({
|
||||
return (
|
||||
<div
|
||||
data-testid="fee-breakdown-tooltip"
|
||||
className="max-w-sm bg-vega-light-100 dark:bg-vega-dark-100 border border-vega-light-200 dark:border-vega-dark-200 px-4 py-2 z-20 rounded text-sm break-word text-black dark:text-white"
|
||||
className="z-20 max-w-sm px-4 py-2 text-sm text-black border rounded bg-vega-light-100 dark:bg-vega-dark-100 border-vega-light-200 dark:border-vega-dark-200 break-word dark:text-white"
|
||||
>
|
||||
{role === MAKER && (
|
||||
<>
|
||||
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
} from '@vegaprotocol/utils';
|
||||
import { t } from '@vegaprotocol/i18n';
|
||||
import type { TypedDataAgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGridLazy as AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { AgGrid } from '@vegaprotocol/datagrid';
|
||||
import { TooltipCellComponent } from '@vegaprotocol/ui-toolkit';
|
||||
import type {
|
||||
ColDef,
|
||||
|
||||
@@ -175,7 +175,7 @@ export const Orderbook = ({
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="h-full text-xs grid grid-rows-[1fr_min-content]">
|
||||
<div className="h-full text-xs grid grid-rows-[1fr_min-content] overflow-hidden">
|
||||
<div>
|
||||
<ReactVirtualizedAutoSizer>
|
||||
{({ width, height }) => {
|
||||
|
||||
@@ -60,6 +60,7 @@ export const FeesBreakdown = ({
|
||||
.plus(fees.infrastructureFee)
|
||||
.plus(fees.liquidityFee)
|
||||
.toString();
|
||||
if (totalFees === '0') return null;
|
||||
const formatValue = (value: string | number | null | undefined): string => {
|
||||
return value && !isNaN(Number(value))
|
||||
? addDecimalsFormatNumber(value, decimals)
|
||||
|
||||
@@ -157,6 +157,12 @@ query MarketInfo($marketId: ID!) {
|
||||
scalingFactor
|
||||
}
|
||||
}
|
||||
liquiditySLAParameters {
|
||||
priceRange
|
||||
commitmentMinTimeFraction
|
||||
performanceHysteresisEpochs
|
||||
slaCompetitionFactor
|
||||
}
|
||||
tradableInstrument {
|
||||
instrument {
|
||||
id
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
Link as UILink,
|
||||
Splash,
|
||||
AccordionItem,
|
||||
Tooltip,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import { generatePath, Link } from 'react-router-dom';
|
||||
|
||||
@@ -29,6 +30,8 @@ import {
|
||||
KeyDetailsInfoPanel,
|
||||
LiquidityInfoPanel,
|
||||
LiquidityMonitoringParametersInfoPanel,
|
||||
LiquidityPriceRangeInfoPanel,
|
||||
LiquiditySLAParametersInfoPanel,
|
||||
MarketPriceInfoPanel,
|
||||
MarketVolumeInfoPanel,
|
||||
MetadataInfoPanel,
|
||||
@@ -265,6 +268,26 @@ export const MarketInfoAccordion = ({
|
||||
title={t('Liquidity monitoring parameters')}
|
||||
content={<LiquidityMonitoringParametersInfoPanel market={market} />}
|
||||
/>
|
||||
<AccordionItem
|
||||
itemId="liquidity-price-range"
|
||||
title={t('Liquidity price range')}
|
||||
content={<LiquidityPriceRangeInfoPanel market={market} />}
|
||||
/>
|
||||
<AccordionItem
|
||||
itemId="liquidity-sla-parameters"
|
||||
title={
|
||||
<span>
|
||||
<Tooltip
|
||||
description={t(
|
||||
'SLA protocol = a part of the Vega protocol that creates similar incentives within the decentralised system to those achieved by a Service Level Agreement between parties in traditional finance. The SLA protocol involves no discussion, agreement, or contracts between parties but instead relies upon rules and an economic mechanism implemented in code running on the network'
|
||||
)}
|
||||
>
|
||||
<span>{t('Liquidity SLA protocol')}</span>
|
||||
</Tooltip>
|
||||
</span>
|
||||
}
|
||||
content={<LiquiditySLAParametersInfoPanel market={market} />}
|
||||
/>
|
||||
<AccordionItem
|
||||
itemId="liquidity"
|
||||
title={t('Liquidity')}
|
||||
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
VegaIconNames,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import {
|
||||
addDecimalsFormatNumber,
|
||||
formatNumber,
|
||||
formatNumberPercentage,
|
||||
getDateTimeFormat,
|
||||
@@ -58,6 +59,10 @@ import { useSuccessorMarketProposalDetailsQuery } from '@vegaprotocol/proposals'
|
||||
import { getQuoteName, getAsset } from '../../market-utils';
|
||||
import classNames from 'classnames';
|
||||
import compact from 'lodash/compact';
|
||||
import {
|
||||
NetworkParams,
|
||||
useNetworkParams,
|
||||
} from '@vegaprotocol/network-parameters';
|
||||
import type { DataSourceFragment } from './__generated__/MarketInfo';
|
||||
import { formatDuration } from 'date-fns';
|
||||
|
||||
@@ -654,6 +659,193 @@ export const LiquidityMonitoringParametersInfoPanel = ({
|
||||
return <MarketInfoTable data={marketData} parentData={parentMarketData} />;
|
||||
};
|
||||
|
||||
export const LiquidityPriceRangeInfoPanel = ({
|
||||
market,
|
||||
parentMarket,
|
||||
}: MarketInfoProps) => {
|
||||
const marketLpPriceRange = market.liquiditySLAParameters?.priceRange;
|
||||
const parentMarketLpPriceRange =
|
||||
parentMarket?.liquiditySLAParameters?.priceRange;
|
||||
const quoteUnit =
|
||||
('quoteName' in market.tradableInstrument.instrument.product &&
|
||||
market?.tradableInstrument.instrument.product?.quoteName) ||
|
||||
'';
|
||||
const parentQuoteUnit =
|
||||
(parentMarket &&
|
||||
'quoteName' in parentMarket.tradableInstrument.instrument.product &&
|
||||
parentMarket?.tradableInstrument.instrument.product?.quoteName) ||
|
||||
'';
|
||||
|
||||
const liquidityPriceRange =
|
||||
marketLpPriceRange &&
|
||||
formatNumberPercentage(new BigNumber(marketLpPriceRange).times(100));
|
||||
const parentLiquidityPriceRange =
|
||||
parentMarket && parentMarketLpPriceRange
|
||||
? formatNumberPercentage(
|
||||
new BigNumber(parentMarketLpPriceRange).times(100)
|
||||
)
|
||||
: null;
|
||||
|
||||
const { data } = useDataProvider({
|
||||
dataProvider: marketDataProvider,
|
||||
variables: { marketId: market.id },
|
||||
});
|
||||
|
||||
const { data: parentMarketData } = useDataProvider({
|
||||
dataProvider: marketDataProvider,
|
||||
variables: { marketId: parentMarket?.id || '' },
|
||||
skip: !parentMarket,
|
||||
});
|
||||
|
||||
let parentData;
|
||||
|
||||
if (parentMarket && parentMarketData && quoteUnit === parentQuoteUnit) {
|
||||
parentData = {
|
||||
liquidityPriceRange: `${parentLiquidityPriceRange} of mid price`,
|
||||
lowestPrice:
|
||||
parentMarketLpPriceRange &&
|
||||
parentMarketData?.midPrice &&
|
||||
`${addDecimalsFormatNumber(
|
||||
new BigNumber(1)
|
||||
.minus(parentMarketLpPriceRange)
|
||||
.times(parentMarketData.midPrice)
|
||||
.toString(),
|
||||
parentMarket.decimalPlaces
|
||||
)} ${quoteUnit}`,
|
||||
highestPrice:
|
||||
parentMarketLpPriceRange &&
|
||||
parentMarketData?.midPrice &&
|
||||
`${addDecimalsFormatNumber(
|
||||
new BigNumber(1)
|
||||
.plus(parentMarketLpPriceRange)
|
||||
.times(parentMarketData.midPrice)
|
||||
.toString(),
|
||||
parentMarket.decimalPlaces
|
||||
)} ${quoteUnit}`,
|
||||
};
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<p className="text-xs mb-2 border-l-2 pl-2">
|
||||
{`For liquidity orders to count towards a commitment, they must be
|
||||
within the liquidity monitoring bounds.`}
|
||||
</p>
|
||||
<MarketInfoTable
|
||||
data={{
|
||||
liquidityPriceRange: `${liquidityPriceRange} of mid price`,
|
||||
lowestPrice:
|
||||
marketLpPriceRange &&
|
||||
data?.midPrice &&
|
||||
`${addDecimalsFormatNumber(
|
||||
new BigNumber(1)
|
||||
.minus(marketLpPriceRange)
|
||||
.times(data.midPrice)
|
||||
.toString(),
|
||||
market.decimalPlaces
|
||||
)} ${quoteUnit}`,
|
||||
highestPrice:
|
||||
marketLpPriceRange &&
|
||||
data?.midPrice &&
|
||||
`${addDecimalsFormatNumber(
|
||||
new BigNumber(1)
|
||||
.plus(marketLpPriceRange)
|
||||
.times(data.midPrice)
|
||||
.toString(),
|
||||
market.decimalPlaces
|
||||
)} ${quoteUnit}`,
|
||||
}}
|
||||
parentData={parentData}
|
||||
/>
|
||||
<p className="text-xs mb-2 border-l-2 pl-2 mt-2">
|
||||
{`The liquidity price range is a ${liquidityPriceRange} difference from the mid
|
||||
price.`}
|
||||
</p>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
const fromNanoSecondsToSeconds = (nanoseconds: number | string) =>
|
||||
t('%ss', [new BigNumber(nanoseconds).dividedBy(1e9).toString()]);
|
||||
|
||||
export const LiquiditySLAParametersInfoPanel = ({
|
||||
market,
|
||||
parentMarket,
|
||||
}: MarketInfoProps) => {
|
||||
const marketData = {
|
||||
performanceHysteresisEpochs:
|
||||
market.liquiditySLAParameters?.performanceHysteresisEpochs,
|
||||
SLACompetitionFactor:
|
||||
market.liquiditySLAParameters?.slaCompetitionFactor &&
|
||||
formatNumberPercentage(
|
||||
new BigNumber(
|
||||
market.liquiditySLAParameters?.slaCompetitionFactor
|
||||
).times(100)
|
||||
),
|
||||
commitmentMinimumTimeFraction:
|
||||
market.liquiditySLAParameters?.commitmentMinTimeFraction &&
|
||||
formatNumberPercentage(
|
||||
new BigNumber(
|
||||
market.liquiditySLAParameters?.commitmentMinTimeFraction
|
||||
).times(100)
|
||||
),
|
||||
};
|
||||
|
||||
const parentMarketData = parentMarket
|
||||
? {
|
||||
performanceHysteresisEpochs:
|
||||
parentMarket.liquiditySLAParameters?.performanceHysteresisEpochs,
|
||||
slaCompetitionFactor:
|
||||
parentMarket.liquiditySLAParameters?.slaCompetitionFactor,
|
||||
commitmentMinimumTimeFraction:
|
||||
parentMarket.liquiditySLAParameters?.commitmentMinTimeFraction,
|
||||
}
|
||||
: undefined;
|
||||
|
||||
const { params: networkParams } = useNetworkParams([
|
||||
NetworkParams.market_liquidity_bondPenaltyParameter,
|
||||
NetworkParams.market_liquidity_nonPerformanceBondPenaltySlope,
|
||||
NetworkParams.market_liquidity_sla_nonPerformanceBondPenaltyMax,
|
||||
NetworkParams.market_liquidity_maximumLiquidityFeeFactorLevel,
|
||||
NetworkParams.market_liquidity_stakeToCcyVolume,
|
||||
NetworkParams.validators_epoch_length,
|
||||
NetworkParams.market_liquidity_earlyExitPenalty,
|
||||
NetworkParams.market_liquidity_probabilityOfTrading_tau_scaling,
|
||||
NetworkParams.market_liquidity_minimum_probabilityOfTrading_lpOrders,
|
||||
NetworkParams.market_liquidity_feeCalculationTimeStep,
|
||||
]);
|
||||
|
||||
const marketNetworkParamData = {
|
||||
epochLength: networkParams['validators_epoch_length'],
|
||||
bondPenaltyParameter:
|
||||
networkParams['market_liquidity_bondPenaltyParameter'],
|
||||
nonPerformanceBondPenaltySlope:
|
||||
networkParams['market_liquidity_nonPerformanceBondPenaltySlope'],
|
||||
nonPerformanceBondPenaltyMax:
|
||||
networkParams['market_liquidity_sla_nonPerformanceBondPenaltyMax'],
|
||||
maximumLiquidityFeeFactorLevel:
|
||||
networkParams['market_liquidity_maximumLiquidityFeeFactorLevel'],
|
||||
stakeToCCYVolume: networkParams['market_liquidity_stakeToCcyVolume'],
|
||||
earlyExitPenalty: networkParams['market_liquidity_earlyExitPenalty'],
|
||||
probabilityOfTradingTauScaling:
|
||||
networkParams['market_liquidity_probabilityOfTrading_tau_scaling'],
|
||||
minimumProbabilityOfTradingLPOrders:
|
||||
networkParams['market_liquidity_minimum_probabilityOfTrading_lpOrders'],
|
||||
feeCalculationTimeStep:
|
||||
networkParams['market_liquidity_feeCalculationTimeStep'] &&
|
||||
fromNanoSecondsToSeconds(
|
||||
networkParams['market_liquidity_feeCalculationTimeStep']
|
||||
),
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<MarketInfoTable data={marketData} parentData={parentMarketData} />
|
||||
<MarketInfoTable data={marketNetworkParamData} unformatted={true} />
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export const LiquidityInfoPanel = ({ market, children }: MarketInfoProps) => {
|
||||
const asset = getAsset(market);
|
||||
const { data } = useDataProvider({
|
||||
|
||||