Skip to content

Commit 0993e6c

Browse files
committed
updates batch
1 parent bff7ed3 commit 0993e6c

File tree

3 files changed

+75
-53
lines changed

3 files changed

+75
-53
lines changed

__tests__/Batch/batch.test.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
import { convertPayoutScheduleToBigInt } from '../../lib/batchUtils'
1+
import { convertPayoutScheduleToBigInt } from '../../lib/batchUtils';
22

33
describe('Batch Mint', () => {
44
it('should pass', async () => {
5-
const payoutScheduleString = '[375.0, 375.0, 375.0, 375.0, 750.0, 750.0, 750.0, 750.0, 833.33, 833.33, 833.33]'
6-
7-
const convertedToBigInt = convertPayoutScheduleToBigInt(payoutScheduleString, 6)
5+
const payoutScheduleString = '[375.0, 375.0, 375.0, 375.0, 750.0, 750.0, 750.0, 750.0, 833.33, 833.33, 833.33]';
86

9-
expect(convertedToBigInt.toString()).toEqual('375000000,375000000,375000000,375000000,750000000,750000000,750000000,750000000,833330000,833330000,833330000');
7+
const convertedToBigInt = convertPayoutScheduleToBigInt(payoutScheduleString, 6);
8+
9+
expect(convertedToBigInt.toString()).toEqual(
10+
'375000000,375000000,375000000,375000000,750000000,750000000,750000000,750000000,833330000,833330000,833330000'
11+
);
1012
});
1113
});

lib/batchUtils.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
import { ethers } from 'ethers';
22

3+
const convertCsvToJson = (csvData) => {
4+
const headers = csvData[0];
5+
const rows = csvData.slice(1);
6+
const jsonData = rows.map((row) => {
7+
const jsonObject = {};
8+
row.forEach((cell, index) => {
9+
jsonObject[headers[index]] = cell;
10+
});
11+
return jsonObject;
12+
});
13+
return jsonData;
14+
};
15+
316
const convertPayoutScheduleToBigInt = (payoutSchedule, decimals) => {
4-
const payoutScheduleParsed = payoutSchedule && JSON.parse(payoutSchedule);
17+
const payoutScheduleParsed = payoutSchedule && JSON.parse(payoutSchedule);
518

6-
const newPayoutSchedule = payoutScheduleParsed.map((tierVolume) => {
7-
let formattedVolume = tierVolume * 10 ** decimals;
8-
return ethers.BigNumber.from(formattedVolume.toLocaleString('fullwide', { useGrouping: false }));
9-
});
19+
const newPayoutSchedule = payoutScheduleParsed.map((tierVolume) => {
20+
let formattedVolume = tierVolume * 10 ** decimals;
21+
return ethers.BigNumber.from(formattedVolume.toLocaleString('fullwide', { useGrouping: false }));
22+
});
1023

11-
return newPayoutSchedule;
12-
}
24+
return newPayoutSchedule;
25+
};
1326

