Skip to content

Commit

Permalink
Merge pull request #1644 from bancorprotocol/config/demo
Browse files Browse the repository at this point in the history
Improve config & import config
  • Loading branch information
GrandSchtroumpf authored Feb 4, 2025
2 parents 62e0deb + bee57ad commit 6ac72ba
Show file tree
Hide file tree
Showing 28 changed files with 52 additions and 58 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,9 @@ The file `common.ts` with type [`AppConfig`](src/config/types.ts) contains impor

- `appUrl`: The URL of the app.
- `carbonApi`: The URL of the API.
- `walletConnectProjectId`: The WalletConnect project ID If you wish to add walletConnect, make sure to add it to `selectableConnectionTypes` as well.
- `selectedConnectors`: List of connectors to make available by default in the wallet selection modal that will be shown even if the connector is not injected.
- `selectedConnectors`: List of connectors to make available by default in the wallet selection modal that will be shown even if the connector is not injected. ex ['MetaMask', 'WalletConnect', 'Coinbase Wallet', 'Safe']
- `blockedConnectors`: List of EIP-6963 injected connectors names to block in the wallet selection modal.
- `isSimulatorEnabled`: Flag to enable the simulation page.
- `walletConnectProjectId`: The WalletConnect project ID If you wish to add walletConnect, make sure to add it to `selectableConnectionTypes` as well.
- `network`
- `name`: Network name.
- `logoUrl`: Network logo URL.
Expand All @@ -263,11 +262,24 @@ The file `common.ts` with type [`AppConfig`](src/config/types.ts) contains impor
- `defaultTokenPair`: Default token pair to be used in the app when opening the trade, explore, and simulation pages.
- `popularPairs`: List of popular pairs to be used in the app when opening the token selection modal.
- `popularTokens`: List of popular tokens to be used in the app when opening the token selection modal.
- `addresses`/`carbon` and `addresses/utils`: CarbonController, Voucher and multicall3 contract addresses.
- `addresses`
- `tokens`:
- `ZERO`: Address of the zero token
- `carbon`:
- `carbonController`: Address of CarbonController contract
- `voucher`: Address of Voucher contract
- `utils`:
- `multicall3`
- `address`: Address of the multicall3 contract
- `blockCreated`: Block of the creation of the multicall3
- `tokenListOverride`: Token list override to be used in the app when fetching the token list. Tokens in the list will override any other token with the same address.
- `tokenLists`: List of token lists including the uri and the parser name to be used to parse the token list. Please update the tokenParserMap in the `src/config/utils.ts` file to include the parser name and the parser function.
- `sdk`/`cacheTTL`: When the app loads, it will ignore any cached data if it is older than the cacheTTL time in milliseconds. If set to 0, the app will always ignore the cache data and fetch new data on load.
- `sdk`:
- `cacheTTL`: When the app loads, it will ignore any cached data if it is older than the cacheTTL time in milliseconds. If set to 0, the app will always ignore the cache data and fetch new data on load.
- `tenderly`
- `faucetTokens`: List of address to get tokens from in the debug page
- `ui`
- `showSimulator`: Flag to enable the simulation page.
- `priceChart`: use `tradingView` chart or `native` chart for token pair price history. You need to provide a backend with price history endpoint to support `native` view.
- `useGradientBranding`: Flag to enable gradient styles for buttons.
- `tradeCount`: Display the amount of trades in the explorer page.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/components/core/menu/menuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const menuItems: MenuItem[] = [
href: '/explore',
testid: 'explore-page',
},
...(!config.isSimulatorEnabled
...(!config.ui.showSimulator
? []
: [
{
Expand Down
24 changes: 20 additions & 4 deletions src/components/debug/DebugConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,28 @@ export const DebugConfig = () => {
lsService.removeItem('configOverride');
} else {
const parsedConfig = JSON.parse(configOverride || '');
v.parse(v.partial(AppConfigSchema), parsedConfig);
lsService.setItem('configOverride', parsedConfig);
const result = v.safeParse(v.partial(AppConfigSchema), parsedConfig);
if (result.success) {
for (let i = 0; i < localStorage.length; i++) {
localStorage.removeItem(localStorage.key(i)!);
}
lsService.setItem('configOverride', parsedConfig);
window?.location.reload();
} else {
const errors = result.issues
.map((issue) => {
const path = issue.path
?.map((p) => p.type === 'object' && p.key)
.join('.');
return `[${path}]: ${issue.message}`;
})
.join('\n');
console.error(result.issues);
setError(errors);
}
}
setError('');
window?.location.reload();
} catch (error) {
console.log(error);
setError(errorMessage);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export const StrategyBlockManage: FC<Props> = (props) => {

const isDisposable = isDisposableStrategy(strategy);

if (!isDisposable && config.isSimulatorEnabled) {
if (!isDisposable && config.ui.showSimulator) {
items.push({
id: 'simulate',
name: 'Simulate Strategy',
Expand Down
4 changes: 1 addition & 3 deletions src/config/blast/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ export const commonConfig: AppConfig = {
selectedConnectors: ['MetaMask', 'Coinbase Wallet', 'Safe'],
blockedConnectors: ['Tailwind', 'Compass Wallet', 'Seif'],
walletConnectProjectId: '',
isSimulatorEnabled: false,
policiesLastUpdated: '31 Jul, 2024',
network: {
name: 'Blast Network',
Expand Down Expand Up @@ -104,8 +103,6 @@ export const commonConfig: AppConfig = {
},
],
tenderly: {
nativeTokenDonorAccount: '0xf89d7b9c864f589bbF53a82105107622B35EaA40',
faucetAmount: 1000,
faucetTokens: [
{
donorAccount: '0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972',
Expand All @@ -128,6 +125,7 @@ export const commonConfig: AppConfig = {
],
},
ui: {
showSimulator: false,
priceChart: 'tradingView',
useGradientBranding: true,
tradeCount: false,
Expand Down
4 changes: 1 addition & 3 deletions src/config/celo/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export const commonConfig: AppConfig = {
selectedConnectors: ['MetaMask', 'Coinbase Wallet', 'Safe', 'WalletConnect'],
blockedConnectors: ['Tailwind', 'Compass Wallet', 'Seif'],
walletConnectProjectId: 'f9d8863ab6c03f2293d7d56d7c0c0853',
isSimulatorEnabled: true,
policiesLastUpdated: '31 Jul, 2024',
network: {
name: 'Celo Network',
Expand Down Expand Up @@ -115,8 +114,6 @@ export const commonConfig: AppConfig = {
},
],
tenderly: {
nativeTokenDonorAccount: '0xf89d7b9c864f589bbF53a82105107622B35EaA40',
faucetAmount: 1000,
faucetTokens: [
{
donorAccount: '0xD533Ca259b330c7A88f74E000a3FaEa2d63B7972',
Expand All @@ -139,6 +136,7 @@ export const commonConfig: AppConfig = {
],
},
ui: {
showSimulator: true,
priceChart: 'native',
useGradientBranding: true,
tradeCount: true,
Expand Down
4 changes: 1 addition & 3 deletions src/config/configSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export const AppConfigSchema = v.object({
selectedConnectors: ConnectorSchema,
blockedConnectors: v.optional(ConnectorSchema),
walletConnectProjectId: v.string(),
isSimulatorEnabled: v.boolean(),
sentryDSN: v.optional(v.string()),
policiesLastUpdated: v.optional(v.string()),
network: v.object({
Expand Down Expand Up @@ -93,8 +92,6 @@ export const AppConfigSchema = v.object({
),
]),
tenderly: v.object({
nativeTokenDonorAccount: v.string(),
faucetAmount: v.number(),
faucetTokens: v.array(
v.object({
decimals: v.number(),
Expand All @@ -105,6 +102,7 @@ export const AppConfigSchema = v.object({
),
}),
ui: v.object({
showSimulator: v.boolean(),
priceChart: v.union([v.literal('native'), v.literal('tradingView')]),
useGradientBranding: v.optional(v.boolean()),
tradeCount: v.optional(v.boolean()),
Expand Down
36 changes: 6 additions & 30 deletions src/config/demo/common.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
import { AppConfig } from 'config/types';

const addresses = {
ZERO: '0x0000000000000000000000000000000000000000',
};

export const commonConfig: AppConfig = {
hidden: true,
mode: 'development',
appName: '',
appUrl: '',
carbonApi: '',
selectedConnectors: ['MetaMask'],
blockedConnectors: [],
walletConnectProjectId: '',
isSimulatorEnabled: false,
policiesLastUpdated: '',
network: {
name: 'Demo Network',
Expand All @@ -24,7 +18,7 @@ export const commonConfig: AppConfig = {
url: '',
},
rpc: {
url: import.meta.env.VITE_CHAIN_RPC_URL,
url: import.meta.env.VITE_CHAIN_RPC_URL ?? '',
},
defaultLimitedApproval: true,
gasToken: {
Expand All @@ -45,7 +39,9 @@ export const commonConfig: AppConfig = {
quote: [],
},
addresses: {
tokens: addresses,
tokens: {
ZERO: '0x0000000000000000000000000000000000000000',
},
carbon: {
carbonController: '',
voucher: '',
Expand All @@ -60,30 +56,10 @@ export const commonConfig: AppConfig = {
tokenListOverride: [],
tokenLists: [],
tenderly: {
nativeTokenDonorAccount: '',
faucetAmount: 1000,
faucetTokens: [
{
donorAccount: '',
tokenContract: '',
decimals: 18,
symbol: '',
},
{
donorAccount: '',
tokenContract: '',
decimals: 6,
symbol: '',
},
{
donorAccount: '',
tokenContract: '',
decimals: 6,
symbol: '',
},
],
faucetTokens: [],
},
ui: {
showSimulator: false,
priceChart: 'tradingView',
useGradientBranding: false,
tradeCount: false,
Expand Down
4 changes: 1 addition & 3 deletions src/config/ethereum/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const commonConfig: AppConfig = {
selectedConnectors: ['MetaMask', 'WalletConnect', 'Coinbase Wallet', 'Safe'],
blockedConnectors: ['Tailwind', 'Compass Wallet', 'Seif'],
walletConnectProjectId: 'f9d8863ab6c03f2293d7d56d7c0c0853',
isSimulatorEnabled: true,
policiesLastUpdated: '18 April, 2023',
network: {
name: 'Ethereum Network',
Expand Down Expand Up @@ -148,8 +147,6 @@ export const commonConfig: AppConfig = {
},
],
tenderly: {
nativeTokenDonorAccount: '0x00000000219ab540356cbb839cbe05303d7705fa',
faucetAmount: 1000,
faucetTokens: [
{
donorAccount: '0x0a59649758aa4d66e25f08dd01271e891fe52199',
Expand Down Expand Up @@ -214,6 +211,7 @@ export const commonConfig: AppConfig = {
],
},
ui: {
showSimulator: true,
priceChart: 'native',
useGradientBranding: true,
tradeCount: false,
Expand Down
4 changes: 1 addition & 3 deletions src/config/sei/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ export const commonConfig: AppConfig = {
],
blockedConnectors: ['Tailwind'],
walletConnectProjectId: '',
isSimulatorEnabled: true,
policiesLastUpdated: '27 May, 2024',
network: {
name: 'Sei Network',
Expand Down Expand Up @@ -91,8 +90,6 @@ export const commonConfig: AppConfig = {
},
],
tenderly: {
nativeTokenDonorAccount: '0x3a7AB16485770c21B7543058De545E986284d0D3',
faucetAmount: 1000,
faucetTokens: [
{
donorAccount: '0x06b49C508f278a9219a6e45A7bcEbBC0aA1E2e7b',
Expand All @@ -115,6 +112,7 @@ export const commonConfig: AppConfig = {
],
},
ui: {
showSimulator: true,
priceChart: 'native',
useGradientBranding: true,
tradeCount: true,
Expand Down
2 changes: 1 addition & 1 deletion src/libs/routing/routes/sim.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const simulatorInputRootRoute = createRoute({
path: '/',
component: SimulatorPage,
beforeLoad: ({ location }) => {
if (!config.isSimulatorEnabled) {
if (!config.ui.showSimulator) {
throw redirect({ to: '/', replace: true });
}
if (
Expand Down
2 changes: 1 addition & 1 deletion src/libs/wagmi/wagmi.constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { tenderlyRpc } from 'utils/tenderly';

const IS_ENV_RPC = !!import.meta.env.VITE_CHAIN_RPC_URL;
const CHAIN_RPC_URL =
tenderlyRpc || import.meta.env.VITE_CHAIN_RPC_URL || config.network.rpc.url;
tenderlyRpc || config.network.rpc.url || import.meta.env.VITE_CHAIN_RPC_URL;
const CHAIN_RPC_HEADERS =
tenderlyRpc || IS_ENV_RPC ? {} : config.network.rpc?.headers || {};
export const CHAIN_ID = config.network.chainId;
Expand Down

0 comments on commit 6ac72ba

Please sign in to comment.