Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3ce166d

Browse files
committed
added get all timestamps
1 parent 46bc96a commit 3ce166d

4 files changed

Lines changed: 657 additions & 545 deletions

File tree

app/src/components/LockedEthList.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,11 @@ const LockedEthList: React.FC<LockHistoryProps> = ({ web3, contractInstance }) =
100100
setValue(index);
101101
};
102102

103-
const updateList = () => {
104-
getLockEvents(web3, contractInstance).then(i => setEvents(i));
103+
const updateList = async () => {
104+
await getLockEvents(web3, contractInstance).then(i => {
105+
setEvents(i);
106+
console.log(i);
107+
});
105108
};
106109

107110
const getTotalLockVal = (locks: LockEvent[]): string => {
@@ -116,8 +119,8 @@ const LockedEthList: React.FC<LockHistoryProps> = ({ web3, contractInstance }) =
116119
};
117120

118121
useEffect(() => {
119-
setTimeout(() => {
120-
updateList();
122+
setTimeout(async () => {
123+
await updateList();
121124
}, 1000);
122125
});
123126
return (

app/src/helpers/lockdrop/EthereumLockdrop.ts

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

app/src/models/LockdropModels.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export interface LockEvent {
1515
introducer: string;
1616
blockNo: number;
1717
txHash: string;
18-
timestamp: string | number; // in Unix epoch
18+
timestamp: string; // in Unix epoch
1919
}

0 commit comments

Comments
 (0)