Skip to content

Commit

Permalink
Implement CSV Grain Integration Plugin (#3078)
Browse files Browse the repository at this point in the history
This plugin outputs a csv file. Each row contains a payout address in
the first column and the raw amount to be paid in the second column.

The file content is returned to SourceCred, which will handle file I/O
on behalf of plugins.

grain integrations shall be prefixed in their package.json files with
`sc-grainIntegration-*` this will allow for grouping and filtering using
lerna and allow for a clean change in the scope of concerns.

The output is optimized for https://disperse.app

test plan: unit tests are provided
  • Loading branch information
topocount committed Aug 16, 2021
1 parent 9f11c25 commit 3d3eb21
Show file tree
Hide file tree
Showing 13 changed files with 1,415 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# dependencies
/node_modules

**/node_modules
# testing
/coverage

Expand All @@ -27,5 +27,5 @@
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log
.DS_Store

19 changes: 19 additions & 0 deletions packages/grainIntegration-csv/.babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @flow

const presets = [
[
"@babel/preset-env",
{
targets: {
edge: "17",
firefox: "60",
chrome: "67",
safari: "11.1",
node: true,
},
},
],
"@babel/preset-flow",
];

module.exports = { presets };
55 changes: 55 additions & 0 deletions packages/grainIntegration-csv/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// @flow
module.exports = {
parser: "babel-eslint",
plugins: ["flowtype", "react"],
env: {
browser: true,
es6: true,
node: true,
jest: true,
},
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
ecmaFeatures: {
jsx: true,
},
},
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:flowtype/recommended",
],
rules: {
"prefer-const": ["warn"],
camelcase: [
"error",
{properties: "never", allow: ["^_unused_.*", "(_\\d+)+"]},
],
eqeqeq: ["error", "always", {null: "ignore"}],
"no-unused-vars": [
"warn",
{
argsIgnorePattern: "^_$|^_unused_",
varsIgnorePattern: "^_$|^_unused_",
caughtErrorsIgnorePattern: "^_$|^_unused_",
},
],
"no-constant-condition": ["warn", {checkLoops: false}],
"no-inner-declarations": ["off"],
"no-use-before-define": ["off"],
"no-useless-constructor": ["off"],
"no-case-declarations": ["off"],
"react/prop-types": ["off"],
"flowtype/generic-spacing": ["off"],
"flowtype/space-after-type-colon": ["off"],
},
settings: {
react: {
version: "detect",
},
},
globals: {
BigInt: "readonly",
},
};
14 changes: 14 additions & 0 deletions packages/grainIntegration-csv/.flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# If modifying this file, please modify .flowconfig-ci too!
[ignore]

[include]

[libs]
flow-typed

[lints]

[options]
include_warnings=true

[strict]
16 changes: 16 additions & 0 deletions packages/grainIntegration-csv/.flowconfig-ci
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# If modifying this file, please modify .flowconfig too!
[ignore]

[include]

[libs]
flow-typed

[lints]

[options]
include_warnings=true
server.max_workers=1
types_first=false

[strict]
12 changes: 12 additions & 0 deletions packages/grainIntegration-csv/distributionToCsv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @flow

/*:: type PayoutDistributions = $ReadOnlyArray<[string, string]>;*/
module.exports = function payoutDistributionToCsv(
payoutDistributions /*: PayoutDistributions*/
) /*: string*/ {
let csvString = "";
for (const [payoutAddress, amount] of payoutDistributions) {
csvString += `${payoutAddress},${amount}\n`;
}
return csvString;
};
Loading

0 comments on commit 3d3eb21

Please sign in to comment.