Skip to content

Commit ce86e6c

Browse files
anxolinalfetopito
andcommitted
App id miscelaneus (gnosis#1267)
* Remove fuse reference * Move appId to the root of the config * Override config with envs * Define a max app id for validation * Define env overrides for config * Move validation to override env conf * Remove default appId from config * Fix error in message * Improve message * Give it more space Co-authored-by: Leandro Boscariol <[email protected]> Co-authored-by: Leandro Boscariol <[email protected]>
1 parent 69e0b81 commit ce86e6c

File tree

9 files changed

+89
-10
lines changed

9 files changed

+89
-10
lines changed

config-default.yaml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,32 @@
11
#######################################################################################
22
## DEFAULT CONFIG ##
33
#######################################################################################
4-
# - Defines the default configuration
5-
# - **WARNING**: Do not modify this file
6-
# - For custom config create a new file "custom/config.yaml"
7-
# - You can override in the custom file any config that is defined here
8-
# - For redefining components, or for more information, follow the instructions in ./README.md
9-
4+
# Defines the default configuration
5+
# 🚫 WARNING 🚫: Do not modify this file
6+
# - For custom config create a new file "custom/config.yaml"
7+
# - You can override in the custom file any config that is defined here
8+
# - For redefining components, or for more information, follow the instructions in ./README.md
9+
# ⚙️Read more here:
10+
# https://github.com/gnosis/dex-react/wiki/Config
11+
12+
# App Id
13+
# Identify the app. The IDs range from 1 until 256
14+
# Every transaction sent to the blockchain will include the ID and some basic analytic info
15+
#
16+
# ⚠️IMPORTANT: The ID must be unique per App/Client of Gnosis Protocol:
17+
# https://github.com/gnosis/dex-react/wiki/App-Ids-for-Forks
18+
# More information about forking the web:
19+
# https://github.com/gnosis/dex-react/wiki/Fork-project
20+
#
21+
#appId: 1
22+
23+
# Name of the app
1024
name: Gnosis Protocol Web
1125

26+
# Logo used for the favicon
1227
logoPath: './src/assets/img/logo.svg'
1328

29+
# HTML template
1430
templatePath: './src/html/index.html'
1531

1632
# Whitelisted tokens from Gnosis Contract retrieved from a smart contract
@@ -89,7 +105,7 @@ disabledTokens:
89105
description: This token is disabled for trading and depositing. SNX will be deprecated and replaced by another token at the end of July 2020. Go to https://www.synthetix.io for more information
90106
reason: DEPRECATED
91107
url: https://docs.synthetix.io/integrations/guide/#proxy-deprecation
92-
108+
93109
- address: '0x45804880De22913dAFE09f4980848ECE6EcbAf78'
94110
name: Paxos Gold
95111
symbol: PAXG

jest.config.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
const config = require('./src/loadConfig')(true)
1+
const loadConfig = require('./src/loadConfig')
2+
const overrideEnvConfig = require('./src/overrideEnvConfig')
3+
4+
const config = overrideEnvConfig(loadConfig(true))
25

36
module.exports = {
47
roots: ['<rootDir>/test'],

src/components/Layout/Footer.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ const Footer: React.FC = () => {
148148
<a target="_blank" rel="noopener noreferrer" href={'https://github.com/gnosis/dex-react/tree/v' + VERSION}>
149149
v{VERSION}
150150
</a>{' '}
151+
-{' '}
152+
<a target="_blank" rel="noopener noreferrer" href="https://github.com/gnosis/dex-react/wiki/App-Ids-for-Forks">
153+
App Id: {CONFIG.appId}
154+
</a>{' '}
151155
- Contracts{' '}
152156
<a
153157
target="_blank"

src/const.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export const BATCH_SUBMISSION_CLOSE_TIME = 4 // in minutes
3737

3838
export const MINIMUM_ALLOWANCE_DECIMALS = 10
3939

40+
// Max App Id: Read more here:
41+
// https://github.com/gnosis/dex-react/wiki/App-Ids-for-Forks
42+
export const MAX_APP_ID = 255
43+
4044
export const APP_NAME = 'Gnosis Protocol Web'
4145

4246
export const ETHER_PNG =

src/overrideEnvConfig.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const MAX_APP_ID = 255
2+
const DEFAULT_DEV_APP_ID = 1
3+
const IS_DEV = process.env.NODE_ENV === 'development' || process.env.NODE_ENV === 'test'
4+
5+
function getAppId(config) {
6+
const appId = Number(process.env.APP_ID || config.appId || (IS_DEV ? DEFAULT_DEV_APP_ID : undefined))
7+
8+
let error
9+
if (!appId) {
10+
error = 'The appId config, or APP_ID environment variable is required'
11+
} else {
12+
if (!Number.isInteger(appId) || appId < 1 || appId > MAX_APP_ID) {
13+
error = `appId config or APP_ID environment variable isn't valid. Expected a positive integer <= ${MAX_APP_ID}, got ${appId}`
14+
}
15+
}
16+
17+
if (error) {
18+
throw new Error(error + '. Read more in https://github.com/gnosis/dex-react/wiki/App-Ids-for-Forks')
19+
}
20+
21+
return appId
22+
}
23+
24+
function overrideEnvConfig(config) {
25+
return {
26+
...config,
27+
appId: getAppId(config),
28+
}
29+
}
30+
31+
module.exports = overrideEnvConfig

src/types/config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ export interface DisabledTokens {
5757
}
5858

5959
export interface Config {
60+
appId: number
6061
name: string
6162
logoPath: string
6263
templatePath: string

src/utils/flagCodes.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,19 @@ export interface Flag<T extends string> {
77
}
88

99
// OUR specific flags
10+
const FIXED_SENTINEL = 'dec0de'
11+
1012
// lowercase hex value to be appended to tx.data
11-
const SENTINEL = 'dec0de'
13+
const SENTINEL =
14+
FIXED_SENTINEL +
15+
Number(CONFIG.appId)
16+
.toString(16)
17+
.padStart(2, '0')
18+
console.log('SENTINEL', SENTINEL)
19+
20+
if (!/^[0-9a-f]+$/.test(SENTINEL)) {
21+
throw new Error(`SENTINEL isn't valid. Expected lowercase hex value, got ${SENTINEL}`)
22+
}
1223

1324
type DxFlagName = 'provider' | 'mobile' | 'browser' | 'screenSize'
1425

test/config.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,16 @@ import {
66
ExchangeContractConfig,
77
} from 'types/config'
88
import { Network } from 'types'
9+
import { MAX_APP_ID } from 'const'
910

1011
describe('Test config defaults', () => {
12+
it('appId', () => {
13+
expect(CONFIG.appId).toEqual(expect.any(Number))
14+
expect(Number.isInteger(CONFIG.appId)).toBe(true)
15+
expect(CONFIG.appId).toBeGreaterThanOrEqual(1)
16+
expect(CONFIG.appId).toBeLessThanOrEqual(MAX_APP_ID)
17+
})
18+
1119
it('name', () => {
1220
expect(CONFIG.name).toEqual('Gnosis Protocol Web')
1321
})

webpack.config.babel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import path from 'path'
1010

1111
import dotenv from 'dotenv'
1212
import loadConfig from './src/loadConfig'
13+
import overrideEnvConfig from './src/overrideEnvConfig'
1314

1415
// Setup env vars
1516
dotenv.config()
1617

1718
const isProduction = process.env.NODE_ENV == 'production'
1819

1920
const baseUrl = isProduction ? '' : '/'
20-
const config = loadConfig()
21+
const config = overrideEnvConfig(loadConfig())
2122
const { name: appName } = config
2223

2324
module.exports = ({ stats = false } = {}) => ({

0 commit comments

Comments
 (0)