11import React , { useState , useContext , useEffect } from 'react' ;
2- import Papa from 'papaparse' ;
32import { ethers } from 'ethers' ;
3+ import Papa from 'papaparse' ;
44import StoreContext from '../store/Store/StoreContext' ;
55import _ from 'lodash' ;
66import mintBountyTemplate from '../constants/mintBountyTemplate.json' ;
@@ -9,7 +9,7 @@ import md4 from 'js-md4';
99import Link from 'next/link' ;
1010import Image from 'next/image' ;
1111import BountyCardLean from '../components/BountyCard/BountyCardLean' ;
12- import { convertCsvToJson , convertPayoutScheduleToBigInt } from '../lib/batchUtils'
12+ import { convertCsvToJson , convertPayoutScheduleToBigInt , abiEncodeTieredFixed } from '../lib/batchUtils' ;
1313
1414function 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