Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🔌 Toggle ProxyApi with an environment variable #4679

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/ui/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ REACT_APP_IMAGE_REPORT_FORM_URL="https://airtable.com/formXYZ?prefill_image={ima
# Development
REACT_APP_API_BENCHMARK=false
REACT_APP_IS_UNDER_MAINTENANCE=false
DISABLE_PROXY_API=false
4 changes: 3 additions & 1 deletion packages/ui/src/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
export { ProxyApi as Api } from '@/proxyApi'
// Warning: This file is aliased in the Webpack config to either `src/proxyApi` or `src/api/api-rx'` depending on the value of DISABLE_PROXY_API

export { Api } from '@/proxyApi'
// export { Api } from './api-rx'
2 changes: 1 addition & 1 deletion packages/ui/src/api/utils/getChainMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ApiRx } from '@polkadot/api'
import { getPolkadotApiChainInfo } from 'injectweb3-connect'

import { ProxyApi } from '@/proxyApi'
import { ProxyApi } from '@/proxyApi/client/ProxyApi'

import { MetadataDef } from '../types'

Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/proxyApi/client/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ import { AnyTuple } from '@polkadot/types/types'
import { uniqueId } from 'lodash'
import { filter, Observable, map, share } from 'rxjs'

import { ProxyApi } from '..'
import { deserializeMessage } from '../models/payload'
import { ApiKinds, PostMessage, RawWorkerMessageEvent } from '../types'
import { apiInterfaceProxy } from '../utils/proxy'

import { ProxyApi } from './ProxyApi'

export type ApiQueryKinds = Exclude<ApiKinds, 'tx'>

export type ClientQueryMessage<K = ApiQueryKinds> = K extends ApiQueryKinds
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/src/proxyApi/client/tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { AnyTuple } from '@polkadot/types/types'
import { uniqueId } from 'lodash'
import { filter, map, Observable, share } from 'rxjs'

import { ProxyApi } from '..'
import { deserializeMessage } from '../models/payload'
import { PostMessage, ProxyPromisePayload, RawWorkerMessageEvent } from '../types'
import { apiInterfaceProxy } from '../utils/proxy'

import { ProxyApi } from './ProxyApi'

type ObservableMethods = (typeof ObservableMethods)[number]

export type TxModule = keyof ProxyApi['tx']
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/proxyApi/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './client/ProxyApi'
export { ProxyApi as Api } from './client/ProxyApi'
2 changes: 1 addition & 1 deletion packages/ui/src/proxyApi/types.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SubmittableExtrinsic } from '@polkadot/api/types'

import { ProxyApi } from '.'
import { ClientAsyncMessage, WorkerAsyncMessage } from './client/_async'
import { ProxyApi } from './client/ProxyApi'
import { ClientQueryMessage, WorkerQueryMessage } from './client/query'
import { ClientTxMessage, WorkerTxMessage } from './client/tx'
import { ClientProxyMessage, WorkerProxyMessage } from './models/payload'
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/proxyApi/utils/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AnyTuple } from '@polkadot/types/types'

import { recursiveProxy } from '@/common/utils/proxy'

import { ProxyApi } from '..'
import { ProxyApi } from '../client/ProxyApi'
import { ApiKinds } from '../types'

type ApiPath<K extends ApiKinds> = [keyof ProxyApi[K], ...string[]]
Expand Down
9 changes: 8 additions & 1 deletion packages/ui/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = (env, argv) => {
.map(([key, value]) => [`process.env.${key}`, JSON.stringify(value)])

const imageBlacklist = [...(env.blacklist ?? []), ...(process.env.REACT_APP_BLACKLISTED_IMAGES?.split(/\s+/) ?? [])]
const disableProxyApi = process.env.DISABLE_PROXY_API === 'true'

const plugins = [
...shared.plugins,
Expand Down Expand Up @@ -89,7 +90,13 @@ module.exports = (env, argv) => {
},
],
},
resolve: shared.resolve,
resolve: {
...shared.resolve,
alias: {
'@/api$': path.resolve(__dirname, disableProxyApi ? './src/api/api-rx.ts' : './src/proxyApi/index.ts'),
...shared.resolve.alias,
},
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'build'),
Expand Down