Skip to content

Commit

Permalink
πŸ”Œ Toggle ProxyApi with an environment variable (#4679)
Browse files Browse the repository at this point in the history
Toggle `ProxyApi` with an environment variable
  • Loading branch information
thesan authored Dec 22, 2023
1 parent 8c2b81a commit 799161e
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 8 deletions.
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

2 comments on commit 799161e

@vercel
Copy link

@vercel vercel bot commented on 799161e Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2-storybook – ./

pioneer-2-storybook-git-dev-joystream.vercel.app
pioneer-2-storybook.vercel.app
pioneer-2-storybook-joystream.vercel.app

@vercel
Copy link

@vercel vercel bot commented on 799161e Dec 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

pioneer-2 – ./

pioneer-2-git-dev-joystream.vercel.app
pioneer-2-joystream.vercel.app
pioneer-2.vercel.app

Please sign in to comment.