5afe / safe-react

Deprecated! New repo – https://github.com/safe-global/web-core
MIT License
332 stars 363 forks source link

[xDai] - Create "generic network configuration" #1414

Closed fernandomg closed 4 years ago

fernandomg commented 4 years ago

The aim of this task is to create a configuration setup that will ease the addition of networks to the Safe.

an initial sketch:

const xDai = {
  dev: {},
  staging: {},
  production: {
    NETWORK_LABEL: 'xDai STAKE',
    NETWORK_COLOR: '#48A8A6',
    NETWORK_ID: 100,
    // mocks the structure of `Token` in `src/logic/tokens/store/model/token.ts`
    NATIVE_COIN: {
      // address mocks the ETH_ADDRESS in `src/logic/tokens/utils/tokenHelpers.ts`
      address: '0x000',
      name: 'xDai',
      symbol: 'xDai',
      decimals: 18,
      logoUri: '',
    },
    // something around this to display or not some critical sections in the app, depending on the network support
    // I listed the ones that may conflict with the network.
    // If non is present, all the sections are available.
    DISABLE: {
      SAFE_APPS: true,
      COLLECTIBLES: true,
      CONTRACT_INTERACTION: true,
    },
    TX_SERVICE_HOST: 'https://safe-transaction.xdai.gnosis.io/api/v1/',
    // Shall we keep a reference to the relay?
    RELAY_API_URL: null,
    // won't be used in xDai, for the first iteration
    SAFE_APPS_URL: null,
    // mainnet+rinkeby: ethgasstation,
    // xDai: Ask Richard about the oracle for the gasPrice
    GAS_PRICE_ORACLE_URL: '',
    // mainnet+rinkeby: infura,
    //    for infura there's a REST API Token required stored in: `REACT_APP_INFURA_TOKEN`
    // xDai: `rpc.xdaichain.com` among others
    //    see: https://www.xdaichain.com/for-developers/developer-resources#json-rpc-endpoints
    RPC_SERVICE_URL: '',
    // mainnet+rinkeby uses etherscan,
    // xDai uses:
    //  - `blockscout.com/poa/xdai/api`
    //  - `blockscout.com/poa/xdai/api/eth-rpc`
    //        This API is provided to support some rpc methods
    //        in the exact format specified for ethereum nodes
    NETWORK_EXPLORER_URL: '',
  },
}

An example of how the current configurations would look with the said "generic network configuration".

const mainnet = {
  dev: {
    [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.staging.gnosisdev.com/api/v1/',
    [RELAY_API_URL]: 'https://safe-relay.mainnet.staging.gnosisdev.com/api/v1/',
    [SAFE_APPS_URL]: 'https://safe-apps.dev.gnosisdev.com/',
  },
  staging: {
    [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.staging.gnosisdev.com/api/v1/',
    [RELAY_API_URL]: 'https://safe-relay.mainnet.staging.gnosisdev.com/api/v1/',
    [SAFE_APPS_URL]: 'https://safe-apps.staging.gnosisdev.com',
  },
  production: {
    [TX_SERVICE_HOST]: 'https://safe-transaction.mainnet.gnosis.io/api/v1/',
    [RELAY_API_URL]: 'https://safe-relay.gnosis.io/api/v1/',
    [SAFE_APPS_URL]: 'https://apps.gnosis-safe.io/',
  },
}

Finally, the env variables (the ones listed in the .env.example file), need to be revisited along with this change too.

A commented list of the env vars:

/*
 * .env file
 */
const envVariables = {
  // mainnet | rinkeby | xdai | ewc | volta
  // defaults to? rinkeby
  REACT_APP_NETWORK: '',

  // should we add analytics_ids for every network?
  REACT_APP_GOOGLE_ANALYTICS_ID_RINKEBY: '',
  REACT_APP_GOOGLE_ANALYTICS_ID_MAINNET: '',

  // we should add the required tokens for every RPC that requires one.
  REACT_APP_INFURA_TOKEN: '',

  REACT_APP_IPFS_GATEWAY: '',
  PUBLIC_URL: '',
  REACT_APP_BLOCKNATIVE_KEY: '',
  REACT_APP_INTERCOM_ID: '',
  REACT_APP_PORTIS_ID: '',
  REACT_APP_SQUARELINK_ID: '',
  REACT_APP_FORTMATIC_KEY: '',

  // This will be deprecated in favor of gnosis tx-service, see https://github.com/gnosis/safe-react/issues/1408
  REACT_APP_OPENSEA_API_KEY: '',
  // OpenSea | gnosis?
  REACT_APP_COLLECTIBLES_SOURCE: '',

  // we should add required tokens ver every explorer that requires one.
  REACT_APP_ETHERSCAN_API_KEY: '',

  REACT_APP_LATEST_SAFE_VERSION: '',
  REACT_APP_APP_VERSION: '',

  // depends on REACT_APP_GNOSIS_APPS_URL_PROD and REACT_APP_GNOSIS_APPS_URL_STAGING. See .travis.yml
  // also is used in .github/workflows/release.yml
  REACT_APP_GNOSIS_APPS_URL: '',
}
fernandomg commented 4 years ago

Maybe adding one more level to the configs makes a bit more sense (added environments and generics).

/*
 * xDai
 */
const xDai = {
  network: {
    ID: 100,
    COLOR: '#48A8A6',
    LABEL: 'xDai STAKE',
    // mocks the structure of `Token` in `src/logic/tokens/store/model/token.ts`
    NATIVE_COIN: {
      // address mocks the ETH_ADDRESS in `src/logic/tokens/utils/tokenHelpers.ts`
      address: '0x000',
      name: 'xDai',
      symbol: 'xDai',
      decimals: 18,
      logoUri: '',
    },
  },
  /*
  feature: {
    // something around this to display or not some critical sections in the app, depending on the network support
    // I listed the ones that may conflict with the network.
    // If non is present, all the sections are available.
    DISABLE: {
      SAFE_APPS: true,
      COLLECTIBLES: true,
      CONTRACT_INTERACTION: true,
    },
  },
  */
  environment: {
    dev: {},
    staging: {},
    production: {
      TX_SERVICE_HOST: 'https://safe-transaction.xdai.gnosis.io/api/v1/',
      // Shall we keep a reference to the relay?
      RELAY_API_URL: null,
      // won't be used in xDai, for the first iteration
      SAFE_APPS_URL: null,
      // mainnet+rinkeby: ethgasstation,
      // xDai: Ask Richard about the oracle for the gasPrice
      GAS_PRICE_ORACLE_URL: '',
      // mainnet+rinkeby: infura,
      //      for infura there's a REST API Token required stored in: `REACT_APP_INFURA_TOKEN`
      // xDai: `rpc.xdaichain.com` among others
      //      see: https://www.xdaichain.com/for-developers/developer-resources#json-rpc-endpoints
      RPC_SERVICE_URL: '',
      // mainnet+rinkeby uses etherscan,
      // xDai uses:
      //  - `blockscout.com/poa/xdai/api`
      //  - `blockscout.com/poa/xdai/api/eth-rpc`
      //        This API is provided to support some rpc methods
      //        in the exact format specified for ethereum nodes
      NETWORK_EXPLORER_URL: '',
    },
  }
}