Skip to content

Commit

Permalink
Remove timestamp_gt filter from queries
Browse files Browse the repository at this point in the history
  • Loading branch information
lmcorbalan committed Jun 2, 2020
1 parent bcde40c commit 8fcca1b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/utils/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ myWindow.exportCache = async () => {
cache[key] = value
})

const fileName = `maker-governace-${(Date.now() / 1000).toFixed(0)}.json`
const fileName = `maker-governance-${(Date.now() / 1000).toFixed(0)}.json`
const file = new File([JSON.stringify(cache)], fileName, { type: 'application/json' })
saveFile(file, fileName)
}

myWindow.exportCacheByKey = async key => {
let cache = await getCache(key)

const fileName = `maker-governace-${key}-${(Date.now() / 1000).toFixed(0)}.json`
const fileName = `maker-governance-${key}-${(Date.now() / 1000).toFixed(0)}.json`
const file = new File([JSON.stringify(cache)], fileName, { type: 'application/json' })
saveFile(file, fileName)
}
Expand All @@ -32,7 +32,7 @@ myWindow.exportCacheByMultipleKey = async (keys: Array<any>) => {
if (keys.includes(key)) cache[key] = value
})

const fileName = `maker-governace-multiple-${(Date.now() / 1000).toFixed(0)}.json`
const fileName = `maker-governance-multiple-${(Date.now() / 1000).toFixed(0)}.json`
const file = new File([JSON.stringify(cache)], fileName, { type: 'application/json' })
saveFile(file, fileName)
}
Expand Down
27 changes: 9 additions & 18 deletions src/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,15 @@ export const getVotersSnapshots = async voters => {
return Object.keys(allSnapshots).map(add => allSnapshots[add].data)
}

export const getVoterBalancesFrom = async ({ voter, fromDate = 0, endDate }) => {
export const getVoterBalancesFrom = async ({ voter, endDate }) => {
// Query
const query = `
query getAccountBalances($voter: Bytes!, $endDate: BigInt!, $fromDate: BigInt!, $skip: Int = 0 ) {
query getAccountBalances($voter: Bytes!, $endDate: BigInt!, $skip: Int = 0 ) {
accountBalanceSnapshots(
first: 1000,
skip: $skip,
where:{
account: $voter,
timestamp_gt: $fromDate
timestamp_lte: $endDate
},
orderBy: timestamp, orderDirection: desc
Expand All @@ -242,7 +241,6 @@ export const getVoterBalancesFrom = async ({ voter, fromDate = 0, endDate }) =>
while (more) {
const partial: any = await fetchQuery(MKR_API_URI, query, {
voter,
fromDate,
endDate,
skip,
})
Expand Down Expand Up @@ -354,26 +352,26 @@ export const getStakedByPoll = async (proxies, voters, poll) => {
}

const query = `
query getStakedByPoll( $proxies: [Bytes!]!, $voters: [Bytes!]!, $fromDate: BigInt!, $endDate: BigInt! ) {
lock_proxies: actions(first: 1000, where: {type: LOCK, sender_in: $proxies, timestamp_gt: $fromDate, timestamp_lte: $endDate}) {
query getStakedByPoll( $proxies: [Bytes!]!, $voters: [Bytes!]!, $endDate: BigInt! ) {
lock_proxies: actions(first: 1000, where: {type: LOCK, sender_in: $proxies, timestamp_lte: $endDate}) {
sender
type
wad
timestamp
}
free_proxies: actions(first: 1000, where: {type: FREE, sender_in: $proxies, timestamp_gt: $fromDate, timestamp_lte: $endDate}) {
free_proxies: actions(first: 1000, where: {type: FREE, sender_in: $proxies, timestamp_lte: $endDate}) {
sender
type
wad
timestamp
}
lock_voters: actions(first: 1000, where: {type: LOCK, sender_in: $voters, timestamp_gt: $fromDate, timestamp_lte: $endDate}) {
lock_voters: actions(first: 1000, where: {type: LOCK, sender_in: $voters, timestamp_lte: $endDate}) {
sender
type
wad
timestamp
}
free_voters: actions(first: 1000, where: {type: FREE, sender_in: $voters, timestamp_gt: $fromDate, timestamp_lte: $endDate}) {
free_voters: actions(first: 1000, where: {type: FREE, sender_in: $voters, timestamp_lte: $endDate}) {
sender
type
wad
Expand All @@ -384,18 +382,11 @@ export const getStakedByPoll = async (proxies, voters, poll) => {
const result: any = await fetchQuery(GOVERNANCE_API_URI, query, {
proxies,
voters,
fromDate: locksFrees.lastUpdate || 0,
endDate,
})

const newProxies =
locksFrees && locksFrees.data && locksFrees.data.proxies
? [...locksFrees.data.proxies, ...result.lock_proxies, ...result.free_proxies]
: [...result.lock_proxies, ...result.free_proxies]
const newVoters =
locksFrees && locksFrees.data && locksFrees.data.voters
? [...locksFrees.data.voters, ...result.lock_voters, ...result.free_voters]
: [...result.lock_voters, ...result.free_voters]
const newProxies = [...result.lock_proxies, ...result.free_proxies]
const newVoters = [...result.lock_voters, ...result.free_voters]

const newCacheData = {
lastUpdate: endDate,
Expand Down

0 comments on commit 8fcca1b

Please sign in to comment.