@@ -47,7 +47,6 @@ export async function connectWeb3() {
4747 }
4848 } catch ( error ) {
4949 // Catch any errors for any of the above operations.
50- //todo: display a graphical error message
5150 alert ( 'Failed to load web3, accounts, or contract. Check console for details.' ) ;
5251 console . error ( error ) ;
5352 }
@@ -105,42 +104,29 @@ export async function getLockEvents(web3: Web3, instance: Contract): Promise<Loc
105104 // this value can be set as the block number of where the contract was deployed
106105 const startBlock = 0 ;
107106 try {
108- const ev = await instance . getPastEvents ( 'allEvents' , {
109- filter : { event : 'Locked' } ,
110- fromBlock : startBlock ,
111- toBlock : 'latest' ,
112- } ) ;
113- ev . map ( i => {
114- //console.log(i);
115- const e = i . returnValues ;
107+ const ev = await instance . getPastEvents ( 'Locked' , { fromBlock : startBlock } ) ;
116108
117- web3 . eth . getBlock ( i . transactionHash ) . then ( x => {
118- // getting key value pairs from the event value
119- lockEvents . push ( {
109+ return Promise . all (
110+ ev . map ( async i => {
111+ const transactionString = await Promise . resolve ( web3 . eth . getBlock ( i . blockNumber ) ) ;
112+ const time = transactionString . timestamp . toString ( ) ;
113+
114+ const e = i . returnValues ;
115+ return {
120116 eth : e [ 'eth' ] as BN ,
121117 duration : e [ 'duration' ] as number ,
122118 lock : e [ 'lock' ] as string ,
123119 introducer : e [ 'introducer' ] as string ,
124120 blockNo : i . blockNumber ,
125121 txHash : i . transactionHash ,
126- timestamp : x . timestamp ,
127- } ) ;
128- } ) ;
129-
130- // getting key value pairs from the event value
131- // lockEvents.push({
132- // eth: e['eth'] as BN,
133- // duration: e['duration'] as number,
134- // lock: e['lock'] as string,
135- // introducer: e['introducer'] as string,
136- // blockNo: i.blockNumber,
137- // txHash: i.transactionHash,
138- // timestamp: lockedTime,
139- // });
140- } ) ;
122+ timestamp : time ,
123+ } as LockEvent ;
124+ } ) ,
125+ ) ;
141126 } catch ( error ) {
142127 console . log ( error ) ;
128+ return lockEvents ;
143129 }
144130
145- return lockEvents ;
131+ // return lockEvents;
146132}
0 commit comments