feat#873): wallet service v2 (#1349)
* feat: update connect dialog to handle api v2 * feat: better error handling * feat: update to only use strings for pubkey, add json rpc connector * feat: make json connector follow same patterns as rest connector * feat: add ability to change wallet location * feat: add chain id fetch * feat: improve types * feat: adjust send tx types * chore: remove dialog title and chain check temporarily * feat: additional UI and error handling * feat: rename keypair and keypairs to pubKey and pubKeys * feat: make rest and json rpc connectors return consistent data * feat: rename derived ids more clearly * feat: update send_transaction response type * chore: fix tests after context name change * feat: add utils for wallet, add encode tx func * feat: return null if tx is rejected * feat: fix up styles for connect buttons * feat: handle wallet version check * feat: add chain id check * chore: rename select pub key function to match, fix tests * fix: tests for rest connector form * feat: add tests for json rpc flow * feat: connect dialog changes * chore: change status to enum to avoid magic strings * feat: add custom icons and handle provided key name * chore: update global wallet connection e2d tests * chore: change zod validation to only expected required values * chore: ignore new generated code files * chore: fix typos and add translations * chore: set hosted wallet via env var and only show if not mainnet * feat: add functionality for try again button * test: fix failing tests * chore: fix lint and test * chore: remove double import * chore: make console-lite-e2e strict so json connector compiles correctly * chore: make token e2e tsconfig strict * chore: make stats-e2e tsconfig strict * feat: update json rpc request namespace * feat: simplify connector setup, support try again * chore: remove comment * fix: build errors * chore: make chainId check optional based on presence of appChainId, mock request for tests * chore: mock chain id request for all apps on all pages * fix: footer border on small screens * fix: use beforeEach for chainId query mock * chore: remove optional chain check, prevent rendering until fetch is complete * chore: update NX_VEGA_WALLET_URLs as the application now appends the base path, adjust token tests * fix: token e2e test that checks for pubkey name * chore: remove duplicated test, update wallet title assertion * fix: token tests * fix: token e2e assertions * fix: withdraw test * feat: enable json RPC for token * fix: sendTx command now accpets pubkey as separate arg * fix: test to use gui option temporarily Co-authored-by: Dexter <dexter.edwards93@gmail.com>
This commit is contained in:
parent
fe6c5520a9
commit
4ed623c84c
@ -23,4 +23,4 @@ NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
|
||||
|
||||
NX_VEGA_URL=https://api.n11.testnet.vega.xyz/graphql
|
||||
NX_VEGA_ENV=TESTNET
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
|
@ -79,9 +79,9 @@ describe('market list', { tags: '@smoke' }, () => {
|
||||
cy.visit('/markets');
|
||||
cy.wait('@Markets').then((filters) => {
|
||||
const data: MarketsQuery | undefined = filters?.response?.body?.data;
|
||||
if (data.marketsConnection.edges.length) {
|
||||
if (data?.marketsConnection?.edges.length) {
|
||||
const asset =
|
||||
data.marketsConnection.edges[0].node.tradableInstrument.instrument
|
||||
data?.marketsConnection?.edges[0].node.tradableInstrument.instrument
|
||||
.product.settlementAsset.symbol;
|
||||
cy.visit(`/markets/Suspended/Future/${asset}`);
|
||||
cy.getByTestId('market-assets-menu')
|
||||
|
@ -37,8 +37,8 @@ describe('market selector', { tags: '@smoke' }, () => {
|
||||
cy.visit('/markets');
|
||||
cy.wait('@Markets').then((response) => {
|
||||
const data: MarketsQuery | undefined = response?.response?.body?.data;
|
||||
if (data.marketsConnection.edges.length) {
|
||||
markets = data.marketsConnection.edges.map((edge) => edge.node);
|
||||
if (data?.marketsConnection?.edges.length) {
|
||||
markets = data?.marketsConnection?.edges.map((edge) => edge.node);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -35,8 +35,8 @@ describe('Market trade', { tags: '@smoke' }, () => {
|
||||
cy.visit('/markets');
|
||||
cy.wait('@Markets').then((response) => {
|
||||
const data: MarketsQuery | undefined = response?.response?.body?.data;
|
||||
if (data.marketsConnection.edges.length) {
|
||||
markets = data.marketsConnection.edges.map((edge) => edge.node);
|
||||
if (data?.marketsConnection?.edges.length) {
|
||||
markets = data?.marketsConnection?.edges.map((edge) => edge.node);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,9 @@ export const connectVegaWallet = () => {
|
||||
const walletPassphrase = Cypress.env('TRADING_TEST_VEGA_WALLET_PASSPHRASE');
|
||||
|
||||
cy.getByTestId('connect-vega-wallet').click();
|
||||
cy.getByTestId('connectors-list').find('button').click();
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-gui"]')
|
||||
.click();
|
||||
cy.getByTestId(form).find('#wallet').click().type(walletName);
|
||||
cy.getByTestId(form).find('#passphrase').click().type(walletPassphrase);
|
||||
cy.getByTestId('rest-connector-form').find('button[type=submit]').click();
|
||||
|
@ -18,4 +18,14 @@ import 'cypress-real-events/support';
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands';
|
||||
import registerCypressGrep from 'cypress-grep';
|
||||
import { aliasQuery } from '@vegaprotocol/cypress';
|
||||
registerCypressGrep();
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock chainId fetch which happens on every page for wallet connection
|
||||
cy.mockGQL((req) => {
|
||||
aliasQuery(req, 'ChainId', {
|
||||
statistics: { __typename: 'Statistics', chainId: 'test-chain-id' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1107,7 +1107,8 @@ export const generateLongListMarkets = (count: number) => {
|
||||
};
|
||||
};
|
||||
|
||||
export const generateMarkets = (override?): MarketsQuery => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export const generateMarkets = (override?: any): MarketsQuery => {
|
||||
const markets = [protoMarket];
|
||||
|
||||
const defaultResult = {
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"jsx": "react-jsx",
|
||||
"sourceMap": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
@ -20,7 +20,7 @@ NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
|
||||
NX_VEGA_CONFIG_URL="https://static.vega.xyz/assets/testnet-network.json"
|
||||
NX_VEGA_ENV = 'TESTNET'
|
||||
NX_VEGA_URL="https://api.n11.testnet.vega.xyz/graphql"
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
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"}
|
||||
|
@ -37,13 +37,13 @@ const PARTY_BALANCE_QUERY = gql`
|
||||
|
||||
export const DealTicketContainer = () => {
|
||||
const { marketId } = useParams<{ marketId: string }>();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const { data: partyData, loading } = useQuery<PartyBalanceQuery>(
|
||||
PARTY_BALANCE_QUERY,
|
||||
{
|
||||
variables: { partyId: keypair?.pub },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey },
|
||||
skip: !pubKey,
|
||||
}
|
||||
);
|
||||
|
||||
@ -63,7 +63,7 @@ export const DealTicketContainer = () => {
|
||||
data.market.tradableInstrument.instrument.product?.settlementAsset
|
||||
}
|
||||
accounts={partyData?.party?.accounts || []}
|
||||
isWalletConnected={!!keypair?.pub}
|
||||
isWalletConnected={!!pubKey}
|
||||
/>
|
||||
);
|
||||
|
||||
@ -82,7 +82,7 @@ export const DealTicketContainer = () => {
|
||||
return (
|
||||
<section className="flex p-4 md:p-6">
|
||||
<section className="w-full md:w-1/2 md:min-w-[500px]">
|
||||
{keypair ? container : <ConnectWallet />}
|
||||
{pubKey ? container : <ConnectWallet />}
|
||||
</section>
|
||||
<Baubles />
|
||||
</section>
|
||||
|
@ -80,15 +80,15 @@ export const DealTicketSteps = ({
|
||||
fieldErrors: errors,
|
||||
});
|
||||
const { submit, transaction, finalizedOrder, Dialog } = useOrderSubmit();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const estMargin = useOrderMargin({
|
||||
order,
|
||||
market,
|
||||
partyId: keypair?.pub || '',
|
||||
partyId: pubKey || '',
|
||||
});
|
||||
|
||||
const maxTrade = useMaximumPositionSize({
|
||||
partyId: keypair?.pub || '',
|
||||
partyId: pubKey || '',
|
||||
accounts: partyData?.party?.accounts || [],
|
||||
marketId: market.id,
|
||||
settlementAssetId:
|
||||
|
@ -33,11 +33,11 @@ const DEPOSITS_QUERY = gql`
|
||||
*/
|
||||
export const DepositContainer = () => {
|
||||
const { VEGA_ENV } = useEnvironment();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const { data, loading, error } = useQuery<DepositAssets>(DEPOSITS_QUERY, {
|
||||
variables: { partyId: keypair?.pub },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey },
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
const assets = getEnabledAssets(data);
|
||||
|
@ -6,11 +6,11 @@ import { HorizontalMenu } from '../horizontal-menu';
|
||||
import * as constants from './constants';
|
||||
|
||||
export const Portfolio = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { pathname } = useLocation();
|
||||
const module = pathname.split('/portfolio/')?.[1] ?? '';
|
||||
const outlet = useOutlet({ partyId: keypair?.pub || '' });
|
||||
if (!keypair) {
|
||||
const outlet = useOutlet({ partyId: pubKey || '' });
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<section className="xl:w-1/2">
|
||||
<ConnectWallet />
|
||||
|
@ -10,8 +10,8 @@ export const VegaWalletConnectButton = ({
|
||||
setConnectDialog,
|
||||
setManageDialog,
|
||||
}: VegaWalletConnectButtonProps) => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const isConnected = keypair !== null;
|
||||
const { pubKey } = useVegaWallet();
|
||||
const isConnected = pubKey !== null;
|
||||
|
||||
const handleClick = () => {
|
||||
if (isConnected) {
|
||||
@ -31,7 +31,7 @@ export const VegaWalletConnectButton = ({
|
||||
onClick={handleClick}
|
||||
className="ml-auto inline-block text-ui-small font-mono hover:underline"
|
||||
>
|
||||
{isConnected ? truncateByChars(keypair.pub) : 'Connect Vega wallet'}
|
||||
{isConnected ? truncateByChars(pubKey) : 'Connect Vega wallet'}
|
||||
</button>
|
||||
</span>
|
||||
);
|
||||
|
@ -52,7 +52,7 @@ interface Props {
|
||||
}
|
||||
|
||||
const useOrderCloseOut = ({ order, market, partyData }: Props): string => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const account = useSettlementAccount(
|
||||
market.tradableInstrument.instrument.product.settlementAsset.id,
|
||||
partyData?.party?.accounts || []
|
||||
@ -61,15 +61,15 @@ const useOrderCloseOut = ({ order, market, partyData }: Props): string => {
|
||||
CLOSEOUT_PRICE_QUERY,
|
||||
{
|
||||
pollInterval: 5000,
|
||||
variables: { partyId: keypair?.pub || '' },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
}
|
||||
);
|
||||
|
||||
const markPriceData = useMarketData(market.id);
|
||||
const marketPositions = useMarketPositions({
|
||||
marketId: market.id,
|
||||
partyId: keypair?.pub || '',
|
||||
partyId: pubKey || '',
|
||||
});
|
||||
|
||||
const marginMaintenanceLevel = new BigNumber(
|
||||
|
@ -5,6 +5,7 @@ NX_VEGA_CONFIG_URL=https://static.vega.xyz/assets/stagnet3-network.json
|
||||
NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https://explorer.vega.xyz"}'
|
||||
NX_VEGA_ENV=STAGNET3
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
|
||||
# App flags
|
||||
NX_EXPLORER_ASSETS=1
|
||||
|
@ -7,3 +7,4 @@ NX_VEGA_NETWORKS='{"TESTNET":"https://explorer.fairground.wtf","MAINNET":"https:
|
||||
NX_VEGA_ENV=TESTNET
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_VEGA_URL=https://api.n09.testnet.vega.xyz/graphql
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
|
@ -20,7 +20,7 @@ NX_DEPLOY_PRIME_URL=$DEPLOY_PRIME_URL
|
||||
NX_VEGA_CONFIG_URL="https://static.vega.xyz/assets/testnet-network.json"
|
||||
NX_VEGA_ENV = 'TESTNET'
|
||||
NX_VEGA_URL="https://api.n11.testnet.vega.xyz/graphql"
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
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"}
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"jsx": "react-jsx",
|
||||
"sourceMap": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
@ -10,7 +10,7 @@ NX_ETHEREUM_CHAIN_ID=1440
|
||||
NX_ETH_URL_CONNECT=1
|
||||
NX_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session
|
||||
NX_LOCAL_PROVIDER_URL=http://localhost:8545/
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
|
||||
#Test configuration variables
|
||||
CYPRESS_FAIRGROUND=false
|
||||
|
@ -1153,7 +1153,7 @@ context(
|
||||
.should('be.visible')
|
||||
.and('have.text', 'Connect Vega wallet')
|
||||
.click();
|
||||
cy.contains('rest provider').click();
|
||||
cy.getByTestId('connector-gui').click();
|
||||
cy.get(restConnectorForm).within(() => {
|
||||
cy.get('#wallet').click().type(vegaWalletName);
|
||||
cy.get('#passphrase').click().type(vegaWalletPassphrase);
|
||||
|
@ -6,6 +6,7 @@ const connectButton = '[data-testid="connect-vega"]';
|
||||
const getVegaLink = '[data-testid="link"]';
|
||||
const dialog = '[role="dialog"]';
|
||||
const dialogHeader = '[data-testid="dialog-title"]';
|
||||
const walletDialogHeader = '[data-testid="wallet-dialog-title"]';
|
||||
const connectorsList = '[data-testid="connectors-list"]';
|
||||
const dialogCloseBtn = '[data-testid="dialog-close"]';
|
||||
const restConnectorForm = '[data-testid="rest-connector-form"]';
|
||||
@ -75,17 +76,23 @@ context(
|
||||
|
||||
it('should have Connect Vega header visible', function () {
|
||||
cy.get(dialog).within(() => {
|
||||
cy.get(dialogHeader)
|
||||
cy.get(walletDialogHeader)
|
||||
.should('be.visible')
|
||||
.and('have.text', 'Connect to your Vega Wallet');
|
||||
.and('have.text', 'Connect');
|
||||
});
|
||||
});
|
||||
|
||||
it('should have REST connector visible on list', function () {
|
||||
it('should have gui, cli and hosted connection options visible on list', function () {
|
||||
cy.get(connectorsList).within(() => {
|
||||
cy.get('button')
|
||||
cy.getByTestId('connector-gui')
|
||||
.should('be.visible')
|
||||
.and('have.text', 'rest provider');
|
||||
.and('have.text', 'Desktop wallet app');
|
||||
cy.getByTestId('connector-cli')
|
||||
.should('be.visible')
|
||||
.and('have.text', 'Command line wallet app');
|
||||
cy.getByTestId('connector-hosted')
|
||||
.should('be.visible')
|
||||
.and('have.text', 'Hosted Fairground wallet');
|
||||
});
|
||||
});
|
||||
|
||||
@ -97,9 +104,11 @@ context(
|
||||
});
|
||||
|
||||
describe('when rest connector form opened', function () {
|
||||
before('click rest provider link', function () {
|
||||
// Note using desktop wallet app link temporarily whilst its still on v1,
|
||||
// tests will need to be updated to handle v2
|
||||
before('click desktop wallet app link', function () {
|
||||
cy.get(connectorsList).within(() => {
|
||||
cy.get('button').click();
|
||||
cy.getByTestId('connector-gui').click();
|
||||
});
|
||||
});
|
||||
|
||||
@ -123,14 +132,6 @@ context(
|
||||
});
|
||||
});
|
||||
|
||||
it('should have Connect Vega header visible', function () {
|
||||
cy.get(dialog).within(() => {
|
||||
cy.get(dialogHeader)
|
||||
.should('be.visible')
|
||||
.and('have.text', 'Connect to your Vega Wallet');
|
||||
});
|
||||
});
|
||||
|
||||
it('should have close button visible', function () {
|
||||
cy.get(dialog).within(() => {
|
||||
cy.get(dialogCloseBtn).should('be.visible');
|
||||
@ -150,7 +151,8 @@ context(
|
||||
cy.get(connectButton).click();
|
||||
});
|
||||
cy.get(connectorsList).within(() => {
|
||||
cy.get('button').click();
|
||||
// using gui option to connect using wallet service V1
|
||||
cy.getByTestId('connector-gui').click();
|
||||
});
|
||||
// cy.vega_wallet_connect(); - to be changed when dialog state is fixed - https://github.com/vegaprotocol/frontend-monorepo/issues/838
|
||||
// then code below can be removed
|
||||
@ -331,6 +333,7 @@ context(
|
||||
.and('be.visible')
|
||||
.click({ force: true });
|
||||
});
|
||||
cy.getByTestId('connector-gui').click();
|
||||
cy.get(restConnectorForm).within(() => {
|
||||
cy.get('#wallet').click().type(Cypress.env('vegaWalletName'));
|
||||
cy.get('#passphrase')
|
||||
|
@ -7,6 +7,7 @@ import './wallet-eth.functions.js';
|
||||
import './wallet-teardown.functions.js';
|
||||
import './wallet-vega.functions.js';
|
||||
import registerCypressGrep from 'cypress-grep';
|
||||
import { aliasQuery } from '@vegaprotocol/cypress';
|
||||
registerCypressGrep();
|
||||
|
||||
// Hide fetch/XHR requests - They create a lot of noise in command log
|
||||
@ -18,3 +19,12 @@ if (!app.document.head.querySelector('[data-hide-command-log-request]')) {
|
||||
style.setAttribute('data-hide-command-log-request', '');
|
||||
app.document.head.appendChild(style);
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock chainId fetch which happens on every page for wallet connection
|
||||
cy.mockGQL((req) => {
|
||||
aliasQuery(req, 'ChainId', {
|
||||
statistics: { __typename: 'Statistics', chainId: 'test-chain-id' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -13,7 +13,9 @@ Cypress.Commands.add('vega_wallet_connect', () => {
|
||||
.and('be.visible')
|
||||
.click({ force: true });
|
||||
});
|
||||
cy.contains('rest provider').click();
|
||||
// Connect with gui as its the v1 service and tests should still pass. This will need
|
||||
// to be update to use v2
|
||||
cy.getByTestId('connector-gui').click();
|
||||
cy.get(restConnectorForm).within(() => {
|
||||
cy.get('#wallet').click().type(vegaWalletName);
|
||||
cy.get('#passphrase').click().type(vegaWalletPassphrase);
|
||||
|
@ -1,6 +1,7 @@
|
||||
{
|
||||
"extends": "../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"strict": true,
|
||||
"jsx": "react-jsx",
|
||||
"sourceMap": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
|
@ -7,8 +7,9 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_FAIRGROUND=false
|
||||
NX_VEGA_NETWORKS='{"DEVNET":"https://dev.token.vega.xyz","STAGNET3":"https://stagnet3.token.vega.xyz","TESTNET":"https://token.fairground.wtf","MAINNET":"https://token.vega.xyz"}'
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
|
||||
#Test configuration variables
|
||||
CYPRESS_FAIRGROUND=false
|
||||
|
@ -12,7 +12,7 @@ NX_ETHEREUM_CHAIN_ID=1440
|
||||
NX_ETH_URL_CONNECT=1
|
||||
NX_ETH_WALLET_MNEMONIC=ozone access unlock valid olympic save include omit supply green clown session
|
||||
NX_LOCAL_PROVIDER_URL=http://localhost:8545/
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
|
||||
#Test configuration variables
|
||||
CYPRESS_FAIRGROUND=false
|
||||
|
@ -8,3 +8,4 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_GITHUB_FEEDBACK_URL=https://github.com/vegaprotocol/feedback/discussions
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
NX_VEGA_DOCS_URL=https://docs.vega.xyz/docs/testnet
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
@ -45,7 +45,6 @@ There are a few different configuration options offered for this app:
|
||||
| `NX_APP_DEX_STAKING_DISABLED` | Disable the dex liquidity page an show a coming soon message |
|
||||
| `NX_APP_FAIRGROUND` | Change styling to be themed as the fairground version of the website |
|
||||
| `NX_APP_INFURA_ID` | Infura fallback for if the user does not have a web3 compatible browser |
|
||||
| `NX_APP_HOSTED_WALLET_ENABLED` | If the hosted wallet is enabled or not. If so then allow users to login using the hosted wallet |
|
||||
| `NX_APP_ENV` | Change network to connect to. When set to CUSTOM use CUSTOM\_\* vars for network parameters |
|
||||
| `NX_ETH_URL_CONNECT` (optional) | If set to true the below two must also be set. This allows siging transactions in brower to allow to connect to a local ganache node through cypress |
|
||||
| `NX_ETH_WALLET_MNEMONIC` (optional) | The mnemonic to be used to sign transactions with in browser |
|
||||
|
@ -22,7 +22,7 @@ export const AppLoader = ({ children }: { children: React.ReactElement }) => {
|
||||
const { t } = useTranslation();
|
||||
const { account } = useWeb3React();
|
||||
const { VEGA_URL } = useEnvironment();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { appDispatch } = useAppState();
|
||||
const { token, staking, vesting } = useContracts();
|
||||
const setAssociatedBalances = useRefreshAssociatedBalances();
|
||||
@ -68,10 +68,10 @@ export const AppLoader = ({ children }: { children: React.ReactElement }) => {
|
||||
}, [token, appDispatch, staking, vesting]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (account && keypair) {
|
||||
setAssociatedBalances(account, keypair.pub);
|
||||
if (account && pubKey) {
|
||||
setAssociatedBalances(account, pubKey);
|
||||
}
|
||||
}, [setAssociatedBalances, account, keypair]);
|
||||
}, [setAssociatedBalances, account, pubKey]);
|
||||
|
||||
React.useEffect(() => {
|
||||
const networkLimitsEndpoint = new URL('/network/limits', VEGA_URL).href;
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { Button } from '@vegaprotocol/ui-toolkit';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -10,15 +9,15 @@ import {
|
||||
} from '../../contexts/app-state/app-state-context';
|
||||
|
||||
interface VegaWalletContainerProps {
|
||||
children: (key: VegaKeyExtended) => React.ReactElement;
|
||||
children: (key: string) => React.ReactElement;
|
||||
}
|
||||
|
||||
export const VegaWalletContainer = ({ children }: VegaWalletContainerProps) => {
|
||||
const { t } = useTranslation();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { appDispatch } = useAppState();
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<p>
|
||||
<Button
|
||||
@ -36,5 +35,5 @@ export const VegaWalletContainer = ({ children }: VegaWalletContainerProps) => {
|
||||
);
|
||||
}
|
||||
|
||||
return children(keypair);
|
||||
return children(pubKey);
|
||||
};
|
||||
|
@ -63,7 +63,7 @@ const DELEGATIONS_QUERY = gql`
|
||||
export const usePollForDelegations = () => {
|
||||
const { token: vegaToken } = useContracts();
|
||||
const { t } = useTranslation();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const client = useApolloClient();
|
||||
const [delegations, setDelegations] = React.useState<
|
||||
Delegations_party_delegations[]
|
||||
@ -86,13 +86,13 @@ export const usePollForDelegations = () => {
|
||||
let interval: any;
|
||||
let mounted = true;
|
||||
|
||||
if (keypair?.pub) {
|
||||
if (pubKey) {
|
||||
// start polling for delegation
|
||||
interval = setInterval(() => {
|
||||
client
|
||||
.query<Delegations, DelegationsVariables>({
|
||||
query: DELEGATIONS_QUERY,
|
||||
variables: { partyId: keypair.pub },
|
||||
variables: { partyId: pubKey },
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
.then((res) => {
|
||||
@ -229,7 +229,7 @@ export const usePollForDelegations = () => {
|
||||
clearInterval(interval);
|
||||
mounted = false;
|
||||
};
|
||||
}, [client, keypair?.pub, t, vegaToken.address]);
|
||||
}, [client, pubKey, t, vegaToken.address]);
|
||||
|
||||
return { delegations, currentStakeAvailable, delegatedNodes, accounts };
|
||||
};
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
@ -22,18 +22,20 @@ import {
|
||||
} from '../wallet-card';
|
||||
import { DownloadWalletPrompt } from './download-wallet-prompt';
|
||||
import { usePollForDelegations } from './hooks';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { Button, ButtonLink } from '@vegaprotocol/ui-toolkit';
|
||||
|
||||
export const VegaWallet = () => {
|
||||
const { t } = useTranslation();
|
||||
const { keypair, keypairs } = useVegaWallet();
|
||||
const { pubKey, pubKeys } = useVegaWallet();
|
||||
const pubKeyObj = useMemo(() => {
|
||||
return pubKeys?.find((pk) => pk.publicKey === pubKey);
|
||||
}, [pubKey, pubKeys]);
|
||||
|
||||
const child = !keypairs ? (
|
||||
const child = !pubKeys ? (
|
||||
<VegaWalletNotConnected />
|
||||
) : (
|
||||
<VegaWalletConnected vegaKeys={keypairs} />
|
||||
<VegaWalletConnected vegaKeys={pubKeys.map((pk) => pk.publicKey)} />
|
||||
);
|
||||
|
||||
return (
|
||||
@ -41,19 +43,19 @@ export const VegaWallet = () => {
|
||||
<WalletCard>
|
||||
<WalletCardHeader dark={true}>
|
||||
<h1 className="col-start-1 m-0">{t('vegaWallet')}</h1>
|
||||
{keypair && (
|
||||
{pubKeyObj && (
|
||||
<>
|
||||
<div
|
||||
data-testid="wallet-name"
|
||||
className="sm:row-start-2 sm:col-start-1 sm:col-span-2 text-base mb-4"
|
||||
>
|
||||
{keypair.name}
|
||||
{pubKeyObj.name}
|
||||
</div>
|
||||
<span
|
||||
data-testid="vega-account-truncated"
|
||||
className="sm:col-start-2 place-self-end font-mono pb-2 px-4"
|
||||
>
|
||||
{truncateMiddle(keypair.pub)}
|
||||
{truncateMiddle(pubKeyObj.publicKey)}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
@ -109,7 +111,7 @@ const VegaWalletAssetList = ({ accounts }: VegaWalletAssetsListProps) => {
|
||||
};
|
||||
|
||||
interface VegaWalletConnectedProps {
|
||||
vegaKeys: VegaKeyExtended[];
|
||||
vegaKeys: string[];
|
||||
}
|
||||
|
||||
const VegaWalletConnected = ({ vegaKeys }: VegaWalletConnectedProps) => {
|
||||
|
@ -54,9 +54,6 @@ export const ENV = {
|
||||
localProviderUrl: windowOrDefault('NX_LOCAL_PROVIDER_URL'),
|
||||
flags: {
|
||||
NETWORK_DOWN: TRUTHY.includes(windowOrDefault('NX_NETWORK_DOWN')),
|
||||
HOSTED_WALLET_ENABLED: TRUTHY.includes(
|
||||
windowOrDefault('NX_HOSTED_WALLET_ENABLED')
|
||||
),
|
||||
MOCK: TRUTHY.includes(windowOrDefault('NX_MOCKED')),
|
||||
FAIRGROUND: TRUTHY.includes(windowOrDefault('NX_FAIRGROUND')),
|
||||
NETWORK_LIMITS: TRUTHY.includes(windowOrDefault('NX_NETWORK_LIMITS')),
|
||||
|
@ -15,7 +15,7 @@ export const useRefreshBalances = (address: string) => {
|
||||
appState: { decimals },
|
||||
appDispatch,
|
||||
} = useAppState();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { token, staking, vesting } = useContracts();
|
||||
const { config } = useEthereumConfig();
|
||||
|
||||
@ -29,8 +29,8 @@ export const useRefreshBalances = (address: string) => {
|
||||
vesting.user_stats(address),
|
||||
token.allowance(address, config.staking_bridge_contract.address),
|
||||
// Refresh connected vega key balances as well if we are connected to a vega key
|
||||
keypair?.pub ? staking.stake_balance(address, keypair.pub) : null,
|
||||
keypair?.pub ? vesting.stake_balance(address, keypair.pub) : null,
|
||||
pubKey ? staking.stake_balance(address, pubKey) : null,
|
||||
pubKey ? vesting.stake_balance(address, pubKey) : null,
|
||||
]);
|
||||
|
||||
const balance = toBigNum(b, decimals);
|
||||
@ -52,14 +52,5 @@ export const useRefreshBalances = (address: string) => {
|
||||
} catch (err) {
|
||||
Sentry.captureException(err);
|
||||
}
|
||||
}, [
|
||||
address,
|
||||
decimals,
|
||||
appDispatch,
|
||||
keypair?.pub,
|
||||
staking,
|
||||
token,
|
||||
vesting,
|
||||
config,
|
||||
]);
|
||||
}, [address, decimals, appDispatch, pubKey, staking, token, vesting, config]);
|
||||
};
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { RestConnector } from '@vegaprotocol/wallet';
|
||||
import { RestConnector, JsonRpcConnector } from '@vegaprotocol/wallet';
|
||||
|
||||
export const rest = new RestConnector();
|
||||
export const jsonRpc = new JsonRpcConnector();
|
||||
|
||||
export const Connectors = {
|
||||
rest,
|
||||
jsonRpc,
|
||||
};
|
||||
|
@ -42,7 +42,7 @@ export function useUserVote(
|
||||
yesVotes: Votes | null,
|
||||
noVotes: Votes | null
|
||||
) {
|
||||
const { keypair, sendTx } = useVegaWallet();
|
||||
const { pubKey, sendTx } = useVegaWallet();
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const [timeout, setTimeoutValue] = useState<any>(null);
|
||||
const yes = useMemo(() => yesVotes || [], [yesVotes]);
|
||||
@ -54,11 +54,11 @@ export function useUserVote(
|
||||
|
||||
// Find the users vote everytime yes or no votes change
|
||||
const userVote = useMemo(() => {
|
||||
if (keypair) {
|
||||
return getUserVote(keypair.pub, yes, no);
|
||||
if (pubKey) {
|
||||
return getUserVote(pubKey, yes, no);
|
||||
}
|
||||
return null;
|
||||
}, [keypair, yes, no]);
|
||||
}, [pubKey, yes, no]);
|
||||
|
||||
// If user vote changes update the vote state
|
||||
useEffect(() => {
|
||||
@ -91,20 +91,17 @@ export function useUserVote(
|
||||
* Casts a vote using the users connected wallet
|
||||
*/
|
||||
async function castVote(value: VoteValue) {
|
||||
if (!proposalId || !keypair) return;
|
||||
if (!proposalId || !pubKey) return;
|
||||
|
||||
setVoteState(VoteState.Requested);
|
||||
|
||||
try {
|
||||
const variables = {
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
await sendTx(pubKey, {
|
||||
voteSubmission: {
|
||||
value: value,
|
||||
proposalId,
|
||||
},
|
||||
};
|
||||
await sendTx(variables);
|
||||
});
|
||||
setVoteState(VoteState.Pending);
|
||||
|
||||
// Now await vote via poll in parent component
|
||||
|
@ -39,13 +39,13 @@ const VOTE_BUTTONS_QUERY = gql`
|
||||
`;
|
||||
|
||||
export const VoteButtonsContainer = (props: VoteButtonsContainerProps) => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data, loading } = useQuery<
|
||||
VoteButtonsQueryResult,
|
||||
VoteButtonsVariables
|
||||
>(VOTE_BUTTONS_QUERY, {
|
||||
variables: { partyId: keypair?.pub || '' },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
if (loading) return null;
|
||||
@ -73,7 +73,7 @@ export const VoteButtons = ({
|
||||
}: VoteButtonsProps) => {
|
||||
const { t } = useTranslation();
|
||||
const { appDispatch } = useAppState();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [changeVote, setChangeVote] = React.useState(false);
|
||||
|
||||
const cantVoteUI = React.useMemo(() => {
|
||||
@ -81,7 +81,7 @@ export const VoteButtons = ({
|
||||
return t('youDidNotVote');
|
||||
}
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<>
|
||||
<ButtonLink
|
||||
@ -104,7 +104,7 @@ export const VoteButtons = ({
|
||||
}
|
||||
|
||||
return false;
|
||||
}, [t, keypair, currentStakeAvailable, proposalState, appDispatch]);
|
||||
}, [t, pubKey, currentStakeAvailable, proposalState, appDispatch]);
|
||||
|
||||
function submitVote(vote: VoteValue) {
|
||||
setChangeVote(false);
|
||||
|
@ -17,7 +17,7 @@ interface VoteDetailsProps {
|
||||
}
|
||||
|
||||
export const VoteDetails = ({ proposal }: VoteDetailsProps) => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const {
|
||||
totalTokensPercentage,
|
||||
participationMet,
|
||||
@ -114,7 +114,7 @@ export const VoteDetails = ({ proposal }: VoteDetailsProps) => {
|
||||
{t('governanceRequired')})
|
||||
</span>
|
||||
</p>
|
||||
{keypair ? (
|
||||
{pubKey ? (
|
||||
<>
|
||||
<h3 className="text-xl mb-2">{t('yourVote')}</h3>
|
||||
<VoteButtonsContainer
|
||||
|
@ -15,12 +15,12 @@ import { PROPOSAL_EVENT_SUB } from '@vegaprotocol/governance';
|
||||
import type { ProposalEvent } from '@vegaprotocol/governance';
|
||||
|
||||
describe('Raw proposal form', () => {
|
||||
const pubkey = '0x123';
|
||||
const pubKey = '0x123';
|
||||
const mockProposalEvent: MockedResponse<ProposalEvent> = {
|
||||
request: {
|
||||
query: PROPOSAL_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: pubkey,
|
||||
partyId: pubKey,
|
||||
},
|
||||
},
|
||||
result: {
|
||||
@ -51,7 +51,7 @@ describe('Raw proposal form', () => {
|
||||
<VegaWalletContext.Provider
|
||||
value={
|
||||
{
|
||||
keypair: { pub: pubkey },
|
||||
pubKey,
|
||||
sendTx: mockSendTx,
|
||||
} as unknown as VegaWalletContextShape
|
||||
}
|
||||
@ -103,13 +103,9 @@ describe('Raw proposal form', () => {
|
||||
setTimeout(
|
||||
() =>
|
||||
resolve({
|
||||
txHash: 'tx-hash',
|
||||
tx: {
|
||||
signature: {
|
||||
value:
|
||||
'cfe592d169f87d0671dd447751036d0dddc165b9c4b65e5a5060e2bbadd1aa726d4cbe9d3c3b327bcb0bff4f83999592619a2493f9bbd251fae99ce7ce766909',
|
||||
},
|
||||
},
|
||||
transactionHash: 'tx-hash',
|
||||
signature:
|
||||
'cfe592d169f87d0671dd447751036d0dddc165b9c4b65e5a5060e2bbadd1aa726d4cbe9d3c3b327bcb0bff4f83999592619a2493f9bbd251fae99ce7ce766909',
|
||||
}),
|
||||
100
|
||||
);
|
||||
@ -141,9 +137,7 @@ describe('Raw proposal form', () => {
|
||||
fireEvent.click(screen.getByTestId('proposal-submit'));
|
||||
});
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith({
|
||||
propagate: true,
|
||||
pubKey: pubkey,
|
||||
expect(mockSendTx).toHaveBeenCalledWith(pubKey, {
|
||||
proposalSubmission: JSON.parse(inputJSON),
|
||||
});
|
||||
|
||||
|
@ -1,20 +1,16 @@
|
||||
import { NETWORK_PARAMS_QUERY } from '@vegaprotocol/web3';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import type { NetworkParamsQuery } from '@vegaprotocol/web3';
|
||||
|
||||
export const mockPubkey = '0x123';
|
||||
const mockKeypair = {
|
||||
pub: mockPubkey,
|
||||
} as VegaKeyExtended;
|
||||
|
||||
export const mockWalletContext = {
|
||||
keypair: mockKeypair,
|
||||
keypairs: [mockKeypair],
|
||||
pubKey: mockPubkey,
|
||||
pubKeys: [mockPubkey],
|
||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
||||
connect: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
selectPublicKey: jest.fn(),
|
||||
selectPubKey: jest.fn(),
|
||||
connector: null,
|
||||
};
|
||||
|
||||
|
@ -66,11 +66,11 @@ export const REWARDS_QUERY = gql`
|
||||
|
||||
export const RewardsIndex = () => {
|
||||
const { t } = useTranslation();
|
||||
const { keypair, keypairs } = useVegaWallet();
|
||||
const { pubKey, pubKeys } = useVegaWallet();
|
||||
const { appDispatch } = useAppState();
|
||||
const { data, loading, error } = useQuery<Rewards>(REWARDS_QUERY, {
|
||||
variables: { partyId: keypair?.pub },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey },
|
||||
skip: !pubKey,
|
||||
});
|
||||
const { params } = useNetworkParams([
|
||||
NetworkParams.reward_asset,
|
||||
@ -137,9 +137,9 @@ export const RewardsIndex = () => {
|
||||
</section>
|
||||
)}
|
||||
<section>
|
||||
{keypair && keypairs?.length ? (
|
||||
{pubKey && pubKeys?.length ? (
|
||||
<RewardInfo
|
||||
currVegaKey={keypair}
|
||||
currVegaKey={pubKey}
|
||||
data={data}
|
||||
rewardAssetId={params.reward_asset}
|
||||
/>
|
||||
|
@ -11,11 +11,10 @@ import type {
|
||||
Rewards_party_delegations,
|
||||
Rewards_party_rewardDetails_rewards,
|
||||
} from './__generated__/Rewards';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
|
||||
interface RewardInfoProps {
|
||||
data: Rewards | undefined;
|
||||
currVegaKey: VegaKeyExtended;
|
||||
currVegaKey: string;
|
||||
rewardAssetId: string;
|
||||
}
|
||||
|
||||
@ -61,7 +60,7 @@ export const RewardInfo = ({
|
||||
return (
|
||||
<div>
|
||||
<p>
|
||||
{t('Connected Vega key')}: {currVegaKey.pub}
|
||||
{t('Connected Vega key')}: {currVegaKey}
|
||||
</p>
|
||||
{vegaTokenRewards.length ? (
|
||||
vegaTokenRewards.map((reward, i) => {
|
||||
|
@ -12,11 +12,11 @@ export const AssociateContainer = () => {
|
||||
|
||||
return (
|
||||
<StakingWalletsContainer>
|
||||
{({ address, currVegaKey }) =>
|
||||
currVegaKey ? (
|
||||
{({ address, pubKey }) =>
|
||||
pubKey ? (
|
||||
<AssociatePage
|
||||
address={address}
|
||||
vegaKey={currVegaKey}
|
||||
vegaKey={pubKey}
|
||||
ethereumConfig={config}
|
||||
/>
|
||||
) : (
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { Callout, Intent } from '@vegaprotocol/ui-toolkit';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import type { EthereumConfig } from '@vegaprotocol/web3';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@ -22,7 +21,7 @@ export const AssociatePage = ({
|
||||
ethereumConfig,
|
||||
}: {
|
||||
address: string;
|
||||
vegaKey: VegaKeyExtended;
|
||||
vegaKey: string;
|
||||
ethereumConfig: EthereumConfig;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
@ -46,12 +45,12 @@ export const AssociatePage = ({
|
||||
} = useAddStake(
|
||||
address,
|
||||
amount,
|
||||
vegaKey.pub,
|
||||
vegaKey,
|
||||
selectedStakingMethod,
|
||||
ethereumConfig.confirmations
|
||||
);
|
||||
|
||||
const linking = usePollForStakeLinking(vegaKey.pub, txState.txData.hash);
|
||||
const linking = usePollForStakeLinking(vegaKey, txState.txData.hash);
|
||||
|
||||
const {
|
||||
appState: { walletBalance, totalVestedBalance, totalLockedBalance },
|
||||
@ -81,7 +80,7 @@ export const AssociatePage = ({
|
||||
return (
|
||||
<AssociateTransaction
|
||||
amount={amount}
|
||||
vegaKey={vegaKey.pub}
|
||||
vegaKey={vegaKey}
|
||||
state={txState}
|
||||
dispatch={txDispatch}
|
||||
requiredConfirmations={ethereumConfig.confirmations}
|
||||
|
@ -6,7 +6,6 @@ import { TokenInput } from '../../../components/token-input';
|
||||
import { useAppState } from '../../../contexts/app-state/app-state-context';
|
||||
import { BigNumber } from '../../../lib/bignumber';
|
||||
import { AssociateInfo } from './associate-info';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
|
||||
export const ContractAssociate = ({
|
||||
perform,
|
||||
@ -17,7 +16,7 @@ export const ContractAssociate = ({
|
||||
perform: () => void;
|
||||
amount: string;
|
||||
setAmount: React.Dispatch<React.SetStateAction<string>>;
|
||||
vegaKey: VegaKeyExtended | null;
|
||||
vegaKey: string | null;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const {
|
||||
@ -51,7 +50,7 @@ export const ContractAssociate = ({
|
||||
'You can associate tokens while they are held in the vesting contract, when they unlock you will need to dissociate them before they can be redeemed.'
|
||||
)}
|
||||
</Callout>
|
||||
<AssociateInfo pubKey={vegaKey ? vegaKey.pub : null} />
|
||||
<AssociateInfo pubKey={vegaKey ? vegaKey : null} />
|
||||
<TokenInput
|
||||
submitText={t('Associate VEGA Tokens with key')}
|
||||
perform={perform}
|
||||
|
@ -11,7 +11,6 @@ import { TxState } from '../../../hooks/transaction-reducer';
|
||||
import { useTransaction } from '../../../hooks/use-transaction';
|
||||
import { BigNumber } from '../../../lib/bignumber';
|
||||
import { AssociateInfo } from './associate-info';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { removeDecimal, toBigNum } from '@vegaprotocol/react-helpers';
|
||||
import type { EthereumConfig } from '@vegaprotocol/web3';
|
||||
|
||||
@ -26,7 +25,7 @@ export const WalletAssociate = ({
|
||||
perform: () => void;
|
||||
amount: string;
|
||||
setAmount: React.Dispatch<React.SetStateAction<string>>;
|
||||
vegaKey: VegaKeyExtended;
|
||||
vegaKey: string;
|
||||
address: string;
|
||||
ethereumConfig: EthereumConfig;
|
||||
}) => {
|
||||
@ -100,7 +99,7 @@ export const WalletAssociate = ({
|
||||
} else {
|
||||
pageContent = (
|
||||
<>
|
||||
<AssociateInfo pubKey={vegaKey.pub} />
|
||||
<AssociateInfo pubKey={vegaKey} />
|
||||
<TokenInput
|
||||
approveText={t('Approve VEGA tokens for staking on Vega')}
|
||||
submitText={t('Associate VEGA Tokens with key')}
|
||||
|
@ -4,8 +4,8 @@ import { DisassociatePage } from './disassociate-page';
|
||||
export const DisassociateContainer = () => {
|
||||
return (
|
||||
<StakingWalletsContainer needsEthereum={true} needsVega={false}>
|
||||
{({ address, currVegaKey = null }) => (
|
||||
<DisassociatePage address={address} vegaKey={currVegaKey?.pub ?? ''} />
|
||||
{({ address, pubKey }) => (
|
||||
<DisassociatePage address={address} vegaKey={pubKey ?? ''} />
|
||||
)}
|
||||
</StakingWalletsContainer>
|
||||
);
|
||||
|
@ -11,7 +11,7 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
interface PendingStakeProps {
|
||||
pendingAmount: BigNumber;
|
||||
nodeId: string;
|
||||
pubkey: string;
|
||||
pubKey: string;
|
||||
}
|
||||
|
||||
enum FormState {
|
||||
@ -24,7 +24,7 @@ enum FormState {
|
||||
export const PendingStake = ({
|
||||
pendingAmount,
|
||||
nodeId,
|
||||
pubkey,
|
||||
pubKey,
|
||||
}: PendingStakeProps) => {
|
||||
const { t } = useTranslation();
|
||||
const { sendTx } = useVegaWallet();
|
||||
@ -35,8 +35,6 @@ export const PendingStake = ({
|
||||
setFormState(FormState.Pending);
|
||||
try {
|
||||
const command: UndelegateSubmissionBody = {
|
||||
pubKey: pubkey,
|
||||
propagate: true,
|
||||
undelegateSubmission: {
|
||||
nodeId,
|
||||
amount: removeDecimal(
|
||||
@ -46,7 +44,7 @@ export const PendingStake = ({
|
||||
method: 'METHOD_NOW',
|
||||
},
|
||||
};
|
||||
await sendTx(command);
|
||||
await sendTx(pubKey, command);
|
||||
} catch (err) {
|
||||
setFormState(FormState.Failure);
|
||||
Sentry.captureException(err);
|
||||
|
@ -70,7 +70,7 @@ export enum RemoveType {
|
||||
|
||||
interface StakingFormProps {
|
||||
nodeId: string;
|
||||
pubkey: string;
|
||||
pubKey: string;
|
||||
nodeName: string;
|
||||
availableStakeToAdd: BigNumber;
|
||||
availableStakeToRemove: BigNumber;
|
||||
@ -78,7 +78,7 @@ interface StakingFormProps {
|
||||
|
||||
export const StakingForm = ({
|
||||
nodeId,
|
||||
pubkey,
|
||||
pubKey,
|
||||
nodeName,
|
||||
availableStakeToAdd,
|
||||
availableStakeToRemove,
|
||||
@ -126,16 +126,12 @@ export const StakingForm = ({
|
||||
async function onSubmit() {
|
||||
setFormState(FormState.Requested);
|
||||
const delegateInput: DelegateSubmissionBody = {
|
||||
pubKey: pubkey,
|
||||
propagate: true,
|
||||
delegateSubmission: {
|
||||
nodeId,
|
||||
amount: removeDecimal(new BigNumber(amount), appState.decimals),
|
||||
},
|
||||
};
|
||||
const undelegateInput: UndelegateSubmissionBody = {
|
||||
pubKey: pubkey,
|
||||
propagate: true,
|
||||
undelegateSubmission: {
|
||||
nodeId,
|
||||
amount: removeDecimal(new BigNumber(amount), appState.decimals),
|
||||
@ -147,7 +143,7 @@ export const StakingForm = ({
|
||||
};
|
||||
try {
|
||||
const command = action === Actions.Add ? delegateInput : undelegateInput;
|
||||
const res = await sendTx(command);
|
||||
const res = await sendTx(pubKey, command);
|
||||
if (res) {
|
||||
setFormState(FormState.Pending);
|
||||
} else {
|
||||
@ -171,7 +167,7 @@ export const StakingForm = ({
|
||||
client
|
||||
.query<PartyDelegations, PartyDelegationsVariables>({
|
||||
query: PARTY_DELEGATIONS_QUERY,
|
||||
variables: { partyId: pubkey },
|
||||
variables: { partyId: pubKey },
|
||||
fetchPolicy: 'network-only',
|
||||
})
|
||||
.then((res) => {
|
||||
@ -194,7 +190,7 @@ export const StakingForm = ({
|
||||
}
|
||||
|
||||
return () => clearInterval(interval);
|
||||
}, [formState, client, pubkey, nodeId]);
|
||||
}, [formState, client, pubKey, nodeId]);
|
||||
|
||||
if (formState === FormState.Failure) {
|
||||
return <StakeFailure nodeName={nodeName} />;
|
||||
|
@ -3,7 +3,6 @@ import { useTranslation } from 'react-i18next';
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { EpochCountdown } from '../../components/epoch-countdown';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { BigNumber } from '../../lib/bignumber';
|
||||
import type { Staking as StakingQueryResult } from './__generated__/Staking';
|
||||
import { ConnectToVega } from './connect-to-vega';
|
||||
@ -16,9 +15,9 @@ import { YourStake } from './your-stake';
|
||||
export const StakingNodeContainer = () => {
|
||||
return (
|
||||
<StakingWalletsContainer>
|
||||
{({ currVegaKey }) => (
|
||||
{({ pubKey }) => (
|
||||
<StakingNodesContainer>
|
||||
{({ data }) => <StakingNode vegaKey={currVegaKey} data={data} />}
|
||||
{({ data }) => <StakingNode pubKey={pubKey} data={data} />}
|
||||
</StakingNodesContainer>
|
||||
)}
|
||||
</StakingWalletsContainer>
|
||||
@ -26,11 +25,11 @@ export const StakingNodeContainer = () => {
|
||||
};
|
||||
|
||||
interface StakingNodeProps {
|
||||
vegaKey: VegaKeyExtended | null;
|
||||
pubKey: string;
|
||||
data?: StakingQueryResult;
|
||||
}
|
||||
|
||||
export const StakingNode = ({ vegaKey, data }: StakingNodeProps) => {
|
||||
export const StakingNode = ({ pubKey: vegaKey, data }: StakingNodeProps) => {
|
||||
const { node } = useParams<{ node: string }>();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@ -113,7 +112,6 @@ export const StakingNode = ({ vegaKey, data }: StakingNodeProps) => {
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
|
||||
{vegaKey ? (
|
||||
<>
|
||||
<section className="mb-4">
|
||||
@ -125,7 +123,7 @@ export const StakingNode = ({ vegaKey, data }: StakingNodeProps) => {
|
||||
|
||||
<section>
|
||||
<StakingForm
|
||||
pubkey={vegaKey.pub}
|
||||
pubKey={vegaKey}
|
||||
nodeId={nodeInfo.id}
|
||||
nodeName={nodeInfo.name}
|
||||
availableStakeToAdd={unstaked}
|
||||
|
@ -80,11 +80,12 @@ export const StakingNodesContainer = ({
|
||||
children: ({ data }: { data?: StakingQueryResult }) => React.ReactElement;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data, loading, error, refetch } = useQuery<StakingQueryResult>(
|
||||
STAKING_QUERY,
|
||||
{
|
||||
variables: { partyId: keypair?.pub || '' },
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -2,7 +2,6 @@ import { useWeb3React } from '@web3-react/core';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import { EthConnectPrompt } from '../../components/eth-connect-prompt';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { ConnectToVega } from './connect-to-vega';
|
||||
|
||||
@ -13,14 +12,11 @@ export const StakingWalletsContainer = ({
|
||||
}: {
|
||||
needsEthereum?: boolean;
|
||||
needsVega?: boolean;
|
||||
children: (data: {
|
||||
address: string;
|
||||
currVegaKey: VegaKeyExtended | null;
|
||||
}) => React.ReactElement;
|
||||
children: (data: { address: string; pubKey: string }) => React.ReactElement;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const { account } = useWeb3React();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
if (!account && needsEthereum) {
|
||||
return (
|
||||
@ -31,7 +27,7 @@ export const StakingWalletsContainer = ({
|
||||
);
|
||||
}
|
||||
|
||||
if (!keypair && needsVega) {
|
||||
if (!pubKey || needsVega) {
|
||||
return (
|
||||
<>
|
||||
<EthConnectPrompt>
|
||||
@ -43,5 +39,5 @@ export const StakingWalletsContainer = ({
|
||||
);
|
||||
}
|
||||
|
||||
return children({ address: account || '', currVegaKey: keypair });
|
||||
return children({ address: account || '', pubKey });
|
||||
};
|
||||
|
@ -1,3 +1,3 @@
|
||||
NX_USE_ENV_OVERRIDES=0
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
CYPRESS_VEGA_URL=https://api.n07.testnet.vega.xyz/graphql
|
@ -1,5 +1,5 @@
|
||||
import { connectVegaWallet } from '../support/vega-wallet';
|
||||
import { aliasQuery } from '@vegaprotocol/cypress';
|
||||
import { connectVegaWallet } from '../support/vega-wallet';
|
||||
import { generateNetworkParameters } from '../support/mocks/generate-network-parameters';
|
||||
|
||||
describe('vega wallet', { tags: '@smoke' }, () => {
|
||||
@ -12,14 +12,24 @@ describe('vega wallet', { tags: '@smoke' }, () => {
|
||||
beforeEach(() => {
|
||||
// Using portfolio page as it requires vega wallet connection
|
||||
cy.visit('/portfolio');
|
||||
cy.mockGQL((req) => {
|
||||
aliasQuery(req, 'ChainId', {
|
||||
statistics: { __typename: 'Statistics', chainId: 'test-chain-id' },
|
||||
});
|
||||
});
|
||||
cy.mockGQLSubscription();
|
||||
cy.get('main[data-testid="portfolio"]').should('exist');
|
||||
});
|
||||
|
||||
it('can connect', () => {
|
||||
cy.getByTestId(connectVegaBtn).click();
|
||||
cy.contains('Connects using REST to a running Vega wallet service');
|
||||
cy.getByTestId('connectors-list').find('button').click();
|
||||
cy.contains('Desktop wallet app');
|
||||
cy.contains('Command line wallet app');
|
||||
cy.contains('Hosted Fairground wallet');
|
||||
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-gui"]')
|
||||
.click();
|
||||
cy.getByTestId(form).find('#wallet').click().type(walletName);
|
||||
cy.getByTestId(form).find('#passphrase').click().type(walletPassphrase);
|
||||
cy.getByTestId('rest-connector-form').find('button[type=submit]').click();
|
||||
@ -28,7 +38,9 @@ describe('vega wallet', { tags: '@smoke' }, () => {
|
||||
|
||||
it('doesnt connect with invalid credentials', () => {
|
||||
cy.getByTestId(connectVegaBtn).click();
|
||||
cy.getByTestId('connectors-list').find('button').click();
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-gui"]')
|
||||
.click();
|
||||
cy.getByTestId(form).find('#wallet').click().type('invalid name');
|
||||
cy.getByTestId(form).find('#passphrase').click().type('invalid password');
|
||||
cy.getByTestId('rest-connector-form').find('button[type=submit]').click();
|
||||
@ -37,7 +49,10 @@ describe('vega wallet', { tags: '@smoke' }, () => {
|
||||
|
||||
it('doesnt connect with invalid fields', () => {
|
||||
cy.getByTestId(connectVegaBtn).click();
|
||||
cy.getByTestId('connectors-list').find('button').click();
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-gui"]')
|
||||
.click();
|
||||
|
||||
cy.getByTestId('rest-connector-form').find('button[type=submit]').click();
|
||||
cy.getByTestId(form)
|
||||
.find('#wallet')
|
||||
|
@ -1,4 +1,14 @@
|
||||
import '@vegaprotocol/cypress';
|
||||
import 'cypress-real-events/support';
|
||||
import registerCypressGrep from 'cypress-grep';
|
||||
import { aliasQuery } from '@vegaprotocol/cypress';
|
||||
registerCypressGrep();
|
||||
|
||||
beforeEach(() => {
|
||||
// Mock chainId fetch which happens on every page for wallet connection
|
||||
cy.mockGQL((req) => {
|
||||
aliasQuery(req, 'ChainId', {
|
||||
statistics: { __typename: 'Statistics', chainId: 'test-chain-id' },
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,9 @@ export const connectVegaWallet = () => {
|
||||
const walletName = Cypress.env('TRADING_TEST_VEGA_WALLET_NAME');
|
||||
const walletPassphrase = Cypress.env('TRADING_TEST_VEGA_WALLET_PASSPHRASE');
|
||||
cy.getByTestId('connect-vega-wallet').click();
|
||||
cy.getByTestId('connectors-list').find('button').click();
|
||||
cy.getByTestId('connectors-list')
|
||||
.find('[data-testid="connector-gui"]')
|
||||
.click();
|
||||
cy.getByTestId(form).find('#wallet').click().type(walletName);
|
||||
cy.getByTestId(form).find('#passphrase').click().type(walletPassphrase);
|
||||
cy.getByTestId('rest-connector-form').find('button[type=submit]').click();
|
||||
|
@ -7,4 +7,5 @@ NX_VEGA_NETWORKS={\"MAINNET\":\"https://alpha.console.vega.xyz\"}
|
||||
NX_USE_ENV_OVERRIDES=1
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
NX_VEGA_TOKEN_URL=https://token.fairground.wtf
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
||||
|
@ -7,4 +7,5 @@ NX_ETHERSCAN_URL=https://ropsten.etherscan.io
|
||||
NX_USE_ENV_OVERRIDES=1
|
||||
NX_VEGA_EXPLORER_URL=https://explorer.fairground.wtf
|
||||
NX_VEGA_TOKEN_URL=https://token.fairground.wtf
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789/api/v1
|
||||
NX_VEGA_WALLET_URL=http://localhost:1789
|
||||
NX_HOSTED_WALLET_URL=https://wallet.testnet.vega.xyz
|
@ -25,7 +25,7 @@ const generateJsx = (
|
||||
};
|
||||
|
||||
it('Not connected', () => {
|
||||
render(generateJsx({ keypair: null } as VegaWalletContextShape, props));
|
||||
render(generateJsx({ pubKey: null } as VegaWalletContextShape, props));
|
||||
|
||||
const button = screen.getByRole('button');
|
||||
expect(button).toHaveTextContent('Connect Vega wallet');
|
||||
@ -34,18 +34,16 @@ it('Not connected', () => {
|
||||
});
|
||||
|
||||
it('Connected', () => {
|
||||
const keypair = { pub: '123456__123456', name: 'test' };
|
||||
const pubKey = { publicKey: '123456__123456', name: 'test' };
|
||||
render(
|
||||
generateJsx(
|
||||
{ keypair, keypairs: [keypair] } as VegaWalletContextShape,
|
||||
{ pubKey: pubKey.publicKey, pubKeys: [pubKey] } as VegaWalletContextShape,
|
||||
props
|
||||
)
|
||||
);
|
||||
|
||||
const button = screen.getByRole('button');
|
||||
expect(button).toHaveTextContent(
|
||||
`${keypair.name}: ${truncateByChars(keypair.pub)}`
|
||||
);
|
||||
expect(button).toHaveTextContent(truncateByChars(pubKey.publicKey));
|
||||
fireEvent.click(button);
|
||||
expect(props.setConnectDialog).not.toHaveBeenCalled();
|
||||
});
|
||||
|
@ -10,9 +10,8 @@ import {
|
||||
DropdownMenuTrigger,
|
||||
Icon,
|
||||
} from '@vegaprotocol/ui-toolkit';
|
||||
import type { VegaKeyExtended } from '@vegaprotocol/wallet';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import CopyToClipboard from 'react-copy-to-clipboard';
|
||||
|
||||
export interface VegaWalletConnectButtonProps {
|
||||
@ -23,29 +22,34 @@ export const VegaWalletConnectButton = ({
|
||||
setConnectDialog,
|
||||
}: VegaWalletConnectButtonProps) => {
|
||||
const [dropdownOpen, setDropdownOpen] = useState(false);
|
||||
const { keypair, keypairs, selectPublicKey, disconnect } = useVegaWallet();
|
||||
const isConnected = keypair !== null;
|
||||
const { pubKey, pubKeys, selectPubKey, disconnect } = useVegaWallet();
|
||||
const isConnected = pubKey !== null;
|
||||
|
||||
if (isConnected && keypairs) {
|
||||
const activeKey = useMemo(() => {
|
||||
return pubKeys?.find((pk) => pk.publicKey === pubKey);
|
||||
}, [pubKey, pubKeys]);
|
||||
|
||||
if (isConnected && pubKeys) {
|
||||
return (
|
||||
<DropdownMenu open={dropdownOpen}>
|
||||
<DropdownMenuTrigger
|
||||
data-testid="manage-vega-wallet"
|
||||
onClick={() => setDropdownOpen((curr) => !curr)}
|
||||
>
|
||||
<span className="uppercase">{keypair.name}</span>:{' '}
|
||||
{truncateByChars(keypair.pub)}
|
||||
{activeKey && <span className="uppercase">{activeKey.name}</span>}
|
||||
{': '}
|
||||
{truncateByChars(pubKey)}
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent onInteractOutside={() => setDropdownOpen(false)}>
|
||||
<div className="min-w-[340px]" data-testid="keypair-list">
|
||||
<DropdownMenuRadioGroup
|
||||
value={keypair.pub}
|
||||
value={pubKey}
|
||||
onValueChange={(value) => {
|
||||
selectPublicKey(value);
|
||||
selectPubKey(value);
|
||||
}}
|
||||
>
|
||||
{keypairs.map((kp) => (
|
||||
<KeypairItem key={kp.pub} kp={kp} />
|
||||
{pubKeys.map((k) => (
|
||||
<KeypairItem key={k.publicKey} kp={k.publicKey} />
|
||||
))}
|
||||
</DropdownMenuRadioGroup>
|
||||
<DropdownMenuItem data-testid="disconnect" onClick={disconnect}>
|
||||
@ -68,7 +72,7 @@ export const VegaWalletConnectButton = ({
|
||||
);
|
||||
};
|
||||
|
||||
const KeypairItem = ({ kp }: { kp: VegaKeyExtended }) => {
|
||||
const KeypairItem = ({ kp }: { kp: string }) => {
|
||||
const [copied, setCopied] = useState(false);
|
||||
useEffect(() => {
|
||||
// eslint-disable-next-line
|
||||
@ -86,14 +90,13 @@ const KeypairItem = ({ kp }: { kp: VegaKeyExtended }) => {
|
||||
}, [copied]);
|
||||
|
||||
return (
|
||||
<DropdownMenuRadioItem key={kp.pub} value={kp.pub}>
|
||||
<div className="flex-1 mr-2" data-testid={`key-${kp.pub}`}>
|
||||
<DropdownMenuRadioItem key={kp} value={kp}>
|
||||
<div className="flex-1 mr-2" data-testid={`key-${kp}`}>
|
||||
<span className="mr-2">
|
||||
<span className="uppercase">{kp.name}</span>:{' '}
|
||||
<span>{truncateByChars(kp.pub)}</span>
|
||||
<span>{truncateByChars(kp)}</span>
|
||||
</span>
|
||||
<span>
|
||||
<CopyToClipboard text={kp.pub} onCopy={() => setCopied(true)}>
|
||||
<CopyToClipboard text={kp} onCopy={() => setCopied(true)}>
|
||||
<button
|
||||
data-testid="copy-vega-public-key"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
|
@ -16,12 +16,12 @@ const generateJsx = (context: PartialDeep<VegaWalletContextShape>) => {
|
||||
|
||||
describe('VegaWalletContainer', () => {
|
||||
it('doesnt render children if not connected', () => {
|
||||
render(generateJsx({ keypair: null }));
|
||||
render(generateJsx({ pubKey: null }));
|
||||
expect(screen.queryByTestId('child')).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders children if connected', () => {
|
||||
render(generateJsx({ keypair: { pub: '0x123' } }));
|
||||
render(generateJsx({ pubKey: '0x123' }));
|
||||
expect(screen.getByTestId('child')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
@ -10,9 +10,9 @@ interface VegaWalletContainerProps {
|
||||
|
||||
export const VegaWalletContainer = ({ children }: VegaWalletContainerProps) => {
|
||||
const { update } = useGlobalStore((store) => ({ update: store.update }));
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<Splash>
|
||||
<div className="text-center">
|
||||
|
@ -1,7 +1,9 @@
|
||||
import { RestConnector } from '@vegaprotocol/wallet';
|
||||
import { RestConnector, JsonRpcConnector } from '@vegaprotocol/wallet';
|
||||
|
||||
export const rest = new RestConnector();
|
||||
export const jsonRpc = new JsonRpcConnector();
|
||||
|
||||
export const Connectors = {
|
||||
rest,
|
||||
jsonRpc,
|
||||
};
|
||||
|
@ -17,10 +17,9 @@ import Link from 'next/link';
|
||||
|
||||
const LiquidityPage = ({ id }: { id?: string }) => {
|
||||
const { query } = useRouter();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const gridRef = useRef<AgGridReact | null>(null);
|
||||
|
||||
const partyId = keypair?.pub;
|
||||
// Default to first marketId query item if found
|
||||
const marketId =
|
||||
id || (Array.isArray(query.marketId) ? query.marketId[0] : query.marketId);
|
||||
@ -39,8 +38,8 @@ const LiquidityPage = ({ id }: { id?: string }) => {
|
||||
} = useLiquidityProvision({ marketId });
|
||||
|
||||
const myLpEdges = useMemo(
|
||||
() => liquidityProviders.filter((e) => e.party === partyId),
|
||||
[liquidityProviders, partyId]
|
||||
() => liquidityProviders.filter((e) => e.party === pubKey),
|
||||
[liquidityProviders, pubKey]
|
||||
);
|
||||
const activeEdges = useMemo(
|
||||
() =>
|
||||
@ -116,7 +115,7 @@ const LiquidityPage = ({ id }: { id?: string }) => {
|
||||
<Tab
|
||||
id={LiquidityTabs.MyLiquidityProvision}
|
||||
name={t('My liquidity provision')}
|
||||
hidden={!partyId}
|
||||
hidden={!pubKey}
|
||||
>
|
||||
<LiquidityTable
|
||||
ref={gridRef}
|
||||
|
@ -10,10 +10,10 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { AccountManager } from '@vegaprotocol/accounts';
|
||||
|
||||
export const AccountsContainer = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [depositDialog, setDepositDialog] = useState(false);
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<Splash>
|
||||
<p>{t('Please connect Vega wallet')}</p>
|
||||
@ -24,7 +24,7 @@ export const AccountsContainer = () => {
|
||||
return (
|
||||
<Web3Container>
|
||||
<div className="h-full">
|
||||
<AssetAccountTable partyId={keypair.pub} />
|
||||
<AssetAccountTable partyId={pubKey} />
|
||||
<DepositDialog
|
||||
depositDialog={depositDialog}
|
||||
setDepositDialog={setDepositDialog}
|
||||
|
@ -45,7 +45,7 @@ export const CandlesChartContainer = ({
|
||||
marketId,
|
||||
}: CandlesChartContainerProps) => {
|
||||
const client = useApolloClient();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const theme = useContext(ThemeContext);
|
||||
|
||||
const [interval, setInterval] = useState<Interval>(Interval.I15M);
|
||||
@ -54,8 +54,8 @@ export const CandlesChartContainer = ({
|
||||
const [studies, setStudies] = useState<Study[]>([]);
|
||||
|
||||
const dataSource = useMemo(() => {
|
||||
return new VegaDataSource(client, marketId, keypair?.pub);
|
||||
}, [client, marketId, keypair]);
|
||||
return new VegaDataSource(client, marketId, pubKey);
|
||||
}, [client, marketId, pubKey]);
|
||||
|
||||
return (
|
||||
<div className="h-full flex flex-col">
|
||||
|
@ -1,5 +1,5 @@
|
||||
import merge from 'lodash/merge';
|
||||
import type { TransactionResponse } from '@vegaprotocol/wallet';
|
||||
import type { V1TransactionResponse } from '@vegaprotocol/wallet';
|
||||
import type { PartialDeep } from 'type-fest';
|
||||
|
||||
declare global {
|
||||
@ -7,7 +7,7 @@ declare global {
|
||||
namespace Cypress {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
interface Chainable<Subject> {
|
||||
mockVegaCommandSync(override: PartialDeep<TransactionResponse>): void;
|
||||
mockVegaCommandSync(override: PartialDeep<V1TransactionResponse>): void;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -15,9 +15,8 @@ declare global {
|
||||
export function addMockVegaWalletCommands() {
|
||||
Cypress.Commands.add(
|
||||
'mockVegaCommandSync',
|
||||
(override?: PartialDeep<TransactionResponse>) => {
|
||||
(override?: PartialDeep<V1TransactionResponse>) => {
|
||||
const defaultTransactionResponse = {
|
||||
txId: 'tx-id',
|
||||
txHash: 'tx-hash',
|
||||
sentAt: new Date().toISOString(),
|
||||
receivedAt: new Date().toISOString(),
|
||||
|
@ -1,9 +1,6 @@
|
||||
import { renderHook } from '@testing-library/react';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import type {
|
||||
VegaWalletContextShape,
|
||||
VegaKeyExtended,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import {
|
||||
MarketState,
|
||||
MarketStateMapping,
|
||||
@ -44,16 +41,12 @@ const market = {
|
||||
};
|
||||
|
||||
const defaultWalletContext = {
|
||||
keypair: {
|
||||
name: 'keypair0',
|
||||
tainted: false,
|
||||
pub: '111111__111111',
|
||||
} as VegaKeyExtended,
|
||||
keypairs: [],
|
||||
pubKey: '111111__111111',
|
||||
pubKeys: [],
|
||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
||||
connect: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
selectPublicKey: jest.fn(),
|
||||
selectPubKey: jest.fn(),
|
||||
connector: null,
|
||||
};
|
||||
|
||||
@ -98,14 +91,7 @@ describe('useOrderValidation', () => {
|
||||
});
|
||||
|
||||
it('Returns an error message when no keypair found', () => {
|
||||
const { result } = setup(defaultOrder, { keypair: null });
|
||||
expect(result.current).toStrictEqual({ isDisabled: false, message: `` });
|
||||
});
|
||||
|
||||
it('Returns an error message when the keypair is tainted', () => {
|
||||
const { result } = setup(defaultOrder, {
|
||||
keypair: { ...defaultWalletContext.keypair, tainted: true },
|
||||
});
|
||||
const { result } = setup(defaultOrder, { pubKey: null });
|
||||
expect(result.current).toStrictEqual({ isDisabled: false, message: `` });
|
||||
});
|
||||
|
||||
|
@ -51,21 +51,14 @@ export const useOrderValidation = ({
|
||||
message: React.ReactNode | string;
|
||||
isDisabled: boolean;
|
||||
} => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const minSize = toDecimal(market.positionDecimalPlaces);
|
||||
|
||||
const { message, isDisabled } = useMemo(() => {
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return { message: t('No public key selected'), isDisabled: true };
|
||||
}
|
||||
|
||||
if (keypair.tainted) {
|
||||
return {
|
||||
isDisabled: true,
|
||||
message: t('Selected public key has been tainted'),
|
||||
};
|
||||
}
|
||||
|
||||
if (
|
||||
[
|
||||
MarketState.STATE_SETTLED,
|
||||
@ -292,7 +285,7 @@ export const useOrderValidation = ({
|
||||
return { isDisabled: false, message: '' };
|
||||
}, [
|
||||
minSize,
|
||||
keypair,
|
||||
pubKey,
|
||||
market,
|
||||
fieldErrors?.size?.type,
|
||||
fieldErrors?.size?.message,
|
||||
|
@ -33,11 +33,11 @@ const DEPOSITS_QUERY = gql`
|
||||
*/
|
||||
export const DepositContainer = ({ assetId }: { assetId?: string }) => {
|
||||
const { VEGA_ENV } = useEnvironment();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const { data, loading, error } = useQuery<DepositAsset>(DEPOSITS_QUERY, {
|
||||
variables: { partyId: keypair?.pub },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey },
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
const assets = getEnabledAssets(data);
|
||||
|
@ -43,7 +43,7 @@ beforeEach(() => {
|
||||
isFaucetable: true,
|
||||
};
|
||||
|
||||
(useVegaWallet as jest.Mock).mockReturnValue({ keypair: null });
|
||||
(useVegaWallet as jest.Mock).mockReturnValue({ pubKey: null });
|
||||
(useWeb3React as jest.Mock).mockReturnValue({ account: MOCK_ETH_ADDRESS });
|
||||
});
|
||||
|
||||
@ -180,7 +180,7 @@ describe('Deposit form', () => {
|
||||
|
||||
it('handles deposit approvals', () => {
|
||||
const mockUseVegaWallet = useVegaWallet as jest.Mock;
|
||||
mockUseVegaWallet.mockReturnValue({ keypair: null });
|
||||
mockUseVegaWallet.mockReturnValue({ pubKey: null });
|
||||
|
||||
const mockUseWeb3React = useWeb3React as jest.Mock;
|
||||
mockUseWeb3React.mockReturnValue({ account: undefined });
|
||||
@ -203,10 +203,10 @@ describe('Deposit form', () => {
|
||||
});
|
||||
|
||||
it('handles submitting a deposit', async () => {
|
||||
const vegaKey =
|
||||
const pubKey =
|
||||
'f8885edfa7ffdb6ed996ca912e9258998e47bf3515c885cf3c63fb56b15de36f';
|
||||
const mockUseVegaWallet = useVegaWallet as jest.Mock;
|
||||
mockUseVegaWallet.mockReturnValue({ keypair: { pub: vegaKey } });
|
||||
mockUseVegaWallet.mockReturnValue({ pubKey });
|
||||
|
||||
const account = '0x72c22822A19D20DE7e426fB84aa047399Ddd8853';
|
||||
const mockUseWeb3React = useWeb3React as jest.Mock;
|
||||
@ -255,10 +255,11 @@ describe('Deposit form', () => {
|
||||
// @ts-ignore contract address definitely defined
|
||||
assetSource: asset.source.contractAddress,
|
||||
amount: '8',
|
||||
vegaPublicKey: vegaKey,
|
||||
vegaPublicKey: pubKey,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('shows "View asset details" button when an asset is selected', async () => {
|
||||
render(<DepositForm {...props} selectedAsset={asset} />);
|
||||
expect(await screen.getByTestId('view-asset-details')).toBeInTheDocument();
|
||||
|
@ -67,7 +67,7 @@ export const DepositForm = ({
|
||||
}: DepositFormProps) => {
|
||||
const { open: openAssetDetailsDialog } = useAssetDetailsDialogStore();
|
||||
const { account } = useWeb3React();
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const {
|
||||
register,
|
||||
handleSubmit,
|
||||
@ -78,7 +78,7 @@ export const DepositForm = ({
|
||||
} = useForm<FormFields>({
|
||||
defaultValues: {
|
||||
from: account,
|
||||
to: keypair?.pub,
|
||||
to: pubKey ? pubKey : undefined,
|
||||
asset: selectedAsset?.id || '',
|
||||
},
|
||||
});
|
||||
@ -207,10 +207,10 @@ export const DepositForm = ({
|
||||
{errors.to.message}
|
||||
</InputError>
|
||||
)}
|
||||
{keypair?.pub && (
|
||||
{pubKey && (
|
||||
<UseButton
|
||||
onClick={() => {
|
||||
setValue('to', keypair.pub);
|
||||
setValue('to', pubKey);
|
||||
clearErrors('to');
|
||||
}}
|
||||
>
|
||||
|
@ -17,10 +17,10 @@ import type {
|
||||
} from './__generated__/Deposit';
|
||||
|
||||
export const useDeposits = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const { data, loading, error, subscribeToMore } = useDepositsQuery({
|
||||
variables: { partyId: keypair?.pub || '' },
|
||||
skip: !keypair?.pub,
|
||||
variables: { partyId: pubKey || '' },
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
const deposits = useMemo(() => {
|
||||
@ -36,21 +36,21 @@ export const useDeposits = () => {
|
||||
}, [data]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!keypair?.pub) return;
|
||||
if (!pubKey) return;
|
||||
|
||||
const unsub = subscribeToMore<
|
||||
DepositEventSubscription,
|
||||
DepositEventSubscriptionVariables
|
||||
>({
|
||||
document: DepositEventDocument,
|
||||
variables: { partyId: keypair?.pub },
|
||||
variables: { partyId: pubKey },
|
||||
updateQuery,
|
||||
});
|
||||
|
||||
return () => {
|
||||
unsub();
|
||||
};
|
||||
}, [keypair?.pub, subscribeToMore]);
|
||||
}, [pubKey, subscribeToMore]);
|
||||
|
||||
return { data, loading, error, deposits };
|
||||
};
|
||||
|
@ -74,6 +74,8 @@ const getBundledEnvironmentValue = (key: EnvKey) => {
|
||||
return process.env['NX_VEGA_TOKEN_URL'];
|
||||
case 'VEGA_DOCS_URL':
|
||||
return process.env['NX_VEGA_DOCS_URL'];
|
||||
case 'HOSTED_WALLET_URL':
|
||||
return process.env['NX_HOSTED_WALLET_URL'];
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -45,6 +45,7 @@ const schemaObject = {
|
||||
ETHERSCAN_URL: z.string().url({
|
||||
message: 'The NX_ETHERSCAN_URL environment variable must be a valid url',
|
||||
}),
|
||||
HOSTED_WALLET_URL: z.optional(z.string()),
|
||||
};
|
||||
|
||||
export const ENV_KEYS = Object.keys(schemaObject) as Array<
|
||||
|
@ -4,9 +4,9 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { FillsManager } from './fills-manager';
|
||||
|
||||
export const FillsContainer = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<Splash>
|
||||
<p>{t('Please connect Vega wallet')}</p>
|
||||
@ -14,5 +14,5 @@ export const FillsContainer = () => {
|
||||
);
|
||||
}
|
||||
|
||||
return <FillsManager partyId={keypair.pub} />;
|
||||
return <FillsManager partyId={pubKey} />;
|
||||
};
|
||||
|
@ -1,13 +1,16 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useVegaWallet, useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import { determineId } from '@vegaprotocol/react-helpers';
|
||||
import {
|
||||
useVegaWallet,
|
||||
useVegaTransaction,
|
||||
determineId,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import { useProposalEvent } from './use-proposal-event';
|
||||
import type { ProposalSubmission } from '@vegaprotocol/wallet';
|
||||
import type { ProposalEvent_busEvents_event_Proposal } from './__generated__/ProposalEvent';
|
||||
|
||||
export const useProposalSubmit = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const { send, transaction, setComplete, Dialog } = useVegaTransaction();
|
||||
const waitForProposalEvent = useProposalEvent(transaction);
|
||||
@ -17,35 +20,31 @@ export const useProposalSubmit = () => {
|
||||
|
||||
const submit = useCallback(
|
||||
async (proposal: ProposalSubmission) => {
|
||||
if (!keypair || !proposal) {
|
||||
if (!pubKey || !proposal) {
|
||||
return;
|
||||
}
|
||||
|
||||
setFinalizedProposal(null);
|
||||
|
||||
try {
|
||||
const res = await send({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
const res = await send(pubKey, {
|
||||
proposalSubmission: proposal,
|
||||
});
|
||||
|
||||
if (res?.signature) {
|
||||
const resId = determineId(res.signature);
|
||||
if (resId) {
|
||||
waitForProposalEvent(resId, keypair.pub, (p) => {
|
||||
if (res) {
|
||||
const proposalId = determineId(res.signature);
|
||||
if (proposalId) {
|
||||
waitForProposalEvent(proposalId, pubKey, (p) => {
|
||||
setFinalizedProposal(p);
|
||||
setComplete();
|
||||
});
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} catch (e) {
|
||||
Sentry.captureException(e);
|
||||
return;
|
||||
}
|
||||
},
|
||||
[keypair, send, setComplete, waitForProposalEvent]
|
||||
[pubKey, send, setComplete, waitForProposalEvent]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -121,15 +121,15 @@ export const SelectMarketPopover = ({
|
||||
}) => {
|
||||
const triggerClasses =
|
||||
'sm:text-lg md:text-xl lg:text-2xl flex items-center gap-2 whitespace-nowrap hover:text-neutral-500 dark:hover:text-neutral-300';
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
const [open, setOpen] = useState(false);
|
||||
const { data, loading: marketsLoading } = useMarketList();
|
||||
const variables = useMemo(() => ({ partyId: keypair?.pub }), [keypair?.pub]);
|
||||
const variables = useMemo(() => ({ partyId: pubKey }), [pubKey]);
|
||||
const { data: party, loading: positionsLoading } = useDataProvider({
|
||||
dataProvider: positionsDataProvider,
|
||||
noUpdate: true,
|
||||
variables,
|
||||
skip: !keypair,
|
||||
skip: !pubKey,
|
||||
});
|
||||
|
||||
const onSelectMarket = (marketId: string) => {
|
||||
@ -163,14 +163,14 @@ export const SelectMarketPopover = ({
|
||||
className="w-[90vw] max-h-[80vh] overflow-y-auto"
|
||||
data-testid="select-market-list"
|
||||
>
|
||||
{marketsLoading || (keypair?.pub && positionsLoading) ? (
|
||||
{marketsLoading || (pubKey && positionsLoading) ? (
|
||||
<div className="flex items-center gap-4">
|
||||
<Loader size="small" />
|
||||
Loading market data
|
||||
</div>
|
||||
) : (
|
||||
<table className="relative text-sm w-full whitespace-nowrap">
|
||||
{keypair && (party?.positionsConnection?.edges?.length ?? 0) > 0 ? (
|
||||
{pubKey && (party?.positionsConnection?.edges?.length ?? 0) > 0 ? (
|
||||
<>
|
||||
<TableTitle>{t('My markets')}</TableTitle>
|
||||
<SelectAllMarketsTableBody
|
||||
|
@ -4,11 +4,11 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { OrderListManager } from './order-list-manager';
|
||||
|
||||
export const OrderListContainer = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return <Splash>{t('Please connect Vega wallet')}</Splash>;
|
||||
}
|
||||
|
||||
return <OrderListManager partyId={keypair.pub} />;
|
||||
return <OrderListManager partyId={pubKey} />;
|
||||
};
|
||||
|
@ -3,21 +3,25 @@ import { MockedProvider } from '@apollo/client/testing';
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import type { ReactNode } from 'react';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import type {
|
||||
VegaKeyExtended,
|
||||
VegaWalletContextShape,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { useOrderCancel } from './use-order-cancel';
|
||||
import type { OrderEvent, OrderEvent_busEvents } from './';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import {
|
||||
BusEventType,
|
||||
OrderStatus,
|
||||
OrderTimeInForce,
|
||||
OrderType,
|
||||
Side,
|
||||
} from '@vegaprotocol/types';
|
||||
|
||||
const defaultWalletContext = {
|
||||
keypair: null,
|
||||
keypairs: [],
|
||||
pubKey: null,
|
||||
pubKeys: [],
|
||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
||||
connect: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
selectPublicKey: jest.fn(),
|
||||
selectPubKey: jest.fn(),
|
||||
connector: null,
|
||||
};
|
||||
|
||||
@ -26,33 +30,42 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: 'Limit',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: 'Active',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: 'GTC',
|
||||
side: 'Buy',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -61,33 +74,42 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: 'Limit',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: 'Active',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: 'GTC',
|
||||
side: 'Buy',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -120,8 +142,8 @@ describe('useOrderCancel', () => {
|
||||
const mockSendTx = jest.fn();
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [],
|
||||
keypair: null,
|
||||
pubKeys: [],
|
||||
pubKey: null,
|
||||
});
|
||||
act(() => {
|
||||
result.current.cancel({ orderId: 'order-id', marketId: 'market-id' });
|
||||
@ -131,13 +153,11 @@ describe('useOrderCancel', () => {
|
||||
|
||||
it('should cancel a correctly formatted order', async () => {
|
||||
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
const keypair = {
|
||||
pub: '0x123',
|
||||
} as VegaKeyExtended;
|
||||
const pubKeyObj = { publicKey: '0x123', name: 'test key 1' };
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [keypair],
|
||||
keypair,
|
||||
pubKeys: [pubKeyObj],
|
||||
pubKey: pubKeyObj.publicKey,
|
||||
});
|
||||
|
||||
const args = {
|
||||
@ -148,9 +168,7 @@ describe('useOrderCancel', () => {
|
||||
result.current.cancel(args);
|
||||
});
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
expect(mockSendTx).toHaveBeenCalledWith(pubKeyObj.publicKey, {
|
||||
orderCancellation: args,
|
||||
});
|
||||
});
|
||||
|
@ -10,7 +10,7 @@ export interface CancelOrderArgs {
|
||||
}
|
||||
|
||||
export const useOrderCancel = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const [cancelledOrder, setCancelledOrder] =
|
||||
useState<OrderEvent_busEvents_event_Order | null>(null);
|
||||
@ -32,23 +32,21 @@ export const useOrderCancel = () => {
|
||||
|
||||
const cancel = useCallback(
|
||||
async (args: CancelOrderArgs) => {
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
setCancelledOrder(null);
|
||||
|
||||
try {
|
||||
await send({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
await send(pubKey, {
|
||||
orderCancellation: {
|
||||
orderId: args.orderId,
|
||||
marketId: args.marketId,
|
||||
},
|
||||
});
|
||||
|
||||
waitForOrderEvent(args.orderId, keypair.pub, (cancelledOrder) => {
|
||||
waitForOrderEvent(args.orderId, pubKey, (cancelledOrder) => {
|
||||
setCancelledOrder(cancelledOrder);
|
||||
setComplete();
|
||||
});
|
||||
@ -57,7 +55,7 @@ export const useOrderCancel = () => {
|
||||
return;
|
||||
}
|
||||
},
|
||||
[keypair, send, setComplete, waitForOrderEvent]
|
||||
[pubKey, send, setComplete, waitForOrderEvent]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -1,60 +1,76 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import type {
|
||||
VegaKeyExtended,
|
||||
VegaWalletContextShape,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import type { VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import type { ReactNode } from 'react';
|
||||
import { useOrderEdit } from './use-order-edit';
|
||||
import type { OrderEvent, OrderEvent_busEvents } from './';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
import type { OrderFields } from '../components';
|
||||
import type { OrderWithMarket } from '../components';
|
||||
import { generateOrder } from '../components';
|
||||
import {
|
||||
OrderStatus,
|
||||
OrderType,
|
||||
OrderTimeInForce,
|
||||
Side,
|
||||
BusEventType,
|
||||
} from '@vegaprotocol/types';
|
||||
|
||||
const defaultWalletContext = {
|
||||
keypair: null,
|
||||
keypairs: [],
|
||||
pubKey: null,
|
||||
pubKeys: [],
|
||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
||||
connect: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
selectPublicKey: jest.fn(),
|
||||
selectPubKey: jest.fn(),
|
||||
connector: null,
|
||||
};
|
||||
|
||||
function setup(order: OrderFields, context?: Partial<VegaWalletContextShape>) {
|
||||
function setup(
|
||||
order: OrderWithMarket,
|
||||
context?: Partial<VegaWalletContextShape>
|
||||
) {
|
||||
const mocks: MockedResponse<OrderEvent> = {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: 'Limit',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: 'Active',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: 'GTC',
|
||||
side: 'Buy',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -63,33 +79,42 @@ function setup(order: OrderFields, context?: Partial<VegaWalletContextShape>) {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: 'Limit',
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: 'Active',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: 'GTC',
|
||||
side: 'Buy',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -110,26 +135,22 @@ function setup(order: OrderFields, context?: Partial<VegaWalletContextShape>) {
|
||||
describe('useOrderEdit', () => {
|
||||
it('should edit a correctly formatted order', async () => {
|
||||
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
const keypair = {
|
||||
pub: '0x123',
|
||||
} as VegaKeyExtended;
|
||||
const pubKeyObj = { publicKey: '0x123', name: 'test key 1' };
|
||||
const order = generateOrder({
|
||||
price: '123456789',
|
||||
market: { decimalPlaces: 2 },
|
||||
});
|
||||
const { result } = setup(order, {
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [keypair],
|
||||
keypair,
|
||||
pubKeys: [pubKeyObj],
|
||||
pubKey: pubKeyObj.publicKey,
|
||||
});
|
||||
|
||||
act(() => {
|
||||
result.current.edit({ price: '1234567.89' });
|
||||
});
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
expect(mockSendTx).toHaveBeenCalledWith(pubKeyObj.publicKey, {
|
||||
orderAmendment: {
|
||||
orderId: order.id,
|
||||
// eslint-disable-next-line
|
||||
@ -157,8 +178,8 @@ describe('useOrderEdit', () => {
|
||||
const mockSendTx = jest.fn();
|
||||
const { result } = setup(order, {
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [],
|
||||
keypair: null,
|
||||
pubKeys: [],
|
||||
pubKey: null,
|
||||
});
|
||||
await act(async () => {
|
||||
result.current.edit(order);
|
||||
|
@ -12,7 +12,7 @@ export interface EditOrderArgs {
|
||||
}
|
||||
|
||||
export const useOrderEdit = (order: Order | null) => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const [updatedOrder, setUpdatedOrder] =
|
||||
useState<OrderEvent_busEvents_event_Order | null>(null);
|
||||
@ -34,16 +34,14 @@ export const useOrderEdit = (order: Order | null) => {
|
||||
|
||||
const edit = useCallback(
|
||||
async (args: EditOrderArgs) => {
|
||||
if (!keypair || !order || !order.market) {
|
||||
if (!pubKey || !order || !order.market) {
|
||||
return;
|
||||
}
|
||||
|
||||
setUpdatedOrder(null);
|
||||
|
||||
try {
|
||||
await send({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
await send(pubKey, {
|
||||
orderAmendment: {
|
||||
orderId: order.id,
|
||||
marketId: order.market.id,
|
||||
@ -56,7 +54,7 @@ export const useOrderEdit = (order: Order | null) => {
|
||||
},
|
||||
});
|
||||
|
||||
waitForOrderEvent(order.id, keypair.pub, (updatedOrder) => {
|
||||
waitForOrderEvent(order.id, pubKey, (updatedOrder) => {
|
||||
setUpdatedOrder(updatedOrder);
|
||||
setComplete();
|
||||
});
|
||||
@ -65,7 +63,7 @@ export const useOrderEdit = (order: Order | null) => {
|
||||
return;
|
||||
}
|
||||
},
|
||||
[keypair, send, order, setComplete, waitForOrderEvent]
|
||||
[pubKey, send, order, setComplete, waitForOrderEvent]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -1,10 +1,8 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import type {
|
||||
VegaKeyExtended,
|
||||
VegaWalletContextShape,
|
||||
} from '@vegaprotocol/wallet';
|
||||
import type { PubKey, VegaWalletContextShape } from '@vegaprotocol/wallet';
|
||||
import { VegaTxStatus, VegaWalletContext } from '@vegaprotocol/wallet';
|
||||
import {
|
||||
BusEventType,
|
||||
MarketState,
|
||||
MarketTradingMode,
|
||||
OrderStatus,
|
||||
@ -15,7 +13,7 @@ import {
|
||||
import type { ReactNode } from 'react';
|
||||
import type { OrderSubmissionBody } from '@vegaprotocol/wallet';
|
||||
import { useOrderSubmit } from './use-order-submit';
|
||||
import type { OrderEvent, OrderEvent_busEvents } from './';
|
||||
import type { OrderEvent } from './';
|
||||
import { ORDER_EVENT_SUB } from './order-event-query';
|
||||
import type { MockedResponse } from '@apollo/client/testing';
|
||||
import { MockedProvider } from '@apollo/client/testing';
|
||||
@ -48,12 +46,12 @@ const defaultMarket = {
|
||||
};
|
||||
|
||||
const defaultWalletContext = {
|
||||
keypair: null,
|
||||
keypairs: [],
|
||||
pubKey: null,
|
||||
pubKeys: [],
|
||||
sendTx: jest.fn().mockReturnValue(Promise.resolve(null)),
|
||||
connect: jest.fn(),
|
||||
disconnect: jest.fn(),
|
||||
selectPublicKey: jest.fn(),
|
||||
selectPubKey: jest.fn(),
|
||||
connector: null,
|
||||
};
|
||||
|
||||
@ -62,33 +60,42 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -97,33 +104,42 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
request: {
|
||||
query: ORDER_EVENT_SUB,
|
||||
variables: {
|
||||
partyId: context?.keypair?.pub || '',
|
||||
partyId: context?.pubKey || '',
|
||||
},
|
||||
},
|
||||
result: {
|
||||
data: {
|
||||
busEvents: [
|
||||
{
|
||||
type: 'Order',
|
||||
type: BusEventType.Order,
|
||||
event: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
id: '9c70716f6c3698ac7bbcddc97176025b985a6bb9a0c4507ec09c9960b3216b62',
|
||||
status: OrderStatus.STATUS_ACTIVE,
|
||||
rejectionReason: null,
|
||||
createdAt: '2022-07-05T14:25:47.815283706Z',
|
||||
expiresAt: '2022-07-05T14:25:47.815283706Z',
|
||||
size: '10',
|
||||
price: '300000',
|
||||
timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC,
|
||||
side: Side.SIDE_BUY,
|
||||
market: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
id: 'market-id',
|
||||
decimalPlaces: 5,
|
||||
positionDecimalPlaces: 0,
|
||||
tradableInstrument: {
|
||||
__typename: 'TradableInstrument',
|
||||
instrument: {
|
||||
name: 'UNIDAI Monthly (30 Jun 2022)',
|
||||
__typename: 'Instrument',
|
||||
},
|
||||
},
|
||||
__typename: 'Market',
|
||||
},
|
||||
__typename: 'Order',
|
||||
},
|
||||
__typename: 'BusEvent',
|
||||
} as OrderEvent_busEvents,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
@ -144,13 +160,11 @@ function setup(context?: Partial<VegaWalletContextShape>) {
|
||||
describe('useOrderSubmit', () => {
|
||||
it('should submit a correctly formatted order on GTT', async () => {
|
||||
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
const keypair = {
|
||||
pub: '0x123',
|
||||
} as VegaKeyExtended;
|
||||
const pubKey = '0x123';
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [keypair],
|
||||
keypair,
|
||||
pubKeys: [{ publicKey: pubKey, name: 'test key 1' }],
|
||||
pubKey,
|
||||
});
|
||||
|
||||
const order = {
|
||||
@ -165,9 +179,7 @@ describe('useOrderSubmit', () => {
|
||||
result.current.submit({ ...order, marketId: defaultMarket.id });
|
||||
});
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
expect(mockSendTx).toHaveBeenCalledWith(pubKey, {
|
||||
orderSubmission: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
marketId: defaultMarket.id,
|
||||
@ -182,13 +194,14 @@ describe('useOrderSubmit', () => {
|
||||
|
||||
it('should submit a correctly formatted order on GTC', async () => {
|
||||
const mockSendTx = jest.fn().mockReturnValue(Promise.resolve({}));
|
||||
const keypair = {
|
||||
pub: '0x123',
|
||||
} as VegaKeyExtended;
|
||||
const publicKeyObj: PubKey = {
|
||||
publicKey: '0x123',
|
||||
name: 'test key 1',
|
||||
};
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [keypair],
|
||||
keypair,
|
||||
pubKeys: [publicKeyObj],
|
||||
pubKey: publicKeyObj.publicKey,
|
||||
});
|
||||
|
||||
const order = {
|
||||
@ -203,9 +216,7 @@ describe('useOrderSubmit', () => {
|
||||
result.current.submit({ ...order, marketId: defaultMarket.id });
|
||||
});
|
||||
|
||||
expect(mockSendTx).toHaveBeenCalledWith({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
expect(mockSendTx).toHaveBeenCalledWith(publicKeyObj.publicKey, {
|
||||
orderSubmission: {
|
||||
type: OrderType.TYPE_LIMIT,
|
||||
marketId: defaultMarket.id,
|
||||
@ -231,8 +242,8 @@ describe('useOrderSubmit', () => {
|
||||
const mockSendTx = jest.fn();
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [],
|
||||
keypair: null,
|
||||
pubKeys: [],
|
||||
pubKey: null,
|
||||
});
|
||||
await act(async () => {
|
||||
result.current.submit({} as OrderSubmissionBody['orderSubmission']);
|
||||
@ -242,13 +253,14 @@ describe('useOrderSubmit', () => {
|
||||
|
||||
it('should not sendTx side is not specified', async () => {
|
||||
const mockSendTx = jest.fn();
|
||||
const keypair = {
|
||||
pub: '0x123',
|
||||
} as VegaKeyExtended;
|
||||
const publicKeyObj: PubKey = {
|
||||
publicKey: '0x123',
|
||||
name: 'test key 1',
|
||||
};
|
||||
const { result } = setup({
|
||||
sendTx: mockSendTx,
|
||||
keypairs: [keypair],
|
||||
keypair,
|
||||
pubKeys: [publicKeyObj],
|
||||
pubKey: publicKeyObj.publicKey,
|
||||
});
|
||||
await act(async () => {
|
||||
result.current.submit({} as OrderSubmissionBody['orderSubmission']);
|
||||
|
@ -2,8 +2,8 @@ import { useCallback, useState } from 'react';
|
||||
import type { ReactNode } from 'react';
|
||||
import type { OrderEvent_busEvents_event_Order } from './__generated__/OrderEvent';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { determineId, toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
import { useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import { toNanoSeconds } from '@vegaprotocol/react-helpers';
|
||||
import { useVegaTransaction, determineId } from '@vegaprotocol/wallet';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { useOrderEvent } from './use-order-event';
|
||||
import { OrderTimeInForce } from '@vegaprotocol/types';
|
||||
@ -85,7 +85,7 @@ export const getOrderDialogIcon = (
|
||||
};
|
||||
|
||||
export const useOrderSubmit = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const {
|
||||
send,
|
||||
@ -107,16 +107,14 @@ export const useOrderSubmit = () => {
|
||||
|
||||
const submit = useCallback(
|
||||
async (order: OrderSubmissionBody['orderSubmission']) => {
|
||||
if (!keypair || !order.side) {
|
||||
if (!pubKey || !order.side) {
|
||||
return;
|
||||
}
|
||||
|
||||
setFinalizedOrder(null);
|
||||
|
||||
try {
|
||||
const res = await send({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
const res = await send(pubKey, {
|
||||
orderSubmission: {
|
||||
...order,
|
||||
price:
|
||||
@ -131,22 +129,20 @@ export const useOrderSubmit = () => {
|
||||
},
|
||||
});
|
||||
|
||||
if (res?.signature) {
|
||||
const resId = determineId(res.signature);
|
||||
if (resId) {
|
||||
waitForOrderEvent(resId, keypair.pub, (order) => {
|
||||
if (res) {
|
||||
const orderId = determineId(res.signature);
|
||||
if (orderId) {
|
||||
waitForOrderEvent(orderId, pubKey, (order) => {
|
||||
setFinalizedOrder(order);
|
||||
setComplete();
|
||||
});
|
||||
}
|
||||
}
|
||||
return res;
|
||||
} catch (e) {
|
||||
Sentry.captureException(e);
|
||||
return;
|
||||
}
|
||||
},
|
||||
[keypair, send, setComplete, waitForOrderEvent]
|
||||
[pubKey, send, setComplete, waitForOrderEvent]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -4,9 +4,9 @@ import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { PositionsManager } from './positions-manager';
|
||||
|
||||
export const PositionsContainer = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
if (!keypair) {
|
||||
if (!pubKey) {
|
||||
return (
|
||||
<Splash>
|
||||
<p>{t('Please connect Vega wallet')}</p>
|
||||
@ -14,5 +14,5 @@ export const PositionsContainer = () => {
|
||||
);
|
||||
}
|
||||
|
||||
return <PositionsManager partyId={keypair.pub} />;
|
||||
return <PositionsManager partyId={pubKey} />;
|
||||
};
|
||||
|
@ -1,13 +1,12 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useVegaWallet } from '@vegaprotocol/wallet';
|
||||
import { determineId } from '@vegaprotocol/react-helpers';
|
||||
import { useVegaTransaction } from '@vegaprotocol/wallet';
|
||||
import { useVegaTransaction, determineId } from '@vegaprotocol/wallet';
|
||||
import * as Sentry from '@sentry/react';
|
||||
import { usePositionEvent } from '../';
|
||||
import type { Position } from '../';
|
||||
|
||||
export const useClosePosition = () => {
|
||||
const { keypair } = useVegaWallet();
|
||||
const { pubKey } = useVegaWallet();
|
||||
|
||||
const {
|
||||
send,
|
||||
@ -24,14 +23,12 @@ export const useClosePosition = () => {
|
||||
|
||||
const submit = useCallback(
|
||||
async (position: Position) => {
|
||||
if (!keypair || position.openVolume === '0') {
|
||||
if (!pubKey || position.openVolume === '0') {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await send({
|
||||
pubKey: keypair.pub,
|
||||
propagate: true,
|
||||
const res = await send(pubKey, {
|
||||
orderCancellation: {
|
||||
marketId: position.marketId,
|
||||
orderId: '',
|
||||
@ -41,7 +38,7 @@ export const useClosePosition = () => {
|
||||
if (res?.signature) {
|
||||
const resId = determineId(res.signature);
|
||||
if (resId) {
|
||||
waitForPositionEvent(resId, keypair.pub, () => {
|
||||
waitForPositionEvent(resId, pubKey, () => {
|
||||
setComplete();
|
||||
});
|
||||
}
|
||||
@ -52,7 +49,7 @@ export const useClosePosition = () => {
|
||||
return;
|
||||
}
|
||||
},
|
||||
[keypair, send, setComplete, waitForPositionEvent]
|
||||
[pubKey, send, setComplete, waitForPositionEvent]
|
||||
);
|
||||
|
||||
return {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"extends": ["plugin:@nrwl/nx/react", "../../.eslintrc.json"],
|
||||
"ignorePatterns": ["!**/*", "__generated__"],
|
||||
"ignorePatterns": ["!**/*", "__generated__", "__generated___"],
|
||||
"overrides": [
|
||||
{
|
||||
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
|
||||
|
@ -1 +0,0 @@
|
||||
export * from './NetworkParams';
|
@ -8,3 +8,4 @@ export * from './use-screen-dimensions';
|
||||
export * from './use-theme-switcher';
|
||||
export * from './use-mutation-observer';
|
||||
export * from './use-resize-observer';
|
||||
export * from './__generated__/NetworkParam';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { gql, useQuery } from '@apollo/client';
|
||||
import { useMemo } from 'react';
|
||||
import type { NetworkParams as NetworkParamsResponse } from './__generated__';
|
||||
import type { NetworkParams as NetworkParamsResponse } from './__generated__/NetworkParams';
|
||||
|
||||
export const NETWORK_PARAMETERS_QUERY = gql`
|
||||
query NetworkParams {
|
||||
|
@ -1,7 +1,6 @@
|
||||
export * from './hooks';
|
||||
export * from './lib/assets';
|
||||
export * from './lib/context';
|
||||
export * from './lib/determine-id';
|
||||
export * from './lib/format';
|
||||
export * from './lib/generic-data-provider';
|
||||
export * from './lib/get-nodes';
|
||||
@ -13,3 +12,4 @@ export * from './lib/remove-0x';
|
||||
export * from './lib/storage';
|
||||
export * from './lib/time';
|
||||
export * from './lib/validate';
|
||||
export * from './lib/__generated___/ChainId';
|
||||
|
5
libs/react-helpers/src/lib/ChainId.graphql
Normal file
5
libs/react-helpers/src/lib/ChainId.graphql
Normal file
@ -0,0 +1,5 @@
|
||||
query ChainId {
|
||||
statistics {
|
||||
chainId
|
||||
}
|
||||
}
|
45
libs/react-helpers/src/lib/__generated___/ChainId.ts
Normal file
45
libs/react-helpers/src/lib/__generated___/ChainId.ts
Normal file
@ -0,0 +1,45 @@
|
||||
import { Schema as Types} from '@vegaprotocol/types';
|
||||
|
||||
import { gql } from '@apollo/client';
|
||||
import * as Apollo from '@apollo/client';
|
||||
const defaultOptions = {} as const;
|
||||
export type ChainIdQueryVariables = Types.Exact<{ [key: string]: never; }>;
|
||||
|
||||
|
||||
export type ChainIdQuery = { __typename?: 'Query', statistics: { __typename?: 'Statistics', chainId: string } };
|
||||
|
||||
|
||||
export const ChainIdDocument = gql`
|
||||
query ChainId {
|
||||
statistics {
|
||||
chainId
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
/**
|
||||
* __useChainIdQuery__
|
||||
*
|
||||
* To run a query within a React component, call `useChainIdQuery` and pass it any options that fit your needs.
|
||||
* When your component renders, `useChainIdQuery` returns an object from Apollo Client that contains loading, error, and data properties
|
||||
* you can use to render your UI.
|
||||
*
|
||||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options;
|
||||
*
|
||||
* @example
|
||||
* const { data, loading, error } = useChainIdQuery({
|
||||
* variables: {
|
||||
* },
|
||||
* });
|
||||
*/
|
||||
export function useChainIdQuery(baseOptions?: Apollo.QueryHookOptions<ChainIdQuery, ChainIdQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useQuery<ChainIdQuery, ChainIdQueryVariables>(ChainIdDocument, options);
|
||||
}
|
||||
export function useChainIdLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<ChainIdQuery, ChainIdQueryVariables>) {
|
||||
const options = {...defaultOptions, ...baseOptions}
|
||||
return Apollo.useLazyQuery<ChainIdQuery, ChainIdQueryVariables>(ChainIdDocument, options);
|
||||
}
|
||||
export type ChainIdQueryHookResult = ReturnType<typeof useChainIdQuery>;
|
||||
export type ChainIdLazyQueryHookResult = ReturnType<typeof useChainIdLazyQuery>;
|
||||
export type ChainIdQueryResult = Apollo.QueryResult<ChainIdQuery, ChainIdQueryVariables>;
|
@ -1,10 +0,0 @@
|
||||
import { ethers } from 'ethers';
|
||||
import { sha3_256 } from 'js-sha3';
|
||||
|
||||
/**
|
||||
* This function creates an ID in the same way that core does on the backend. This way we
|
||||
* Can match up the newly created order with incoming orders via a subscription
|
||||
*/
|
||||
export const determineId = (sig: string) => {
|
||||
return sha3_256(ethers.utils.arrayify('0x' + sig));
|
||||
};
|
@ -4,7 +4,6 @@ export * from './grid';
|
||||
export * from './storage';
|
||||
export * from './validate';
|
||||
export * from './assets';
|
||||
export * from './determine-id';
|
||||
export * from './generic-data-provider';
|
||||
export * from './get-nodes';
|
||||
export * from './get-events';
|
||||
|
@ -33,4 +33,5 @@ export * from './text-area';
|
||||
export * from './theme-switcher';
|
||||
export * from './toggle';
|
||||
export * from './tooltip';
|
||||
export * from './vega-icons';
|
||||
export * from './vega-logo';
|
||||
|
24
libs/ui-toolkit/src/components/vega-icons/cross.tsx
Normal file
24
libs/ui-toolkit/src/components/vega-icons/cross.tsx
Normal file
@ -0,0 +1,24 @@
|
||||
export const Cross = () => {
|
||||
return (
|
||||
<svg width="50" height="50" viewBox="0 0 50 50" fill="currentColor">
|
||||
<path d="M47 47H3V50H47V47Z" />
|
||||
<path d="M3 3H0V47H3V3Z" />
|
||||
<path d="M47 0H3V3H47V0Z" />
|
||||
<path d="M50 3H47V47H50V3Z" />
|
||||
<path d="M17.5 32.5H14.5V35.5H17.5V32.5Z" />
|
||||
<path d="M20.5 29.5H17.5V32.5H20.5V29.5Z" />
|
||||
<path d="M23.5 26.5H20.5V29.5H23.5V26.5Z" />
|
||||
<path d="M26.5 23.5H23.5V26.5H26.5V23.5Z" />
|
||||
<path d="M29.5 20.5H26.5V23.5H29.5V20.5Z" />
|
||||
<path d="M32.5 17.5H29.5V20.5H32.5V17.5Z" />
|
||||
<path d="M35.5 14.5H32.5V17.5H35.5V14.5Z" />
|
||||
<path d="M32.5 32.5V35.5H35.5V32.5H32.5Z" />
|
||||
<path d="M29.5 29.5V32.5H32.5V29.5H29.5Z" />
|
||||
<path d="M26.5 26.5V29.5H29.5V26.5H26.5Z" />
|
||||
<path d="M23.5 23.5V26.5H26.5V23.5H23.5Z" />
|
||||
<path d="M20.5 20.5V23.5H23.5V20.5H20.5Z" />
|
||||
<path d="M17.5 17.5V20.5H20.5V17.5H17.5Z" />
|
||||
<path d="M14.5 14.5V17.5H17.5V14.5H14.5Z" />
|
||||
</svg>
|
||||
);
|
||||
};
|
10
libs/ui-toolkit/src/components/vega-icons/diamond.tsx
Normal file
10
libs/ui-toolkit/src/components/vega-icons/diamond.tsx
Normal file
@ -0,0 +1,10 @@
|
||||
export const Diamond = () => {
|
||||
return (
|
||||
<svg width="67" height="67" viewBox="0 0 67 67" fill="currentColor">
|
||||
<path d="M64.3467 33.234L33.234 64.3467L35.3553 66.468L66.468 35.3553L64.3467 33.234Z" />
|
||||
<path d="M2.12132 33.234L0 35.3553L31.1127 66.468L33.234 64.3467L2.12132 33.234Z" />
|
||||
<path d="M31.1127 0L0 31.1127L2.12132 33.234L33.234 2.12132L31.1127 0Z" />
|
||||
<path d="M35.3553 0L33.234 2.12132L64.3467 33.234L66.468 31.1127L35.3553 0Z" />
|
||||
</svg>
|
||||
);
|
||||
};
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user