Skip to content

Commit

Permalink
refactor(general): Simplify apps backend env var (#412)
Browse files Browse the repository at this point in the history
* feat(wallet-dashboard): show dapps list.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* refactor(general): Simplify the management of the `APPS_BACKEND` env var

* refactor(general): Clean up

* feat(wallet-dashboard): fix cors issue.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* feat(wallet-dashboard): allow cors for all.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* refactor(general): Simplify apps backend env var (#398)

* refactor(general): Simplify the management of the `APPS_BACKEND` env var

* refactor(general): Clean up

* Revert "refactor(general): Simplify apps backend env var (#398)" (#411)

This reverts commit 4270acf.

* feat(wallet-dashboard): pr comments fix. Return list of unique values.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* feat(wallet-dashboard): change network for apps-backend.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* feat(wallet-dashboard): use Image from next/image

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* feat(wallet-dashboard): move AppList to /apps

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* feat(wallet-dashboard): add import React.

Signed-off-by: Eugene Panteleymonchuk <[email protected]>

* chore: lockfile

---------

Signed-off-by: Eugene Panteleymonchuk <[email protected]>
Co-authored-by: Eugene Panteleymonchuk <[email protected]>
Co-authored-by: Mario <[email protected]>
Co-authored-by: cpl121 <[email protected]>
  • Loading branch information
4 people authored May 29, 2024
1 parent 14fbd4a commit 757438e
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 38 deletions.
21 changes: 2 additions & 19 deletions apps/core/src/hooks/useAppsBackend.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,11 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { getAppsBackend } from '@mysten/sui.js/client';
import { useCallback } from 'react';

export function getBackendUrl() {
if (
typeof import.meta !== 'undefined' &&
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import.meta.env &&
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import.meta.env.VITE_APPS_BACKEND_URL
) {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return import.meta.env.VITE_APPS_BACKEND_URL;
}

return process.env.NEXT_PUBLIC_APPS_BACKEND_URL;
}

export function useAppsBackend() {
const backendUrl = getBackendUrl();
const backendUrl = getAppsBackend();

const request = useCallback(
async <T>(
Expand Down
1 change: 0 additions & 1 deletion apps/explorer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@
"@vitejs/plugin-react": "^4.0.3",
"@vitest/ui": "^0.33.0",
"autoprefixer": "^10.4.14",
"dotenv": "^16.4.5",
"happy-dom": "^10.5.1",
"onchange": "^7.1.0",
"postcss": "^8.4.31",
Expand Down
3 changes: 2 additions & 1 deletion apps/explorer/src/utils/growthbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

import { GrowthBook } from '@growthbook/growthbook';
import { getAppsBackend } from '@mysten/sui.js/client';

export const growthbook = new GrowthBook({
// If you want to develop locally, you can set the API host to this:
apiHost: import.meta.env.APPS_BACKEND_URL,
apiHost: getAppsBackend(),
clientKey: import.meta.env.PROD ? 'production' : 'development',
enableDevMode: import.meta.env.DEV,
});
8 changes: 0 additions & 8 deletions apps/explorer/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ import { defineConfig } from 'vite';
import pluginRewriteAll from 'vite-plugin-rewrite-all';
import svgr from 'vite-plugin-svgr';
import { configDefaults } from 'vitest/config';
import dotenv from 'dotenv';
import { resolve } from 'path';

const SDK_ROOT = resolve(__dirname, '..', '..', 'sdk');

dotenv.config({
path: [resolve(SDK_ROOT, '.env'), resolve(SDK_ROOT, '.env.defaults')],
});
process.env.VITE_VERCEL_ENV = process.env.VERCEL_ENV || 'development';
process.env.VITE_APPS_BACKEND_URL = process.env.APPS_BACKEND_URL;

// https://vitejs.dev/config/
export default defineConfig({
Expand Down
3 changes: 1 addition & 2 deletions apps/wallet/configs/webpack/webpack.config.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,7 @@ const commonConfig: () => Promise<Configuration> = async () => {
'process.env.APP_NAME': JSON.stringify(APP_NAME),
'process.env.DEFAULT_NETWORK': JSON.stringify(process.env.DEFAULT_NETWORK),
'process.env.IOTA_NETWORKS': JSON.stringify(process.env.IOTA_NETWORKS),
'process.env.APPS_BACKEND_URL': JSON.stringify(process.env.APPS_BACKEND_URL),
'import.meta.env.VITE_APPS_BACKEND_URL': JSON.stringify(process.env.APPS_BACKEND_URL),
'process.env.APPS_BACKEND': JSON.stringify(process.env.APPS_BACKEND),
}),
new ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/src/shared/experimentation/features.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { GrowthBook } from '@growthbook/growthbook';
import { Network } from '@mysten/sui.js/client';
import { Network, getAppsBackend } from '@mysten/sui.js/client';
import Browser from 'webextension-polyfill';

// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
export const growthbook = new GrowthBook({
apiHost: process.env.APPS_BACKEND_URL,
apiHost: getAppsBackend(),
clientKey: process.env.NODE_ENV === 'development' ? 'development' : 'production',
enableDevMode: process.env.NODE_ENV === 'development',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Banxa from './icons/Banxa.svg';
import MoonPay from './icons/MoonPay.svg';
import Transak from './icons/Transak.svg';
import { type OnrampProvider } from './types';
import { getAppsBackend } from '@mysten/sui.js/client';

const TRANSAK_API_KEY =
process.env.NODE_ENV === 'production'
Expand All @@ -21,7 +22,7 @@ const MOONPAY_API_KEY =
? 'pk_live_iL2LFRM1wCc4EfBuxFJSVTkI8Xno4a'
: 'pk_test_RwNag1qi8jFoymVchhCSc5cYnqyPrVd5';

const BACKEND_HOST = process.env.APPS_BACKEND_URL;
const BACKEND_HOST = getAppsBackend();

const ONRAMP_PROVIDER: OnrampProvider[] = [
{
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion sdk/.env.defaults
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
DEFAULT_NETWORK = 'testnet'
APPS_BACKEND_URL = 'http://localhost:3003'
APPS_BACKEND = 'http://localhost:3003'

IOTA_NETWORKS = '
{
Expand Down
1 change: 1 addition & 0 deletions sdk/build-scripts/src/utils/buildPackage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ async function embedIOTAEnvVars() {
return {
'process.env.DEFAULT_NETWORK': JSON.stringify(process.env['DEFAULT_NETWORK']),
'process.env.IOTA_NETWORKS': JSON.stringify(process.env['IOTA_NETWORKS']),
'process.env.APPS_BACKEND': JSON.stringify(process.env['APPS_BACKEND']),
};
}

Expand Down
3 changes: 3 additions & 0 deletions sdk/typescript/src/client/apps-backend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function getAppsBackend(): string {
return process.env.APPS_BACKEND as string
}
1 change: 1 addition & 0 deletions sdk/typescript/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export * from './network.js';
export * from './types/index.js';
export * from './client.js';
export * from './errors.js';
export * from './apps-backend.js';

0 comments on commit 757438e

Please sign in to comment.