14-
const convertCsvToJson = (csvData) => {
15-
const headers = csvData[0];
16-
const rows = csvData.slice(1);
17-
const jsonData = rows.map((row) => {
18-
const jsonObject = {};
19-
row.forEach((cell, index) => {
20-
jsonObject[headers[index]] = cell;
21-
});
22-
return jsonObject;
23-
});
24-
return jsonData;
27+
const abiEncodeTieredFixed = (initializationData) => {
28+
let abiCoder = new ethers.utils.AbiCoder();
29+
const initializationSchema = ['uint256[]', 'address', 'bool', 'bool', 'bool', 'string', 'string', 'string'];
30+
31+
console.log(initializationData);
32+
33+
const tieredFixedEncoded = abiCoder.encode(initializationSchema, initializationData);
34+
35+
let tieredFixed = [3, `\"${tieredFixedEncoded}\"`];
36+
37+
return tieredFixed;
2538
};
2639

27-
export { convertPayoutScheduleToBigInt, convertCsvToJson }
40+
export { convertPayoutScheduleToBigInt, convertCsvToJson, abiEncodeTieredFixed };

pages/batch.js

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { useState, useContext, useEffect } from 'react';
2-
import Papa from 'papaparse';
32
import { ethers } from 'ethers';
3+
import Papa from 'papaparse';
44
import StoreContext from '../store/Store/StoreContext';
55
import _ from 'lodash';
66
import mintBountyTemplate from '../constants/mintBountyTemplate.json';
@@ -9,7 +9,7 @@ import md4 from 'js-md4';
99
import Link from 'next/link';
1010
import Image from 'next/image';
1111
import BountyCardLean from '../components/BountyCard/BountyCardLean';
12-
import { convertCsvToJson, convertPayoutScheduleToBigInt } from '../lib/batchUtils'
12+
import { convertCsvToJson, convertPayoutScheduleToBigInt, abiEncodeTieredFixed } from '../lib/batchUtils';
1313

1414
function Batch() {
1515
const [mintBountyBatchData, setMintBountyBatchData] = useState(null);
@@ -18,6 +18,9 @@ function Batch() {
1818
const { accountData } = appState;
1919
const [file, setFile] = useState(null);
2020

21+
let abiCoder = new ethers.utils.AbiCoder();
22+
const initializationSchema = ['uint256[]', 'address', 'bool', 'bool', 'bool', 'string', 'string', 'string'];
23+
2124
const handleCopyToClipboard = () => {
2225
navigator.clipboard.writeText(JSON.stringify(mintBountyBatchData));
2326
};
@@ -37,21 +40,23 @@ function Batch() {
3740
document.body.removeChild(element);
3841
};
3942

40-
let abiCoder = new ethers.utils.AbiCoder();
41-
const initializationSchema = ['uint256[]', 'address', 'bool', 'bool', 'bool', 'string', 'string', 'string'];
42-
43-
const loadGithubData = async (githubIssueUrl) => {
44-
const resource = await appState.githubRepository.fetchIssueByUrl(githubIssueUrl);
45-
const githubSponsorResource = await appState.githubRepository.getOrgByUrl(githubSponsorUrl);
43+
const loadGithubData = async (githubIssueUrl, githubSponsorUrl) => {
44+
const resource = await appState.githubRepository.fetchIssueByUrl(githubIssueUrl);
45+
const githubSponsorResource = await appState.githubRepository.getOrgByUrl(githubSponsorUrl);
4646

47-
const bountyId = resource.id;
48-
const organizationId = resource.repository.owner.id;
47+
const bountyId = resource.id;
48+
const organizationId = resource.repository.owner.id;
4949

50-
const sponsorOrganizationName = githubSponsorResource.login;
51-
const sponsorOrganizationLogo = githubSponsorResource.avatarUrl;
50+
const sponsorOrganizationName = githubSponsorResource.login;
51+
const sponsorOrganizationLogo = githubSponsorResource.avatarUrl;
5252

53-
return { bountyId, organizationId, sponsorOrganizationName, sponsorOrganizationLogo};
54-
}
53+
return {
54+
bountyId,
55+
organizationId,
56+
sponsorOrganizationName,
57+
sponsorOrganizationLogo,
58+
};
59+
};
5560

5661
const handleFileUpload = (event) => {
5762
const file = event.target.files[0];
@@ -67,8 +72,6 @@ function Batch() {
6772
// Populate the transaction template
6873
const transactions = [];
6974

70-
console.log('jsonData', jsonData);
71-
7275
for (const transactionData of jsonData) {
7376
const {
7477
githubIssueUrl,
@@ -81,19 +84,16 @@ function Batch() {
8184
} = transactionData;
8285

8386
try {
84-
const { decimals } = await appState.tokenClient.getToken(payoutTokenAddress);
85-
86-
const newPayoutSchedule = convertPayoutScheduleToBigInt(payoutSchedule, decimals);
87+
const { decimals } = await appState.tokenClient.getToken(payoutTokenAddress);
88+
console.log('decimals', decimals)
8789

88-
// Fetch Github Issue ID and Organization ID
89-
const { bountyId, organizationId, sponsorOrganizationName, sponsorOrganizationLogo } = await loadGithubData(githubIssueUrl)
90+
const newPayoutSchedule = convertPayoutScheduleToBigInt(payoutSchedule, decimals);
9091

91-
// Overwrite contractInputsValues on mintBountyTransactionTemplate
92-
const mintBountyTransactionTemplateCopy = _.cloneDeep(mintBountyTransactionTemplate);
93-
94-
mintBountyTransactionTemplateCopy.contractInputsValues._bountyId = bountyId;
95-
mintBountyTransactionTemplateCopy.contractInputsValues._organization = organizationId;
96-
mintBountyTransactionTemplateCopy.to = process.env.NEXT_PUBLIC_OPENQ_PROXY_ADDRESS;
92+
// Fetch Github Issue ID and Organization ID
93+
const { bountyId, organizationId, sponsorOrganizationName, sponsorOrganizationLogo } = await loadGithubData(
94+
githubIssueUrl,
95+
githubSponsorUrl
96+
);
9797

9898
const initializationData = [
9999
newPayoutSchedule,
@@ -106,9 +106,14 @@ function Batch() {
106106
sponsorOrganizationLogo,
107107
];
108108

109-
const tieredFixedEncoded = abiCoder.encode(initializationSchema, initializationData);
110-
let tieredFixed = [3, `\"${tieredFixedEncoded}\"`];
109+
let tieredFixed = abiEncodeTieredFixed(initializationData);
111110

111+
// Overwrite contractInputsValues on mintBountyTransactionTemplate
112+
const mintBountyTransactionTemplateCopy = _.cloneDeep(mintBountyTransactionTemplate);
113+
114+
mintBountyTransactionTemplateCopy.contractInputsValues._bountyId = bountyId;
115+
mintBountyTransactionTemplateCopy.contractInputsValues._organization = organizationId;
116+
mintBountyTransactionTemplateCopy.to = process.env.NEXT_PUBLIC_OPENQ_PROXY_ADDRESS;
112117
mintBountyTransactionTemplateCopy.contractInputsValues._initOperation = `[${tieredFixed}]`;
113118

114119
transactions.push(mintBountyTransactionTemplateCopy);
@@ -119,6 +124,7 @@ function Batch() {
119124

120125
const mintBountyTemplateCopy = _.cloneDeep(mintBountyTemplate);
121126
mintBountyTemplateCopy.transactions = transactions;
127+
console.log(transactions);
122128

123129
setMintBountyBatchData(mintBountyTemplateCopy);
124130
};
@@ -134,6 +140,7 @@ function Batch() {
134140

135141
const [payoutSchedule, payoutTokenAddress, , , , , sponsorOrganizationName, sponsorOrganizationLogo] =
136142
abiCoder.decode(initializationSchema, initializationOp);
143+
137144
return {
138145
...githubData,
139146
payoutSchedule,

0 commit comments

Comments
 (0)