{
setChangeVote(true);
}}
diff --git a/apps/token/src/routes/home/token-details/token-details.tsx b/apps/token/src/routes/home/token-details/token-details.tsx
index 1758680b5..bbf1c9171 100644
--- a/apps/token/src/routes/home/token-details/token-details.tsx
+++ b/apps/token/src/routes/home/token-details/token-details.tsx
@@ -1,7 +1,7 @@
import { useTranslation } from 'react-i18next';
import { Callout, Link, Intent, Splash } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { KeyValueTable, KeyValueTableRow } from '@vegaprotocol/ui-toolkit';
import { useTranches } from '../../../hooks/use-tranches';
import type { BigNumber } from '../../../lib/bignumber';
diff --git a/apps/token/src/routes/staking/associate/associate-transaction.tsx b/apps/token/src/routes/staking/associate/associate-transaction.tsx
index 7ba242296..aa0270546 100644
--- a/apps/token/src/routes/staking/associate/associate-transaction.tsx
+++ b/apps/token/src/routes/staking/associate/associate-transaction.tsx
@@ -1,5 +1,5 @@
import { Button, Callout, Link, Loader } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link as RouteLink } from 'react-router-dom';
diff --git a/apps/token/src/routes/staking/staking.tsx b/apps/token/src/routes/staking/staking.tsx
index be36cbfa7..203566fed 100644
--- a/apps/token/src/routes/staking/staking.tsx
+++ b/apps/token/src/routes/staking/staking.tsx
@@ -5,7 +5,7 @@ import { Link as RouteLink } from 'react-router-dom';
import { BulletHeader } from '../../components/bullet-header';
import { Link } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { Links } from '../../config';
import {
AppStateActionType,
diff --git a/apps/token/src/routes/staking/validator-table.tsx b/apps/token/src/routes/staking/validator-table.tsx
index 041d0ab66..2ebe3abda 100644
--- a/apps/token/src/routes/staking/validator-table.tsx
+++ b/apps/token/src/routes/staking/validator-table.tsx
@@ -2,7 +2,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { KeyValueTable, KeyValueTableRow } from '@vegaprotocol/ui-toolkit';
import { BigNumber } from '../../lib/bignumber';
import { formatNumber } from '../../lib/format-number';
diff --git a/apps/token/src/routes/tranches/tranche.tsx b/apps/token/src/routes/tranches/tranche.tsx
index bff32105a..689118135 100644
--- a/apps/token/src/routes/tranches/tranche.tsx
+++ b/apps/token/src/routes/tranches/tranche.tsx
@@ -7,7 +7,7 @@ import { useParams } from 'react-router';
import { Navigate } from 'react-router-dom';
import { useOutletContext } from 'react-router-dom';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { BigNumber } from '../../lib/bignumber';
import { formatNumber } from '../../lib/format-number';
import { TrancheItem } from '../redemption/tranche-item';
diff --git a/apps/token/src/routes/withdrawals/index.tsx b/apps/token/src/routes/withdrawals/index.tsx
index b00aae9ba..3c3312f26 100644
--- a/apps/token/src/routes/withdrawals/index.tsx
+++ b/apps/token/src/routes/withdrawals/index.tsx
@@ -5,7 +5,7 @@ import React from 'react';
import { useTranslation } from 'react-i18next';
import { Link } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { Heading } from '../../components/heading';
import { KeyValueTable, KeyValueTableRow } from '@vegaprotocol/ui-toolkit';
import { SplashLoader } from '../../components/splash-loader';
diff --git a/apps/trading-e2e/cypress.json b/apps/trading-e2e/cypress.json
index b0c4893c6..fc00e9973 100644
--- a/apps/trading-e2e/cypress.json
+++ b/apps/trading-e2e/cypress.json
@@ -17,7 +17,6 @@
"env": {
"TRADING_TEST_VEGA_WALLET_NAME": "UI_Trading_Test",
"ETHEREUM_PROVIDER_URL": "https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8",
- "ETHEREUM_CHAIN_ID": 3,
"VEGA_PUBLIC_KEY": "47836c253520d2661bf5bed6339c0de08fd02cf5d4db0efee3b4373f20c7d278",
"VEGA_PUBLIC_KEY2": "1a18cdcaaa4f44a57b35a4e9b77e0701c17a476f2b407620f8c17371740cf2e4",
"TRUNCATED_VEGA_PUBLIC_KEY": "47836c…c7d278",
diff --git a/apps/trading-e2e/src/integration/trading-orders.ts b/apps/trading-e2e/src/integration/trading-orders.ts
index 22bed6fcc..88ffd9b5e 100644
--- a/apps/trading-e2e/src/integration/trading-orders.ts
+++ b/apps/trading-e2e/src/integration/trading-orders.ts
@@ -19,12 +19,14 @@ describe('orders', () => {
const orderTimeInForce = 'timeInForce';
const orderCreatedAt = 'createdAt';
- it('renders orders', () => {
+ beforeEach(() => {
cy.getByTestId('Orders').click();
cy.getByTestId('tab-orders').contains('Please connect Vega wallet');
connectVegaWallet();
+ });
+ it('renders orders', () => {
cy.getByTestId('tab-orders').should('be.visible');
cy.getByTestId('tab-orders')
@@ -68,4 +70,17 @@ describe('orders', () => {
cy.wrap($dateTime).invoke('text').should('not.be.empty');
});
});
+
+ it('orders are sorted by most recent order', () => {
+ const expectedOrderList = ['TSLA.QM21', 'BTCUSD.MF21', 'AAVEDAI.MF21'];
+
+ cy.getByTestId('tab-orders')
+ .get(`[col-id='${orderSymbol}']`)
+ .should('have.length.at.least', 3)
+ .each(($symbol, index) => {
+ if (index != 0) {
+ cy.wrap($symbol).should('have.text', expectedOrderList[index - 1]);
+ }
+ });
+ });
});
diff --git a/apps/trading-e2e/src/support/mocks/generate-deal-ticket-query.ts b/apps/trading-e2e/src/support/mocks/generate-deal-ticket-query.ts
index 14626634b..1f168a45d 100644
--- a/apps/trading-e2e/src/support/mocks/generate-deal-ticket-query.ts
+++ b/apps/trading-e2e/src/support/mocks/generate-deal-ticket-query.ts
@@ -15,50 +15,6 @@ export const generateDealTicketQuery = (
positionDecimalPlaces: 0,
state: MarketState.Active,
tradingMode: MarketTradingMode.Continuous,
- fees: {
- __typename: 'Fees',
- factors: {
- __typename: 'FeeFactors',
- makerFee: '0.0002',
- infrastructureFee: '0.0005',
- liquidityFee: '0.01',
- },
- },
- priceMonitoringSettings: {
- __typename: 'PriceMonitoringSettings',
- parameters: {
- __typename: 'PriceMonitoringParameters',
- triggers: [
- {
- __typename: 'PriceMonitoringTrigger',
- horizonSecs: 43200,
- probability: 0.9999999,
- auctionExtensionSecs: 600,
- },
- ],
- },
- updateFrequencySecs: 1,
- },
- riskFactors: {
- __typename: 'RiskFactor',
- market:
- '54b78c1b877e106842ae156332ccec740ad98d6bad43143ac6a029501dd7c6e0',
- short: '0.008571790367285281',
- long: '0.008508132993273576',
- },
- data: {
- __typename: 'MarketData',
- market: {
- __typename: 'Market',
- id: '54b78c1b877e106842ae156332ccec740ad98d6bad43143ac6a029501dd7c6e0',
- },
- markPrice: '5749',
- indicativeVolume: '0',
- bestBidVolume: '5',
- bestOfferVolume: '1',
- bestStaticBidVolume: '5',
- bestStaticOfferVolume: '1',
- },
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
@@ -74,17 +30,6 @@ export const generateDealTicketQuery = (
},
},
},
- riskModel: {
- __typename: 'LogNormalRiskModel',
- tau: 0.0001140771161,
- riskAversionParameter: 0.01,
- params: {
- __typename: 'LogNormalModelParams',
- r: 0.016,
- sigma: 0.3,
- mu: 0,
- },
- },
},
depth: {
__typename: 'MarketDepth',
diff --git a/apps/trading-e2e/src/support/mocks/generate-market-info-query.ts b/apps/trading-e2e/src/support/mocks/generate-market-info-query.ts
new file mode 100644
index 000000000..dd652d2cb
--- /dev/null
+++ b/apps/trading-e2e/src/support/mocks/generate-market-info-query.ts
@@ -0,0 +1,100 @@
+import type { MarketInfoQuery } from '@vegaprotocol/deal-ticket';
+import { MarketState, MarketTradingMode } from '@vegaprotocol/types';
+import merge from 'lodash/merge';
+import type { PartialDeep } from 'type-fest';
+
+export const generateMarketInfoQuery = (
+ override?: PartialDeep
+): MarketInfoQuery => {
+ const defaultResult: MarketInfoQuery = {
+ market: {
+ __typename: 'Market',
+ id: 'market-0',
+ name: 'ETHBTC Quarterly (30 Jun 2022)',
+ decimalPlaces: 2,
+ positionDecimalPlaces: 0,
+ state: MarketState.Active,
+ tradingMode: MarketTradingMode.Continuous,
+ fees: {
+ __typename: 'Fees',
+ factors: {
+ __typename: 'FeeFactors',
+ makerFee: '0.0002',
+ infrastructureFee: '0.0005',
+ liquidityFee: '0.01',
+ },
+ },
+ priceMonitoringSettings: {
+ __typename: 'PriceMonitoringSettings',
+ parameters: {
+ __typename: 'PriceMonitoringParameters',
+ triggers: [
+ {
+ __typename: 'PriceMonitoringTrigger',
+ horizonSecs: 43200,
+ probability: 0.9999999,
+ auctionExtensionSecs: 600,
+ },
+ ],
+ },
+ updateFrequencySecs: 1,
+ },
+ riskFactors: {
+ __typename: 'RiskFactor',
+ market:
+ '54b78c1b877e106842ae156332ccec740ad98d6bad43143ac6a029501dd7c6e0',
+ short: '0.008571790367285281',
+ long: '0.008508132993273576',
+ },
+ data: {
+ __typename: 'MarketData',
+ market: {
+ __typename: 'Market',
+ id: '54b78c1b877e106842ae156332ccec740ad98d6bad43143ac6a029501dd7c6e0',
+ },
+ markPrice: '5749',
+ indicativeVolume: '0',
+ bestBidVolume: '5',
+ bestOfferVolume: '1',
+ bestStaticBidVolume: '5',
+ bestStaticOfferVolume: '1',
+ },
+ tradableInstrument: {
+ __typename: 'TradableInstrument',
+ instrument: {
+ __typename: 'Instrument',
+ product: {
+ __typename: 'Future',
+ quoteName: 'BTC',
+ settlementAsset: {
+ __typename: 'Asset',
+ id: '5cfa87844724df6069b94e4c8a6f03af21907d7bc251593d08e4251043ee9f7c',
+ symbol: 'tBTC',
+ name: 'tBTC TEST',
+ },
+ },
+ },
+ riskModel: {
+ __typename: 'LogNormalRiskModel',
+ tau: 0.0001140771161,
+ riskAversionParameter: 0.01,
+ params: {
+ __typename: 'LogNormalModelParams',
+ r: 0.016,
+ sigma: 0.3,
+ mu: 0,
+ },
+ },
+ },
+ depth: {
+ __typename: 'MarketDepth',
+ lastTrade: {
+ __typename: 'Trade',
+ price: '100',
+ },
+ },
+ },
+ };
+
+ return merge(defaultResult, override);
+};
diff --git a/apps/trading-e2e/src/support/mocks/generate-order-book.ts b/apps/trading-e2e/src/support/mocks/generate-order-book.ts
index 2a4acbc49..1249a75b1 100644
--- a/apps/trading-e2e/src/support/mocks/generate-order-book.ts
+++ b/apps/trading-e2e/src/support/mocks/generate-order-book.ts
@@ -12,6 +12,7 @@ export const generateOrderBook = (
const marketDepth: MarketDepth_market = {
id: 'b2426f67b085ba8fb429f1b529d49372b2d096c6fb6f509f76c5863abb6d969e',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
data: {
staticMidPrice: '826337',
marketTradingMode: MarketTradingMode.Continuous,
diff --git a/apps/trading-e2e/src/support/mocks/generate-orders.ts b/apps/trading-e2e/src/support/mocks/generate-orders.ts
index 7f54fd796..3e5bc8946 100644
--- a/apps/trading-e2e/src/support/mocks/generate-orders.ts
+++ b/apps/trading-e2e/src/support/mocks/generate-orders.ts
@@ -18,6 +18,7 @@ export const generateOrders = (override?: PartialDeep): Orders => {
id: 'c9f5acd348796011c075077e4d58d9b7f1689b7c1c8e030a5e886b83aa96923d',
name: 'AAVEDAI Monthly (30 Jun 2022)',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
@@ -33,7 +34,7 @@ export const generateOrders = (override?: PartialDeep): Orders => {
remaining: '0',
price: '20000000',
timeInForce: OrderTimeInForce.GTC,
- createdAt: new Date().toISOString(),
+ createdAt: new Date(2020, 1, 1).toISOString(),
updatedAt: null,
expiresAt: null,
rejectionReason: null,
@@ -46,6 +47,7 @@ export const generateOrders = (override?: PartialDeep): Orders => {
id: '5a4b0b9e9c0629f0315ec56fcb7bd444b0c6e4da5ec7677719d502626658a376',
name: 'Tesla Quarterly (30 Jun 2022)',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
tradableInstrument: {
__typename: 'TradableInstrument',
instrument: {
@@ -59,13 +61,41 @@ export const generateOrders = (override?: PartialDeep): Orders => {
status: OrderStatus.Filled,
side: Side.Buy,
remaining: '0',
- price: '0',
+ price: '100',
timeInForce: OrderTimeInForce.GTC,
createdAt: new Date().toISOString(),
updatedAt: null,
expiresAt: null,
rejectionReason: null,
},
+ {
+ __typename: 'Order',
+ id: '4e93702990712c41f6995fcbbd94f60bb372ad12d64dfa7d96d205c49f790336',
+ market: {
+ __typename: 'Market',
+ id: 'c6f4337b31ed57a961969c3ba10297b369d01b9e75a4cbb96db4fc62886444e6',
+ name: 'BTCUSD Monthly (30 Jun 2022)',
+ decimalPlaces: 5,
+ tradableInstrument: {
+ __typename: 'TradableInstrument',
+ instrument: {
+ __typename: 'Instrument',
+ code: 'BTCUSD.MF21',
+ },
+ },
+ },
+ size: '1',
+ type: OrderType.Limit,
+ status: OrderStatus.Filled,
+ side: Side.Buy,
+ remaining: '0',
+ price: '20000',
+ timeInForce: OrderTimeInForce.GTC,
+ createdAt: new Date(2022, 5, 10).toISOString(),
+ updatedAt: null,
+ expiresAt: null,
+ rejectionReason: null,
+ },
];
const defaultResult = {
diff --git a/apps/trading-e2e/src/support/mocks/generate-positions.ts b/apps/trading-e2e/src/support/mocks/generate-positions.ts
index 3e8b98f66..e822d4c79 100644
--- a/apps/trading-e2e/src/support/mocks/generate-positions.ts
+++ b/apps/trading-e2e/src/support/mocks/generate-positions.ts
@@ -25,6 +25,7 @@ export const generatePositions = (
market: { __typename: 'Market', id: '123' },
},
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
tradableInstrument: {
instrument: {
id: '',
@@ -78,6 +79,7 @@ export const generatePositions = (
},
},
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
tradableInstrument: {
instrument: {
id: '',
diff --git a/apps/trading-e2e/src/support/mocks/generate-trades.ts b/apps/trading-e2e/src/support/mocks/generate-trades.ts
index 4510acb76..0031ec090 100644
--- a/apps/trading-e2e/src/support/mocks/generate-trades.ts
+++ b/apps/trading-e2e/src/support/mocks/generate-trades.ts
@@ -12,6 +12,7 @@ export const generateTrades = (override?: PartialDeep): Trades => {
market: {
id: '0c3c1490db767f926d24fb674b4235a9aa339614915a4ab96cbfc0e1ad83c0ff',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
__typename: 'Market',
},
__typename: 'Trade',
@@ -24,6 +25,7 @@ export const generateTrades = (override?: PartialDeep): Trades => {
market: {
id: '0c3c1490db767f926d24fb674b4235a9aa339614915a4ab96cbfc0e1ad83c0ff',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
__typename: 'Market',
},
__typename: 'Trade',
@@ -36,6 +38,7 @@ export const generateTrades = (override?: PartialDeep): Trades => {
market: {
id: '0c3c1490db767f926d24fb674b4235a9aa339614915a4ab96cbfc0e1ad83c0ff',
decimalPlaces: 5,
+ positionDecimalPlaces: 0,
__typename: 'Market',
},
__typename: 'Trade',
diff --git a/apps/trading-e2e/src/support/trading.ts b/apps/trading-e2e/src/support/trading.ts
index f60ab1699..3b3c3db57 100644
--- a/apps/trading-e2e/src/support/trading.ts
+++ b/apps/trading-e2e/src/support/trading.ts
@@ -6,6 +6,7 @@ import { generateCandles } from './mocks/generate-candles';
import { generateChart } from './mocks/generate-chart';
import { generateDealTicketQuery } from './mocks/generate-deal-ticket-query';
import { generateMarket } from './mocks/generate-market';
+import { generateMarketInfoQuery } from './mocks/generate-market-info-query';
import { generateOrders } from './mocks/generate-orders';
import { generatePositions } from './mocks/generate-positions';
import { generateTrades } from './mocks/generate-trades';
@@ -31,6 +32,11 @@ export const mockTradingPage = (
'DealTicketQuery',
generateDealTicketQuery({ market: { state } })
);
+ aliasQuery(
+ req,
+ 'MarketInfoQuery',
+ generateMarketInfoQuery({ market: { state } })
+ );
aliasQuery(req, 'Trades', generateTrades());
aliasQuery(req, 'Chart', generateChart());
aliasQuery(req, 'Candles', generateCandles());
diff --git a/apps/trading/.env b/apps/trading/.env
index 17097e2ed..82d9ff526 100644
--- a/apps/trading/.env
+++ b/apps/trading/.env
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=TESTNET
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/testnet-network.json
NX_VEGA_URL=https://lb.testnet.vega.xyz/query
-NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"}
diff --git a/apps/trading/.env.devnet b/apps/trading/.env.devnet
index c8a9a8613..6cc08adc4 100644
--- a/apps/trading/.env.devnet
+++ b/apps/trading/.env.devnet
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=DEVNET
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/devnet-network.json
NX_VEGA_URL=https://n04.d.vega.xyz/query
NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"}
-NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
diff --git a/apps/trading/.env.mainnet b/apps/trading/.env.mainnet
index 7516e6d29..71078005d 100644
--- a/apps/trading/.env.mainnet
+++ b/apps/trading/.env.mainnet
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=MAINNET
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/mainnet-network.json
NX_VEGA_URL=https://api.token.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
-NX_ETHEREUM_CHAIN_ID=1
NX_ETHEREUM_PROVIDER_URL=https://mainnet.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://etherscan.io
diff --git a/apps/trading/.env.stagnet1 b/apps/trading/.env.stagnet1
index 6887edd3d..13ac66839 100644
--- a/apps/trading/.env.stagnet1
+++ b/apps/trading/.env.stagnet1
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=STAGNET
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/stagnet1-network.json
NX_VEGA_URL=https://n03.s.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
-NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
diff --git a/apps/trading/.env.stagnet2 b/apps/trading/.env.stagnet2
index c885d8545..ae6011f3e 100644
--- a/apps/trading/.env.stagnet2
+++ b/apps/trading/.env.stagnet2
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=STAGNET2
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/stagnet2-network.json
NX_VEGA_URL=https://n03.stagnet2.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
-NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
diff --git a/apps/trading/.env.testnet b/apps/trading/.env.testnet
index 6240b763d..7804d1378 100644
--- a/apps/trading/.env.testnet
+++ b/apps/trading/.env.testnet
@@ -1,7 +1,7 @@
# App configuration variables
NX_VEGA_ENV=TESTNET
+NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/testnet-network.json
NX_VEGA_URL=https://lb.testnet.vega.xyz/query
NX_VEGA_NETWORKS='{\"MAINNET\":\"https://alpha.console.vega.xyz\"}'
-NX_ETHEREUM_CHAIN_ID=3
NX_ETHEREUM_PROVIDER_URL=https://ropsten.infura.io/v3/4f846e79e13f44d1b51bbd7ed9edefb8
NX_ETHERSCAN_URL=https://ropsten.etherscan.io
diff --git a/apps/trading/README.md b/apps/trading/README.md
index 29150e050..fedbdd748 100644
--- a/apps/trading/README.md
+++ b/apps/trading/README.md
@@ -26,11 +26,13 @@ Example configurations are provided here:
There are a few different configuration options offered for this app:
+The network configuration for the app
+
| **Flag** | **Purpose** |
| -------------------------- | -------------------------------------------------------------------------------------------------------- |
| `NX_VEGA_ENV` | The name of the currently connected vega environment |
+| `NX_VEGA_CONFIG_URL` | The network configuration for the app |
| `NX_VEGA_URL` | The GraphQL query endpoint of a [Vega data node](https://github.com/vegaprotocol/networks#data-node) |
-| `NX_ETHEREUM_CHAIN_ID` | The ID of the Ethereum chain the currently connected Vega Network uses. E.g. Ropsten (3) for testnet |
| `NX_ETHEREUM_PROVIDER_URL` | The Ethereum Provider URL for getting data from the Ethereum network, for example Infura or a local node |
| `NX_ETHERSCAN_URL` | The Etherscan URL to link Ethereum transactions to |
diff --git a/apps/trading/components/app-loader/index.tsx b/apps/trading/components/app-loader/index.tsx
index 2b93a86bf..30a997e08 100644
--- a/apps/trading/components/app-loader/index.tsx
+++ b/apps/trading/components/app-loader/index.tsx
@@ -1,6 +1,8 @@
-import { useEagerConnect } from '@vegaprotocol/wallet';
-import { Connectors } from '../../lib/vega-connectors';
import type { ReactNode } from 'react';
+import { useEagerConnect } from '@vegaprotocol/wallet';
+import { NetworkLoader } from '@vegaprotocol/environment';
+import { Connectors } from '../../lib/vega-connectors';
+import { createClient } from '../../lib/apollo-client';
interface AppLoaderProps {
children: ReactNode;
@@ -14,5 +16,5 @@ export function AppLoader({ children }: AppLoaderProps) {
// Get keys from vega wallet immediately
useEagerConnect(Connectors);
- return <>{children}>;
+ return {children};
}
diff --git a/apps/trading/components/web3-container/web3-container.spec.tsx b/apps/trading/components/web3-container/web3-container.spec.tsx
index 438899e96..ca3b08a7a 100644
--- a/apps/trading/components/web3-container/web3-container.spec.tsx
+++ b/apps/trading/components/web3-container/web3-container.spec.tsx
@@ -5,7 +5,7 @@ import { Web3Container } from './web3-container';
import type { useWeb3React } from '@web3-react/core';
import type { NetworkParamsQuery } from '@vegaprotocol/web3';
import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3';
-import { EnvironmentProvider } from '@vegaprotocol/network-switcher';
+import { EnvironmentProvider } from '@vegaprotocol/environment';
const defaultHookValue = {
isActive: false,
diff --git a/apps/trading/components/web3-container/web3-container.tsx b/apps/trading/components/web3-container/web3-container.tsx
index 783b93b5c..e0da31b5a 100644
--- a/apps/trading/components/web3-container/web3-container.tsx
+++ b/apps/trading/components/web3-container/web3-container.tsx
@@ -8,7 +8,7 @@ import { useWeb3React } from '@web3-react/core';
import type { ReactNode } from 'react';
import { useEffect, useState, useMemo } from 'react';
import { t } from '@vegaprotocol/react-helpers';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { createConnectors } from '../../lib/web3-connectors';
interface Web3ContainerProps {
@@ -18,14 +18,15 @@ interface Web3ContainerProps {
export const Web3Container = ({ children }: Web3ContainerProps) => {
const [dialogOpen, setDialogOpen] = useState(false);
const { config, loading, error } = useEthereumConfig();
- const { ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID } = useEnvironment();
- const Connectors = useMemo(
- () => createConnectors(ETHEREUM_PROVIDER_URL, ETHEREUM_CHAIN_ID),
- [ETHEREUM_CHAIN_ID, ETHEREUM_PROVIDER_URL]
- );
+ const { ETHEREUM_PROVIDER_URL } = useEnvironment();
+ const Connectors = useMemo(() => {
+ if (config?.chain_id) {
+ return createConnectors(ETHEREUM_PROVIDER_URL, Number(config?.chain_id));
+ }
+ }, [config?.chain_id, ETHEREUM_PROVIDER_URL]);
return (
- {config ? (
+ {Connectors && config && (
{
desiredChainId={Number(config.chain_id)}
/>
- ) : null}
+ )}
);
};
diff --git a/apps/trading/pages/_app.page.tsx b/apps/trading/pages/_app.page.tsx
index 45d4a20af..38aaf4014 100644
--- a/apps/trading/pages/_app.page.tsx
+++ b/apps/trading/pages/_app.page.tsx
@@ -1,5 +1,6 @@
import type { AppProps } from 'next/app';
import Head from 'next/head';
+import { useRouter } from 'next/router';
import { Navbar } from '../components/navbar';
import { t, ThemeContext, useThemeSwitcher } from '@vegaprotocol/react-helpers';
import {
@@ -7,29 +8,27 @@ import {
VegaManageDialog,
VegaWalletProvider,
} from '@vegaprotocol/wallet';
-import { NetworkSwitcherDialog } from '@vegaprotocol/network-switcher';
+import {
+ useEnvironment,
+ EnvironmentProvider,
+ NetworkSwitcherDialog,
+} from '@vegaprotocol/environment';
import { Connectors } from '../lib/vega-connectors';
-import { useMemo } from 'react';
-import { createClient } from '../lib/apollo-client';
import { ThemeSwitcher } from '@vegaprotocol/ui-toolkit';
-import { ApolloProvider } from '@apollo/client';
import { AppLoader } from '../components/app-loader';
import { VegaWalletConnectButton } from '../components/vega-wallet-connect-button';
import './styles.css';
import { useGlobalStore } from '../stores';
-import { ENV } from '../lib/config/env';
-import { EnvironmentProvider } from '@vegaprotocol/network-switcher';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
function AppBody({ Component, pageProps }: AppProps) {
+ const { push } = useRouter();
const store = useGlobalStore();
const { VEGA_NETWORKS } = useEnvironment();
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- const [theme, toggleTheme] = useThemeSwitcher();
+ const [, toggleTheme] = useThemeSwitcher();
return (
-
-
+
+
@@ -62,54 +61,46 @@ function AppBody({ Component, pageProps }: AppProps) {
setDialogOpen={(open) => store.setVegaNetworkSwitcherDialog(open)}
onConnect={({ network }) => {
if (VEGA_NETWORKS[network]) {
- window.location.href = VEGA_NETWORKS[network];
+ push(VEGA_NETWORKS[network] ?? '');
}
}}
/>
-
-
+
+
);
}
function VegaTradingApp(props: AppProps) {
const [theme] = useThemeSwitcher();
- const client = useMemo(() => createClient(ENV.vegaUrl), []);
return (
-
-
-
-
-
- {t('Welcome to Vega trading!')}
-
-
- {['1', 'true'].includes(
- process.env['NX_USE_ENV_OVERRIDES'] || ''
- ) ? (
- /* eslint-disable-next-line @next/next/no-sync-scripts */
-
- ) : null}
-
-
-
-
-
+
+
+
+ {t('Welcome to Vega trading!')}
+
+
+ {['1', 'true'].includes(
+ process.env['NX_USE_ENV_OVERRIDES'] || ''
+ ) ? (
+ /* eslint-disable-next-line @next/next/no-sync-scripts */
+
+ ) : null}
+
+
+
);
diff --git a/apps/trading/pages/markets/trade-grid.tsx b/apps/trading/pages/markets/trade-grid.tsx
index 2920e194d..6a06c6e8c 100644
--- a/apps/trading/pages/markets/trade-grid.tsx
+++ b/apps/trading/pages/markets/trade-grid.tsx
@@ -2,7 +2,10 @@ import classNames from 'classnames';
import AutoSizer from 'react-virtualized-auto-sizer';
import type { ReactNode } from 'react';
import { useState } from 'react';
-import { DealTicketContainer } from '@vegaprotocol/deal-ticket';
+import {
+ DealTicketContainer,
+ MarketInfoContainer,
+} from '@vegaprotocol/deal-ticket';
import { OrderListContainer } from '@vegaprotocol/order-list';
import { TradesContainer } from '@vegaprotocol/trades';
import { PositionsContainer } from '@vegaprotocol/positions';
@@ -30,6 +33,7 @@ const TradingViews = {
Positions: PositionsContainer,
Accounts: AccountsContainer,
Trades: TradesContainer,
+ Info: MarketInfoContainer,
};
type TradingView = keyof typeof TradingViews;
@@ -52,12 +56,12 @@ export const TradeMarketHeader = ({
'font-sans font-normal mb-0 text-dark/80 dark:text-white/80 text-ui-small';
const itemValueClassName =
'capitalize font-sans tracking-tighter text-black dark:text-white text-ui';
- const headerClassname = classNames(
+ const headerClassName = classNames(
'w-full p-8 bg-white dark:bg-black',
className
);
return (
-
+
);
}
diff --git a/libs/tailwindcss-config/src/index.js b/libs/tailwindcss-config/src/index.js
index c7c7a09b6..aea0e9677 100644
--- a/libs/tailwindcss-config/src/index.js
+++ b/libs/tailwindcss-config/src/index.js
@@ -1,7 +1,9 @@
const theme = require('./theme');
+const themelite = require('./theme-lite');
const vegaCustomClasses = require('./vega-custom-classes');
module.exports = {
theme,
+ themelite,
plugins: [vegaCustomClasses],
};
diff --git a/libs/tailwindcss-config/src/theme-lite.js b/libs/tailwindcss-config/src/theme-lite.js
new file mode 100644
index 000000000..a18b56303
--- /dev/null
+++ b/libs/tailwindcss-config/src/theme-lite.js
@@ -0,0 +1,19 @@
+const theme = require('./theme');
+
+module.exports = {
+ ...theme,
+ colors: {
+ ...theme.colors,
+ offBlack: '#252525',
+ midGrey: '#828282',
+ borderGrey: '#4f4f4f',
+ lightGrey: '#F2F2F2',
+ yellow: '#DFFF0B',
+ mint: '#00F780',
+ pink: '#FF077F',
+ },
+ fontSize: {
+ ...theme.fontSize,
+ capMenu: ['15px', { lineHeight: '24px', letterSpacing: '-0.01em' }],
+ },
+};
diff --git a/libs/trades/src/lib/__generated__/TradeFields.ts b/libs/trades/src/lib/__generated__/TradeFields.ts
index 8ea3b94cb..e3eb24265 100644
--- a/libs/trades/src/lib/__generated__/TradeFields.ts
+++ b/libs/trades/src/lib/__generated__/TradeFields.ts
@@ -30,6 +30,12 @@ export interface TradeFields_market {
* GBX (pence) 1 4 GBP 0.000001 ( 0.0001p)
*/
decimalPlaces: number;
+ /**
+ * positionDecimalPlaces indicated the number of decimal places that an integer must be shifted in order to get a correct size (uint64).
+ * i.e. 0 means there are no fractional orders for the market, and order sizes are always whole sizes.
+ * 2 means sizes given as 10^2 * desired size, e.g. a desired size of 1.23 is represented as 123 in this market.
+ */
+ positionDecimalPlaces: number;
}
export interface TradeFields {
diff --git a/libs/trades/src/lib/__generated__/Trades.ts b/libs/trades/src/lib/__generated__/Trades.ts
index 923b49601..e7bd4e8a8 100644
--- a/libs/trades/src/lib/__generated__/Trades.ts
+++ b/libs/trades/src/lib/__generated__/Trades.ts
@@ -30,6 +30,12 @@ export interface Trades_market_trades_market {
* GBX (pence) 1 4 GBP 0.000001 ( 0.0001p)
*/
decimalPlaces: number;
+ /**
+ * positionDecimalPlaces indicated the number of decimal places that an integer must be shifted in order to get a correct size (uint64).
+ * i.e. 0 means there are no fractional orders for the market, and order sizes are always whole sizes.
+ * 2 means sizes given as 10^2 * desired size, e.g. a desired size of 1.23 is represented as 123 in this market.
+ */
+ positionDecimalPlaces: number;
}
export interface Trades_market_trades {
diff --git a/libs/trades/src/lib/__generated__/TradesSub.ts b/libs/trades/src/lib/__generated__/TradesSub.ts
index 54e6be1e0..9b837772d 100644
--- a/libs/trades/src/lib/__generated__/TradesSub.ts
+++ b/libs/trades/src/lib/__generated__/TradesSub.ts
@@ -30,6 +30,12 @@ export interface TradesSub_trades_market {
* GBX (pence) 1 4 GBP 0.000001 ( 0.0001p)
*/
decimalPlaces: number;
+ /**
+ * positionDecimalPlaces indicated the number of decimal places that an integer must be shifted in order to get a correct size (uint64).
+ * i.e. 0 means there are no fractional orders for the market, and order sizes are always whole sizes.
+ * 2 means sizes given as 10^2 * desired size, e.g. a desired size of 1.23 is represented as 123 in this market.
+ */
+ positionDecimalPlaces: number;
}
export interface TradesSub_trades {
diff --git a/libs/trades/src/lib/trades-data-provider.ts b/libs/trades/src/lib/trades-data-provider.ts
index 96462a07e..6381cb8b0 100644
--- a/libs/trades/src/lib/trades-data-provider.ts
+++ b/libs/trades/src/lib/trades-data-provider.ts
@@ -16,6 +16,7 @@ const TRADES_FRAGMENT = gql`
market {
id
decimalPlaces
+ positionDecimalPlaces
}
}
`;
diff --git a/libs/trades/src/lib/trades-table.spec.tsx b/libs/trades/src/lib/trades-table.spec.tsx
index abebb4dd3..e4f566179 100644
--- a/libs/trades/src/lib/trades-table.spec.tsx
+++ b/libs/trades/src/lib/trades-table.spec.tsx
@@ -7,12 +7,13 @@ const trade: TradeFields = {
__typename: 'Trade',
id: 'trade-id',
price: '111122200',
- size: '20',
+ size: '2000',
createdAt: new Date('2022-04-06T19:00:00').toISOString(),
market: {
__typename: 'Market',
id: 'market-id',
decimalPlaces: 2,
+ positionDecimalPlaces: 2,
},
};
@@ -34,7 +35,7 @@ it('Number and data columns are formatted', async () => {
const cells = screen.getAllByRole('gridcell');
const expectedValues = [
'1,111,222.00',
- '20',
+ '20.00',
getDateTimeFormat().format(new Date(trade.createdAt)),
];
cells.forEach((cell, i) => {
diff --git a/libs/trades/src/lib/trades-table.tsx b/libs/trades/src/lib/trades-table.tsx
index 2e2aa577f..5e814a776 100644
--- a/libs/trades/src/lib/trades-table.tsx
+++ b/libs/trades/src/lib/trades-table.tsx
@@ -4,6 +4,7 @@ import { forwardRef, useMemo } from 'react';
import { AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
import type { TradeFields } from './__generated__/TradeFields';
import {
+ addDecimal,
addDecimalsFormatNumber,
getDateTimeFormat,
t,
@@ -73,6 +74,9 @@ export const TradesTable = forwardRef(
{
+ return addDecimal(value, data.market.positionDecimalPlaces);
+ }}
cellClass={changeCellClass('size')}
/>
{
it('should render successfully', () => {
render(
-
);
expect(screen.queryByTestId('accordion-title')).toHaveTextContent(
@@ -17,9 +18,10 @@ describe('Accordion', () => {
it('should toggle and open expansion panel', () => {
render(
-
);
fireEvent.click(screen.getByTestId('accordion-toggle'));
diff --git a/libs/ui-toolkit/src/components/accordion/accordion.stories.tsx b/libs/ui-toolkit/src/components/accordion/accordion.stories.tsx
index e0ebd96d7..775d7d807 100644
--- a/libs/ui-toolkit/src/components/accordion/accordion.stories.tsx
+++ b/libs/ui-toolkit/src/components/accordion/accordion.stories.tsx
@@ -1,17 +1,27 @@
import type { Story, Meta } from '@storybook/react';
-import { AccordionPanel } from './accordion';
+import { Accordion } from './accordion';
export default {
- component: AccordionPanel,
+ component: Accordion,
title: 'Accordion',
} as Meta;
-const Template: Story = (args) => (
-
-);
+const Template: Story = (args) => ;
export const Default = Template.bind({});
Default.args = {
- title: 'Title of expansion panel',
- content: 'Lorem ipsum',
+ panels: [
+ {
+ title: 'Title of expansion panel',
+ content: 'Lorem ipsum',
+ },
+ {
+ title: 'Title of expansion panel',
+ content: 'Lorem ipsum',
+ },
+ {
+ title: 'Title of expansion panel',
+ content: 'Lorem ipsum',
+ },
+ ],
};
diff --git a/libs/ui-toolkit/src/components/accordion/accordion.tsx b/libs/ui-toolkit/src/components/accordion/accordion.tsx
index 58eeafb9c..3116e611c 100644
--- a/libs/ui-toolkit/src/components/accordion/accordion.tsx
+++ b/libs/ui-toolkit/src/components/accordion/accordion.tsx
@@ -1,73 +1,59 @@
-import React, { useRef, useState } from 'react';
+import React, { useState } from 'react';
+import * as AccordionPrimitive from '@radix-ui/react-accordion';
+import ChevronDownIcon from './chevron-down';
+import classNames from 'classnames';
-export interface AccordionProps {
+export interface AccordionItemProps {
title: React.ReactNode;
content: React.ReactNode;
}
-export const AccordionPanel = ({ title, content }: AccordionProps) => {
- const [active, setActive] = useState(false);
- const [height, setHeight] = useState('0px');
- const [rotate, setRotate] = useState(
- 'transform duration-300 ease rotate-180'
+export interface AccordionProps {
+ panels: AccordionItemProps[];
+}
+
+export const Accordion = ({ panels }: AccordionProps) => {
+ const [value, setValue] = useState('');
+ const triggerClassNames = classNames(
+ 'w-full py-2 box-border',
+ 'appearance-none cursor-pointer focus:outline-none',
+ 'flex items-center justify-between border-b border-muted'
);
- const contentSpace = useRef(null);
-
- const toggleAccordion = () => {
- setActive((prevState) => !prevState);
- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
- // @ts-ignore
- setHeight(active ? '0px' : `${contentSpace.current.scrollHeight}px`);
- setRotate(
- active
- ? 'transform duration-300 ease rotate-180'
- : 'transform duration-300 ease'
- );
- };
-
return (
-
-
-
- {title}
-
-
-
-
-
+
+ {panels.map(({ title, content }, i) => (
+
+
+
+
+ {title}
+
+
+
+
+
+
+ {content}
+
+
+
+ ))}
+
);
};
diff --git a/libs/ui-toolkit/src/components/accordion/chevron-down.tsx b/libs/ui-toolkit/src/components/accordion/chevron-down.tsx
new file mode 100644
index 000000000..8b150dc62
--- /dev/null
+++ b/libs/ui-toolkit/src/components/accordion/chevron-down.tsx
@@ -0,0 +1,31 @@
+export const ChevronDownIcon = ({ active }: ChevronDownIconProps) => {
+ const rotate = active
+ ? 'transform duration-300 ease rotate-180'
+ : 'transform duration-300 ease';
+ return (
+
+ );
+};
+
+export interface ChevronDownIconProps {
+ active: boolean;
+}
+
+export default ChevronDownIcon;
diff --git a/libs/ui-toolkit/src/components/async-renderer/async-renderer.tsx b/libs/ui-toolkit/src/components/async-renderer/async-renderer.tsx
index d234e1ffe..16ef721e4 100644
--- a/libs/ui-toolkit/src/components/async-renderer/async-renderer.tsx
+++ b/libs/ui-toolkit/src/components/async-renderer/async-renderer.tsx
@@ -1,12 +1,12 @@
import { Splash } from '../splash';
-import type { ReactElement, ReactNode } from 'react';
+import type { ReactNode } from 'react';
import { t } from '@vegaprotocol/react-helpers';
interface AsyncRendererProps {
loading: boolean;
error: Error | undefined | null;
data: T | undefined;
- children?: ReactElement | null;
+ children?: ReactNode | null;
render?: (data: T) => ReactNode;
}
diff --git a/libs/ui-toolkit/src/components/dialog/dialog.tsx b/libs/ui-toolkit/src/components/dialog/dialog.tsx
index 275707150..e7c7309ca 100644
--- a/libs/ui-toolkit/src/components/dialog/dialog.tsx
+++ b/libs/ui-toolkit/src/components/dialog/dialog.tsx
@@ -8,7 +8,7 @@ import { Icon } from '../icon';
interface DialogProps {
children: ReactNode;
open: boolean;
- onChange: (isOpen: boolean) => void;
+ onChange?: (isOpen: boolean) => void;
title?: string;
intent?: Intent;
titleClassNames?: string;
@@ -33,7 +33,7 @@ export function Dialog({
contentClassNames
);
return (
- onChange(x)}>
+ onChange?.(x)}>
;
+const Template: Story = (args) => ;
export const Default = Template.bind({});
Default.args = {};
diff --git a/libs/ui-toolkit/src/utils/intent.tsx b/libs/ui-toolkit/src/utils/intent.tsx
index 4a9845eaa..ed81ab625 100644
--- a/libs/ui-toolkit/src/utils/intent.tsx
+++ b/libs/ui-toolkit/src/utils/intent.tsx
@@ -19,7 +19,8 @@ export const getIntentShadow = (intent?: Intent) => {
export const getVariantBackground = (variant?: Intent) => {
return {
- 'bg-black dark:bg-white': variant === Intent.None,
+ 'bg-black text-white dark:bg-white dark:text-black':
+ variant === Intent.None,
'bg-vega-pink text-black dark:bg-vega-yellow dark:text-black-normal':
variant === Intent.Primary,
'bg-danger text-white': variant === Intent.Danger,
diff --git a/libs/wallet/src/connectors/rest-connector.ts b/libs/wallet/src/connectors/rest-connector.ts
index 2dfe240f3..de7b9c410 100644
--- a/libs/wallet/src/connectors/rest-connector.ts
+++ b/libs/wallet/src/connectors/rest-connector.ts
@@ -87,27 +87,28 @@ export class RestConnector implements VegaConnector {
async sendTx(body: TransactionSubmission) {
try {
- return await this.service.commandSyncPost(body);
+ const res = await this.service.commandSyncPost(body);
+ return res;
} catch (err) {
return this.handleSendTxError(err);
}
}
private handleSendTxError(err: unknown) {
- if (typeof err === 'object' && err && 'body' in err) {
+ const unpexpectedError = { error: 'Something went wrong' };
+
+ if (isServiceError(err)) {
+ if (err.code === 401) {
+ return { error: 'User rejected' };
+ }
+
try {
- // @ts-ignore Not sure why TS can't infer that 'body' does indeed exist on object
- return JSON.parse(err.body);
+ return JSON.parse(err.body ?? '');
} catch {
- // Unexpected response
- return {
- error: 'Something went wrong',
- };
+ return unpexpectedError;
}
} else {
- return {
- error: 'Something went wrong',
- };
+ return unpexpectedError;
}
}
@@ -132,3 +133,17 @@ export class RestConnector implements VegaConnector {
LocalStorage.removeItem(this.configKey);
}
}
+
+interface ServiceError {
+ code: number;
+ body: string | undefined;
+ headers: object;
+}
+
+export const isServiceError = (err: unknown): err is ServiceError => {
+ // Some responses don't contain body object
+ if (typeof err === 'object' && err !== null && 'code' in err) {
+ return true;
+ }
+ return false;
+};
diff --git a/libs/wallet/src/use-vega-transaction.spec.tsx b/libs/wallet/src/use-vega-transaction.spec.tsx
index 6388745f2..59d115990 100644
--- a/libs/wallet/src/use-vega-transaction.spec.tsx
+++ b/libs/wallet/src/use-vega-transaction.spec.tsx
@@ -2,7 +2,11 @@ import { act, renderHook } from '@testing-library/react-hooks';
import type { VegaWalletContextShape } from './context';
import { VegaWalletContext } from './context';
import type { ReactNode } from 'react';
-import { useVegaTransaction, VegaTxStatus } from './use-vega-transaction';
+import {
+ initialState,
+ useVegaTransaction,
+ VegaTxStatus,
+} from './use-vega-transaction';
import type { OrderSubmission } from './types';
const defaultWalletContext = {
@@ -94,3 +98,14 @@ it('Returns the signature if successful', async () => {
successObj.tx.signature.value
);
});
+
+it('Resets transaction state if user rejects', async () => {
+ const mockSendTx = jest
+ .fn()
+ .mockReturnValue(Promise.resolve({ error: 'User rejected' }));
+ const { result } = setup({ sendTx: mockSendTx });
+ await act(async () => {
+ result.current.send({} as OrderSubmission);
+ });
+ expect(result.current.transaction).toEqual(initialState);
+});
diff --git a/libs/wallet/src/use-vega-transaction.ts b/libs/wallet/src/use-vega-transaction.ts
index 21f7288d1..bbddf9d32 100644
--- a/libs/wallet/src/use-vega-transaction.ts
+++ b/libs/wallet/src/use-vega-transaction.ts
@@ -44,6 +44,10 @@ export const useVegaTransaction = () => {
[setTransaction]
);
+ const reset = useCallback(() => {
+ setTransaction(initialState);
+ }, [setTransaction]);
+
const send = useCallback(
async (tx: TransactionSubmission) => {
setTransaction({
@@ -61,7 +65,12 @@ export const useVegaTransaction = () => {
}
if ('error' in res) {
- handleError(res);
+ // Close dialog if user rejects the transaction
+ if (res.error === 'User rejected') {
+ reset();
+ } else {
+ handleError(res);
+ }
return null;
} else if ('errors' in res) {
handleError(res);
@@ -79,12 +88,8 @@ export const useVegaTransaction = () => {
return null;
},
- [sendTx, handleError, setTransaction]
+ [sendTx, handleError, setTransaction, reset]
);
- const reset = useCallback(() => {
- setTransaction(initialState);
- }, [setTransaction]);
-
return { send, transaction, reset };
};
diff --git a/libs/web3/src/lib/transaction-dialog/dialog-rows.tsx b/libs/web3/src/lib/transaction-dialog/dialog-rows.tsx
index 82dbfdd28..31548a0ba 100644
--- a/libs/web3/src/lib/transaction-dialog/dialog-rows.tsx
+++ b/libs/web3/src/lib/transaction-dialog/dialog-rows.tsx
@@ -1,6 +1,6 @@
import { t } from '@vegaprotocol/react-helpers';
import { Link } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { EthTxStatus } from '../use-ethereum-transaction';
const ACTIVE_CLASSES = 'text-black dark:text-white';
diff --git a/libs/withdraws/src/lib/withdraw-dialog.tsx b/libs/withdraws/src/lib/withdraw-dialog.tsx
index f7e1fc4fd..1e1188283 100644
--- a/libs/withdraws/src/lib/withdraw-dialog.tsx
+++ b/libs/withdraws/src/lib/withdraw-dialog.tsx
@@ -1,5 +1,5 @@
import { Link, Dialog, Icon, Intent, Loader } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import type { VegaTxState } from '@vegaprotocol/wallet';
import { VegaTxStatus } from '@vegaprotocol/wallet';
import type { ReactNode } from 'react';
diff --git a/libs/withdraws/src/lib/withdrawals-table.tsx b/libs/withdraws/src/lib/withdrawals-table.tsx
index 53b7e63cd..d5b363418 100644
--- a/libs/withdraws/src/lib/withdrawals-table.tsx
+++ b/libs/withdraws/src/lib/withdrawals-table.tsx
@@ -11,7 +11,7 @@ import {
} from '@vegaprotocol/react-helpers';
import { WithdrawalStatus } from '@vegaprotocol/types';
import { Link, AgGridDynamic as AgGrid } from '@vegaprotocol/ui-toolkit';
-import { useEnvironment } from '@vegaprotocol/network-switcher';
+import { useEnvironment } from '@vegaprotocol/environment';
import { TransactionDialog } from '@vegaprotocol/web3';
import { useCompleteWithdraw } from './use-complete-withdraw';
import type { Withdrawals_party_withdrawals } from './__generated__/Withdrawals';
diff --git a/package.json b/package.json
index 6968cf920..d0f6b3af8 100644
--- a/package.json
+++ b/package.json
@@ -19,15 +19,17 @@
"@emotion/styled": "^11.8.1",
"@mui/material": "^5.6.2",
"@nrwl/next": "13.10.3",
+ "@radix-ui/react-accordion": "^0.1.6",
"@radix-ui/react-dialog": "^0.1.5",
"@radix-ui/react-dropdown-menu": "^0.1.6",
+ "@radix-ui/react-icons": "^1.1.1",
"@radix-ui/react-radio-group": "^0.1.5",
"@radix-ui/react-tabs": "^0.1.5",
"@radix-ui/react-tooltip": "^0.1.7",
"@sentry/nextjs": "^6.19.3",
"@sentry/react": "^6.19.2",
"@sentry/tracing": "^6.19.2",
- "@vegaprotocol/vegawallet-service-api-client": "^0.4.11",
+ "@vegaprotocol/vegawallet-service-api-client": "^0.4.13",
"@walletconnect/ethereum-provider": "^1.7.5",
"@web3-react/core": "8.0.20-beta.0",
"@web3-react/metamask": "8.0.16-beta.0",
@@ -73,6 +75,7 @@
"tslib": "^2.0.0",
"uuid": "^8.3.2",
"web-vitals": "^2.1.4",
+ "zod": "^3.17.3",
"zustand": "^4.0.0-rc.1"
},
"devDependencies": {
diff --git a/tsconfig.base.json b/tsconfig.base.json
index 5654dfc9a..9c8bdb87a 100644
--- a/tsconfig.base.json
+++ b/tsconfig.base.json
@@ -21,10 +21,10 @@
"@vegaprotocol/cypress": ["libs/cypress/src/index.ts"],
"@vegaprotocol/deal-ticket": ["libs/deal-ticket/src/index.ts"],
"@vegaprotocol/deposits": ["libs/deposits/src/index.ts"],
+ "@vegaprotocol/environment": ["libs/environment/src/index.ts"],
"@vegaprotocol/market-depth": ["libs/market-depth/src/index.ts"],
"@vegaprotocol/market-list": ["libs/market-list/src/index.ts"],
"@vegaprotocol/network-stats": ["libs/network-stats/src/index.ts"],
- "@vegaprotocol/network-switcher": ["libs/network-switcher/src/index.ts"],
"@vegaprotocol/order-list": ["libs/order-list/src/index.ts"],
"@vegaprotocol/positions": ["libs/positions/src/index.ts"],
"@vegaprotocol/react-helpers": ["libs/react-helpers/src/index.ts"],
diff --git a/workspace.json b/workspace.json
index 4836649a8..5d672ae34 100644
--- a/workspace.json
+++ b/workspace.json
@@ -6,12 +6,12 @@
"cypress": "libs/cypress",
"deal-ticket": "libs/deal-ticket",
"deposits": "libs/deposits",
+ "environment": "libs/environment",
"explorer": "apps/explorer",
"explorer-e2e": "apps/explorer-e2e",
"market-depth": "libs/market-depth",
"market-list": "libs/market-list",
"network-stats": "libs/network-stats",
- "network-switcher": "libs/network-switcher",
"order-list": "libs/order-list",
"positions": "libs/positions",
"react-helpers": "libs/react-helpers",
diff --git a/yarn.lock b/yarn.lock
index c01f593da..849d2216f 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -3364,6 +3364,21 @@
dependencies:
"@babel/runtime" "^7.13.10"
+"@radix-ui/react-accordion@^0.1.6":
+ version "0.1.6"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-accordion/-/react-accordion-0.1.6.tgz#b76613d56717ed24b8cf6cb1897cbd54f04714ed"
+ integrity sha512-LOXlqPU6y6EMBopdRIKCWFvMPY1wPTQ4uJiX7ZVxldrMJcM7imBzI3wlRTkPCHZ3FLHmpuw+cQi3du23pzJp1g==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "0.1.0"
+ "@radix-ui/react-collapsible" "0.1.6"
+ "@radix-ui/react-collection" "0.1.4"
+ "@radix-ui/react-compose-refs" "0.1.0"
+ "@radix-ui/react-context" "0.1.1"
+ "@radix-ui/react-id" "0.1.5"
+ "@radix-ui/react-primitive" "0.1.4"
+ "@radix-ui/react-use-controllable-state" "0.1.0"
+
"@radix-ui/react-arrow@0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@radix-ui/react-arrow/-/react-arrow-0.1.4.tgz#a871448a418cd3507d83840fdd47558cb961672b"
@@ -3372,6 +3387,21 @@
"@babel/runtime" "^7.13.10"
"@radix-ui/react-primitive" "0.1.4"
+"@radix-ui/react-collapsible@0.1.6":
+ version "0.1.6"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-collapsible/-/react-collapsible-0.1.6.tgz#3eeadac476761b3c9b8dd91e8a32eb1a547e5a06"
+ integrity sha512-Gkf8VuqMc6HTLzA2AxVYnyK6aMczVLpatCjdD9Lj4wlYLXCz9KtiqZYslLMeqnQFLwLyZS0WKX/pQ8j5fioIBw==
+ dependencies:
+ "@babel/runtime" "^7.13.10"
+ "@radix-ui/primitive" "0.1.0"
+ "@radix-ui/react-compose-refs" "0.1.0"
+ "@radix-ui/react-context" "0.1.1"
+ "@radix-ui/react-id" "0.1.5"
+ "@radix-ui/react-presence" "0.1.2"
+ "@radix-ui/react-primitive" "0.1.4"
+ "@radix-ui/react-use-controllable-state" "0.1.0"
+ "@radix-ui/react-use-layout-effect" "0.1.0"
+
"@radix-ui/react-collection@0.1.4":
version "0.1.4"
resolved "https://registry.yarnpkg.com/@radix-ui/react-collection/-/react-collection-0.1.4.tgz#734061ffd5bb93e88889d49b87391a73a63824c9"
@@ -3462,6 +3492,11 @@
"@radix-ui/react-primitive" "0.1.4"
"@radix-ui/react-use-callback-ref" "0.1.0"
+"@radix-ui/react-icons@^1.1.1":
+ version "1.1.1"
+ resolved "https://registry.yarnpkg.com/@radix-ui/react-icons/-/react-icons-1.1.1.tgz#38d2aa548035dd3b799c169bd17177b1cec3152b"
+ integrity sha512-xc3wQC59rsFylVbSusQCrrM+6695ppF730Q6yqzhRdqDcRNWIm2R6ngpzBoSOQMcwnq4p805F+Gr7xo4fmtN1A==
+
"@radix-ui/react-id@0.1.5":
version "0.1.5"
resolved "https://registry.yarnpkg.com/@radix-ui/react-id/-/react-id-0.1.5.tgz#010d311bedd5a2884c1e9bb6aaaa4e6cc1d1d3b8"
@@ -6715,10 +6750,10 @@
"@typescript-eslint/types" "5.22.0"
eslint-visitor-keys "^3.0.0"
-"@vegaprotocol/vegawallet-service-api-client@^0.4.11":
- version "0.4.11"
- resolved "https://registry.yarnpkg.com/@vegaprotocol/vegawallet-service-api-client/-/vegawallet-service-api-client-0.4.11.tgz#41a623afc9957dcf8b5425f74280ba7861e92b74"
- integrity sha512-yiodc3YFWG+RGG+wjpTjYmNAECP/Nv244mVu8IGVtj8LZo02KC/LpNCgmMhGaK4ZcqVtxHv9t7OUCSEWZhSgOg==
+"@vegaprotocol/vegawallet-service-api-client@^0.4.13":
+ version "0.4.13"
+ resolved "https://registry.yarnpkg.com/@vegaprotocol/vegawallet-service-api-client/-/vegawallet-service-api-client-0.4.13.tgz#fb98ec0179ea6cc27e991ef3d3338327eca4f3c4"
+ integrity sha512-YK6DsDKgvb+n9QwvKYSBQ51TDon0lGpLsNdNUa4oywIjubzWGVE4g98GrEmcP+UB/AfZzLA6A9ul7F/+TSep5Q==
dependencies:
es6-promise "^4.2.4"
url-parse "^1.4.3"
@@ -22669,6 +22704,11 @@ zen-observable@0.8.15, zen-observable@^0.8.0:
resolved "https://registry.yarnpkg.com/zen-observable/-/zen-observable-0.8.15.tgz#96415c512d8e3ffd920afd3889604e30b9eaac15"
integrity sha512-PQ2PC7R9rslx84ndNBZB/Dkv8V8fZEpk83RLgXtYd0fwUgEjseMn1Dgajh2x6S8QbZAFa9p2qVCEuYZNgve0dQ==
+zod@^3.17.3:
+ version "3.17.3"
+ resolved "https://registry.yarnpkg.com/zod/-/zod-3.17.3.tgz#86abbc670ff0063a4588d85a4dcc917d6e4af2ba"
+ integrity sha512-4oKP5zvG6GGbMlqBkI5FESOAweldEhSOZ6LI6cG+JzUT7ofj1ZOC0PJudpQOpT1iqOFpYYtX5Pw0+o403y4bcg==
+
zustand@^4.0.0-beta.2:
version "4.0.0-beta.3"
resolved "https://registry.yarnpkg.com/zustand/-/zustand-4.0.0-beta.3.tgz#16dc82b48b65ed61fe2bae5dea4501f49bd450c7"