vega-frontend-monorepo/apps/trading/lib/apollo-client.ts

112 lines
2.6 KiB
TypeScript
Raw Normal View History

import {
ApolloClient,
ApolloLink,
split,
from,
HttpLink,
InMemoryCache,
} from '@apollo/client';
import { GraphQLWsLink } from '@apollo/client/link/subscriptions';
import { getMainDefinition } from '@apollo/client/utilities';
2022-02-28 23:43:36 +00:00
import { onError } from '@apollo/client/link/error';
import { RetryLink } from '@apollo/client/link/retry';
import { createClient as createWSClient } from 'graphql-ws';
2022-02-28 23:43:36 +00:00
export function createClient(base?: string) {
if (!base) {
throw new Error('Base must be passed into createClient!');
}
feat: 0.54.0 (#949) * chore: remove stagnet2, add stagnet3 * fix: types for transaction order submission (#932) * test: add night runs again (#917) Co-authored-by: Rado <rado@vegaprotocol.io> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Feat/893 anchor per network param (#907) * feat: highlight network param targeted by anchor * Feat/893: Highlighted key-value row colours * Feat/893: Removed unneeded important bangs Co-authored-by: sam-keen <samuel.kleinmann@gmail.com> * Fix/687: Jump to block input should not allow negative block numbers or 0 (#918) * Fix/687: Jump to block input should not allow negative block numbers * Fix/687: Jump to block input should have a minimum of 1 * fix: text and theme icon colors (#920) * Fix/eager connection (#923) * fix: eager connect * chore: add comment for eslint disable * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Task/Remove vegawallet service api client (#916) * chore: remove generated vegawallet client code and implement in rest connector * feat: add zod validation * feat: handle specific auth/token delete case * feat: make withdraw dialog match vega tx dialog * fix: response stub to be right shape, add content type to requests * chore: revert unrelated classname change * feat: [console-lite] - fixes in order margin calcs (#891) * feat: [console-lite] - fixes in order margin calcs * feat: [console-lite] - fixes in order margin calcs - fix decimals * feat: [console-lite] - fixes in order margin calcs - add unit tests * feat: [console-lite] - fixes in order margin calcs - improve cals * feat: [console-lite] - fixes in order margin calcs - improve cals * feat: [console-lite] - fixes in order margin calcs - more improvements Co-authored-by: maciek <maciek@vegaprotocol.io> * fix: make check link unclickable while loading (#928) * fix: make check link unclickable while loading * fix: format * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix/904: Validators sorting (#913) * fix(790): gap between orderbook headers and tabs (#929) * feat: show correct reward type (#930) * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * Task/remove vegawallet service (#926) * feat: improve error handling * chore: lint * fix: cypress test incorrect assertion * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * chore: update tranches Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> * fix: order transaction types Co-authored-by: Radosław Szpiech <szpiechrados@gmail.com> Co-authored-by: Rado <rado@vegaprotocol.io> Co-authored-by: mattrussell36 <mattrussell36@users.noreply.github.com> Co-authored-by: Edd <edd@vega.xyz> Co-authored-by: sam-keen <samuel.kleinmann@gmail.com> Co-authored-by: Sam Keen <samuel@vegaprotocol.io> Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: macqbat <kubat.maciek@gmail.com> Co-authored-by: maciek <maciek@vegaprotocol.io> Co-authored-by: asiaznik <artur.siaznik@gmail.com> Co-authored-by: Dexter Edwards <dexter.edwards93@gmail.com> * test: fix test import * chore: resolve bad merge files * chore: begin enum changes * test: fix the majority of the tests * test: fix tests * style: lint * fix: update enums * fix: adjusted tests to updated enums * ci: bump capsule * fix: temporarily skip failing staking tests * ci: revert capsule changes * test: fix tests for stats * chore: merge few changes and api updates to stagnet3 updates branch (#1100) * chore: merge few changes and api updates to stagnet3 updates branch * chore: [console-lite] - fast fix in unit test Co-authored-by: maciek <maciek@vegaprotocol.io> * test: fix broken test * chore: change to use the new nodes rather than load balancer * style: formatting * style: formatting * chore: fix env file * fix: don't assume GQL URL path * fix: skip positions query if there is no part * fix: simple trading app test Co-authored-by: botond <105208209+notbot00@users.noreply.github.com> Co-authored-by: Radosław Szpiech <szpiechrados@gmail.com> Co-authored-by: Rado <rado@vegaprotocol.io> Co-authored-by: mattrussell36 <mattrussell36@users.noreply.github.com> Co-authored-by: Edd <edd@vega.xyz> Co-authored-by: sam-keen <samuel.kleinmann@gmail.com> Co-authored-by: Sam Keen <samuel@vegaprotocol.io> Co-authored-by: Matthew Russell <mattrussell36@gmail.com> Co-authored-by: macqbat <kubat.maciek@gmail.com> Co-authored-by: maciek <maciek@vegaprotocol.io> Co-authored-by: asiaznik <artur.siaznik@gmail.com> Co-authored-by: Joe <joe@vega.xyz> Co-authored-by: m.ray <16125548+MadalinaRaicu@users.noreply.github.com>
2022-08-22 22:50:13 +00:00
const urlHTTP = new URL(base);
const urlWS = new URL(base);
2022-02-28 23:43:36 +00:00
// Replace http with ws, preserving if its a secure connection eg. https => wss
urlWS.protocol = urlWS.protocol.replace('http', 'ws');
const cache = new InMemoryCache({
typePolicies: {
Account: {
keyFields: false,
fields: {
balanceFormatted: {},
},
},
2022-03-14 15:52:02 +00:00
Instrument: {
keyFields: false,
},
TradableInstrument: {
keyFields: ['instrument'],
},
Product: {
keyFields: ['settlementAsset', ['id']],
},
2022-03-14 15:52:02 +00:00
MarketData: {
keyFields: ['market', ['id']],
},
2022-02-28 23:43:36 +00:00
Node: {
keyFields: false,
},
Feat/104 withdraws (#263) * add withdraw page * add create page and withdraws lib with basic components * add create withdrawal functionality, add withdrawal dialog * re arrange pages so we have a pending page with a list of withdrawals and a withdraw page with the form * handle withdrawal completion * add withdraw dialog so withdraw is completed in one flow * rename and arrange prop getter function to avoid use of any * tidy up and make eth transaction and vega transaction hooks follow similar patterns * make complete withdraw hook fetch approval, combine hooks for full flow * delete unused file * add accounts to query to get use max withdraw button * use ag grid fro withdrawals list * format amount in grid * ensure party has id field for cache * update to use t i18n function * change complete status to better match values of WithdrawalStatus * add asset lib file for type guard * share queries for withdraws lib * move web3 related hooks to the web3 lib and make web3 lib buildable * add unit test for use-complete-withdraw * add test for use-withdraw * add e2e scenarios for withdrawals * don render custom no withdrawals message and use ag grid prop * make withdraw form take ethereum account as prop * add test config, update withdraw form to handle min/max amounts, add unit test for withdraw form * fix rendering 0 if not pending withdrawals * use controlled component for select box * tidy up async parts of tests, add test for withdraw-manager * update withdraw dialog to use map for different tx states * add fallback etherscan link, add test for withdraw-dialog.spec.tsx * rename erc20 query in token app, change page structure to /withdraw and /withdrawals * change linked vegawallet-service-api-client to newly published version * ignore not implemented withdrawals e2e tests * make vega tx pending and requested states the same, for now, until tx confirmation work is done * Add some unit tests for determine-ids and remove0x Neither are critical, but both are libs expected to be shared between projects so some unit tests will hopefully ensure projects all have the same expectations about how the functions act. - Add 1 determine-ids test - Add a few remove-0x tests - Update determine-ids to use remove-0x - Add a comment describing why i18n is what it is * modify cache with client only field for tracking foreign chain progress * move withdrawals-list to lib, add useWithdrawals hook * add container component for withdrawals page * add unit tests for withdrawals-table * add some tests for use-withdrawals hook * revert changes to generated files in other libs and apps * update withdrawals scenarios * resolve pr comments * update page containers to use render prop rather than children * delete unused files * remove transaction dialog story Co-authored-by: Ditmir-Vega <ditmir@vega.xyz> Co-authored-by: Edd <edd@vega.xyz>
2022-04-27 02:51:39 +00:00
Withdrawal: {
fields: {
pendingOnForeignChain: {
read: (isPending = false) => isPending,
},
},
},
feat (#896): large withdraws (#1180) * feat: add deposits table to deposits tab on portfolio page * feat: refactor use-withdraw hook to not invoke eth tx * feat: rename hook for clarity * feat: fix withdrawal creation test * feat: update withdraw-manager and withrawals-table tests * chore: fix lint * feat: remove web3 input to avoid double dialog * chore: use renderHook from testing-library/react * chore: update to use non deprecated fields * chore: remove usage of all bridge contract * feat: correctly merge cache update in withdrawals table * feat: changes to support token app withdrawals * chore: add height to ag grid table wrapping element * feat: add txhash col to withdraw table * feat: provide better ui if withdrawal is not ready to be completed * feat: use separate dialogs for txs * feat: allow user to immediately complete withdrawal if delay not triggered * feat: add withdraw store to tidy up state management * chore: fix tests * chore: convert callback to promises, fix tests, delete withdraw page * chore: fix lint errors * fix: withdrawals link in nav * feat: style changes after design update * fix: proposal form test * chore: tidy error ui logic * feat: review comments * chore: lint * feat: add better typing for tables * chore: put withdrawals tab at the end * chore: update i18n * fix: dialog in positions manager due to rename * chore: increase spacing in withdrawal form * chore: update tests * chore: lint * chore: use new assetsConnection and update cy test * fix: incorrect shape of withdrawal generate function * feat: delete withdrawals page now that its shown on the portfolio page * chore: update tests to check for withdrawals page * chore: fix tests again * fix: page title test
2022-09-06 01:30:13 +00:00
ERC20: {
keyFields: ['contractAddress'],
},
PositionUpdate: {
keyFields: false,
},
AccountUpdate: {
keyFields: false,
},
2022-02-28 23:43:36 +00:00
},
});
const retryLink = new RetryLink({
delay: {
initial: 300,
max: 10000,
jitter: true,
},
});
const httpLink = new HttpLink({
uri: urlHTTP.href,
credentials: 'same-origin',
});
const wsLink = process.browser
? new GraphQLWsLink(
createWSClient({
url: urlWS.href,
})
)
: new ApolloLink((operation, forward) => forward(operation));
const splitLink = process.browser
? split(
({ query }) => {
const definition = getMainDefinition(query);
return (
definition.kind === 'OperationDefinition' &&
definition.operation === 'subscription'
);
},
wsLink,
httpLink
)
: httpLink;
2022-02-28 23:43:36 +00:00
const errorLink = onError(({ graphQLErrors, networkError }) => {
console.log(graphQLErrors);
console.log(networkError);
});
return new ApolloClient({
connectToDevTools: process.env['NODE_ENV'] === 'development',
link: from([errorLink, retryLink, splitLink]),
2022-02-28 23:43:36 +00:00
cache,
});
}