From f5b345636c2decb0abf8f5ba52a95264409ddbca Mon Sep 17 00:00:00 2001 From: Dexter Edwards Date: Thu, 19 Jan 2023 11:16:21 +0000 Subject: [PATCH] feat: view apps as any pub key (#2548) --- apps/token/src/app-loader.tsx | 14 +++- apps/token/src/app.tsx | 2 +- .../page-templates/template-sidebar.tsx | 8 ++ apps/token/src/lib/vega-connectors.ts | 10 ++- .../vote-details/vote-buttons.spec.tsx | 1 + .../propose/freeform/propose-freeform.tsx | 1 - .../propose-network-parameter.tsx | 1 - .../propose/new-asset/propose-new-asset.tsx | 1 - .../propose/new-market/propose-new-market.tsx | 1 - .../proposals/propose/raw/propose-raw.tsx | 1 - .../update-asset/propose-update-asset.tsx | 1 - .../update-market/propose-update-market.tsx | 1 - .../routes/proposals/test-helpers/mocks.ts | 1 + .../components/viewing-banner/index.tsx | 11 +++ apps/trading/lib/vega-connectors.ts | 15 +++- apps/trading/pages/_app.page.tsx | 14 +++- apps/trading/pages/toasts-manager.tsx | 11 ++- .../deal-ticket/deal-ticket-manager.tsx | 3 +- .../lib/order-hooks/use-order-cancel.spec.tsx | 1 + .../lib/order-hooks/use-order-edit.spec.tsx | 1 + .../lib/order-hooks/use-order-submit.spec.tsx | 1 + .../src/lib/use-close-position.spec.tsx | 1 + libs/ui-toolkit/src/components/index.ts | 1 + .../src/components/viewing-as-user/index.tsx | 31 +++++++ .../connect-dialog/connect-dialog.spec.tsx | 81 ++++++++++++++++++- .../src/connect-dialog/connect-dialog.tsx | 26 +++++- .../connect-dialog/view-connector-form.tsx | 64 +++++++++++++++ libs/wallet/src/connectors/index.ts | 1 + libs/wallet/src/connectors/view-connector.tsx | 52 ++++++++++++ libs/wallet/src/context.ts | 2 + libs/wallet/src/provider.spec.tsx | 16 ++++ libs/wallet/src/provider.tsx | 8 +- libs/wallet/src/storage.ts | 2 +- libs/wallet/src/use-eager-connect.ts | 2 - libs/wallet/src/use-vega-transaction.spec.tsx | 19 ++++- libs/wallet/src/use-vega-transaction.tsx | 10 ++- .../vega-transaction-dialog.tsx | 6 +- 37 files changed, 392 insertions(+), 30 deletions(-) create mode 100644 apps/trading/components/viewing-banner/index.tsx create mode 100644 libs/ui-toolkit/src/components/viewing-as-user/index.tsx create mode 100644 libs/wallet/src/connect-dialog/view-connector-form.tsx create mode 100644 libs/wallet/src/connectors/view-connector.tsx diff --git a/apps/token/src/app-loader.tsx b/apps/token/src/app-loader.tsx index 943b1eebc..15e907c8b 100644 --- a/apps/token/src/app-loader.tsx +++ b/apps/token/src/app-loader.tsx @@ -17,6 +17,18 @@ import { import { useContracts } from './contexts/contracts/contracts-context'; import { useRefreshAssociatedBalances } from './hooks/use-refresh-associated-balances'; import { Connectors } from './lib/vega-connectors'; +import { useSearchParams } from 'react-router-dom'; + +const useVegaWalletEagerConnect = () => { + const vegaConnecting = useEagerConnect(Connectors); + const { pubKey, connect } = useVegaWallet(); + const [searchParams] = useSearchParams(); + const [query] = React.useState(searchParams.get('address')); + if (query && !pubKey) { + connect(Connectors['view']); + } + return vegaConnecting; +}; export const AppLoader = ({ children }: { children: React.ReactElement }) => { const { t } = useTranslation(); @@ -27,7 +39,7 @@ export const AppLoader = ({ children }: { children: React.ReactElement }) => { const { token, staking, vesting } = useContracts(); const setAssociatedBalances = useRefreshAssociatedBalances(); const [balancesLoaded, setBalancesLoaded] = React.useState(false); - const vegaConnecting = useEagerConnect(Connectors); + const vegaConnecting = useVegaWalletEagerConnect(); const loaded = balancesLoaded && !vegaConnecting; diff --git a/apps/token/src/app.tsx b/apps/token/src/app.tsx index ab1bdf15a..4fe0e19e3 100644 --- a/apps/token/src/app.tsx +++ b/apps/token/src/app.tsx @@ -88,7 +88,7 @@ const Web3Container = ({ <> -
+
diff --git a/apps/token/src/components/page-templates/template-sidebar.tsx b/apps/token/src/components/page-templates/template-sidebar.tsx index bf4fd8cab..d47b02240 100644 --- a/apps/token/src/components/page-templates/template-sidebar.tsx +++ b/apps/token/src/components/page-templates/template-sidebar.tsx @@ -1,4 +1,6 @@ import { Networks, useEnvironment } from '@vegaprotocol/environment'; +import { ViewingAsBanner } from '@vegaprotocol/ui-toolkit'; +import { useVegaWallet } from '@vegaprotocol/wallet'; import React from 'react'; import { Nav } from '../nav'; @@ -10,9 +12,15 @@ export interface TemplateSidebarProps { export function TemplateSidebar({ children, sidebar }: TemplateSidebarProps) { const { VEGA_ENV } = useEnvironment(); + const { isReadOnly, pubKey, disconnect } = useVegaWallet(); return ( <>