Add valid dapps to config

This commit is contained in:
Richard Ramos 2019-11-18 14:59:25 -04:00
parent abc4993d4b
commit 8573c5f0f2
6 changed files with 13 additions and 11 deletions

View File

@ -27,11 +27,12 @@ yarn
- `SENDGRID_API_KEY`: To send emails.
- `BLOCK_DELAY`: Adds a delay in the number of blocks to avoid reorgs. (default: `6`)
- `POLL_SLEEP`: Interval of time wait for polling the chain for new events. (default: `30`)
- `VALID_DAPPS`: Array with known dapps in `dapps/` folder
The `ENV` variable can be used to set these variables, as well as a `.secret.json` file.
#### Dapp
Each dapp should have their own configuration and templates to send emails. To add a dapp, create a folder inside `./dapps/` with the dapp name. Also, edit `./dapps-config.js` lines 10 and 16 to add the new dapp. (**This will change with a proper dapp registry, to avoid this manual process**)
Each dapp should have their own configuration and templates to send emails. To add a dapp, create a folder inside `./dapps/` with the dapp name. Also, edit `./config/index.js` to add the new dapp in `VALID_DAPPS`. (**This will change with a proper dapp registry, to avoid this manual process**)
Each dapp folder should have a `config.js` file and one or more .html and .txt templates. See `./dapps/teller-network/config.js` for a sample config.

View File

@ -13,7 +13,7 @@ const Controller = require("./controller");
const logger = require("../logger")('api');
const events = new Events();
const dappConfig = new DappConfig();
const dappConfig = new DappConfig(config);
const mailer = new Mailer(config, logger);
const db = new Database(events, config);

View File

@ -21,7 +21,8 @@ const config = {
SENDGRID_API_KEY: secret.SENDGRID_API_KEY,
/* Watcher */
BLOCK_DELAY: 6, // [Recommended 6 ~80 secs...] this could be helpful to avoid reorgs
POLL_SLEEP: 30 // seconds
POLL_SLEEP: 30, // seconds
VALID_DAPPS: ['teller-network']
};
module.exports = config;

View File

@ -1,19 +1,17 @@
const path = require("path");
const fs = require("fs");
class DAppConfig {
constructor(){
constructor(config){
this.configurations = {};
this.appConfig = config;
}
isDapp(dappId) {
// TODO:
if (dappId === "teller-network") return true;
return false;
return this.appConfig.VALID_DAPPS.indexOf(dappId) > -1;
}
getDapps(){
// TODO:
return ['teller-network'];
return this.appConfig.VALID_DAPPS;
}
config(dappId) {

View File

@ -21,7 +21,8 @@ class Ethereum {
this.events.emit("web3:connected");
})
.catch(error => {
logger.error("DB - ", err);
console.log(error);
logger.error("web3 - ", error);
process.exit(1);
});
}

View File

@ -7,8 +7,9 @@ const Mailer = require("../mail/sendgrid");
const DappConfig = require("../dapp-config");
const Subscribers = require("../models/subscribers");
const logger = require("../logger")('watcher');
const events = new Events();
const dappConfig = new DappConfig();
const dappConfig = new DappConfig(config);
const mailer = new Mailer(config);
const db = new Database(events, config);
const eth = new Ethereum(events, config);