Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid null chart data points #91

Merged
merged 5 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 68 additions & 2 deletions packages/api/src/dataFeeds.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,17 @@
"color": "#6600ff",
"blockExplorer": "https://testnet.confluxscan.io/address/{address}"
},
{
"feedFullName": "conflux-testnet_btc-usd_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0x8594B74645644b6a5fdE15597D3ADc15C77284A1",
"network": "conflux-testnet",
"name": "btc/usd",
"label": "$",
"pollingPeriod": 300000,
"color": "#6600ff",
"blockExplorer": "https://testnet.confluxscan.io/address/{address}"
},
{
"feedFullName": "conflux-testnet_eth-usd_6",
"abi": "./src/abi/PriceFeed.json",
Expand All @@ -98,6 +109,39 @@
"color": "#6600ff",
"blockExplorer": "https://testnet.confluxscan.io/address/{address}"
},
{
"feedFullName": "conflux-mainnet_cfx-usdt_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0x86e9A67C92455afa725CC01b2036e47cd4dd9929",
"network": "conflux-mainnet",
"name": "cfx/usdt",
"label": "₮",
"pollingPeriod": 300000,
"color": "#6600ff",
"blockExplorer": "https://confluxscan.io/address/{address}"
},
{
"feedFullName": "conflux-mainnet_btc-usd_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0x84E250b43337512B04aa5449e3A15FB715b78E88",
"network": "conflux-mainnet",
"name": "btc/usd",
"label": "$",
"pollingPeriod": 300000,
"color": "#6600ff",
"blockExplorer": "https://confluxscan.io/address/{address}"
},
{
"feedFullName": "conflux-mainnet_eth-usd_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0x8Fd10Ad4913DC1F0049B46BfeD9F061e100B7ED9",
"network": "conflux-mainnet",
"name": "eth/usd",
"label": "$",
"pollingPeriod": 300000,
"color": "#6600ff",
"blockExplorer": "https://confluxscan.io/address/{address}"
},
{
"feedFullName": "celo-alfajores_btc-usd_6",
"abi": "./src/abi/PriceFeed.json",
Expand All @@ -120,6 +164,28 @@
"color": "#1cd8d2",
"blockExplorer": "https://alfajores-blockscout.celo-testnet.org/address/{address}"
},
{
"feedFullName": "celo-mainnet_btc-usd_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0xa1A950054d1F778B0758EBe89914410d01A37248",
"network": "celo-mainnet",
"name": "btc/usd",
"label": "$",
"pollingPeriod": 300000,
"color": "#ff8100",
"blockExplorer": "https://explorer.celo.org/address/{address}"
},
{
"feedFullName": "celo-mainnet_eth-usd_6",
"abi": "./src/abi/PriceFeed.json",
"address": "0x3ebE9D7BF6cc4A4132c7fC75225f0D1c476d6ACb",
"network": "celo-mainnet",
"name": "eth/usd",
"label": "$",
"pollingPeriod": 300000,
"color": "#ff8100",
"blockExplorer": "https://explorer.celo.org/address/{address}"
},
{
"feedFullName": "boba-rinkeby_btc-usd_6",
"abi": "./src/abi/PriceFeed.json",
Expand All @@ -143,7 +209,7 @@
"blockExplorer": "https://blockexplorer.rinkeby.boba.network/address/{address}"
},
{
"feedFullName": "boba-rinkeby_omg-btc_6",
"feedFullName": "boba-rinkeby_omg-btc_9",
"abi": "./src/abi/PriceFeed.json",
"address": "0x56834Ff8D4b27db647Da97CA3bd8540f7fA0e89D",
"network": "boba-rinkeby",
Expand All @@ -154,7 +220,7 @@
"blockExplorer": "https://blockexplorer.rinkeby.boba.network/address/{address}"
},
{
"feedFullName": "boba-rinkeby_omg-eth_6",
"feedFullName": "boba-rinkeby_omg-eth_9",
"abi": "./src/abi/PriceFeed.json",
"address": "0x225BAd150B9D5202DC805B34A0DF64B1a77459dF",
"network": "boba-rinkeby",
Expand Down
12 changes: 9 additions & 3 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,19 @@ export class ResultRequestRepository {
.find(
{
feedFullName,
timestamp: { $gt: timestamp.toString() }
timestamp: { $gt: timestamp.toString() },
result: { $exists: true }
},
{
sort: { timestamp: -1 }
}
)
.toArray()
).map(this.normalizeId)
)
.filter((request, index, self) => {
return index === self.findIndex(x => x.timestamp === request.timestamp)
})
.map(this.normalizeId)
}

async getFeedRequestsPage (
Expand All @@ -42,7 +47,8 @@ export class ResultRequestRepository {
return (
await this.collection
.find({
feedFullName
feedFullName,
result: { $exists: true }
})
.sort({ timestamp: -1 })
.skip(size * (page - 1))
Expand Down
1 change: 1 addition & 0 deletions packages/api/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum Network {
ConfluxTestnet = 'conflux-testnet',
ConfluxMainnet = 'conflux-mainnet',
CeloAlfajores = 'celo-alfajores',
CeloMainnet = 'celo-mainnet',
BobaRinkeby = 'boba-rinkeby'
}

Expand Down
3 changes: 2 additions & 1 deletion packages/api/src/web3Middleware/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export function getProvider (network: Network) {
[Network.ConfluxTestnet]: process.env.CONFLUX_TESTNET_PROVIDER,
[Network.ConfluxMainnet]: process.env.CONFLUX_MAINNET_PROVIDER,
[Network.BobaRinkeby]: process.env.BOBA_RINKEBY_PROVIDER,
[Network.CeloAlfajores]: process.env.CELO_ALFAJORES_PROVIDER
[Network.CeloAlfajores]: process.env.CELO_ALFAJORES_PROVIDER,
[Network.CeloMainnet]: process.env.CELO_MAINNET_PROVIDER
}
return providers[network]
}
24 changes: 12 additions & 12 deletions packages/api/test/feeds.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe('feeds', function () {
result: '2222.0',
feedFullName,
requestId: '1',
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(),
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(),
drTxHash:
'666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a'
}
Expand Down Expand Up @@ -185,39 +185,39 @@ describe('feeds', function () {
const feed = data.data.feed
expect(feed).toHaveProperty('address', dataFeeds[0].address)
expect(feed).toHaveProperty('name', dataFeeds[0].name)
expect(feed).toHaveProperty('lastResult', resultRequestExample1.result)
expect(feed).toHaveProperty('lastResult', resultRequestExample2.result)
expect(feed.requests.length).toBe(2)
expect(feed.requests[0]).toHaveProperty(
'feedFullName',
resultRequestExample1.feedFullName
resultRequestExample2.feedFullName
)
expect(feed.requests[0]).toHaveProperty(
'result',
resultRequestExample1.result
resultRequestExample2.result
)
expect(feed.requests[0]).toHaveProperty(
'requestId',
resultRequestExample1.requestId
resultRequestExample2.requestId
)
expect(feed.requests[0]).toHaveProperty(
'timestamp',
resultRequestExample1.timestamp
resultRequestExample2.timestamp
)
expect(feed.requests[1]).toHaveProperty(
'feedFullName',
resultRequestExample2.feedFullName
resultRequestExample1.feedFullName
)
expect(feed.requests[1]).toHaveProperty(
'result',
resultRequestExample2.result
resultRequestExample1.result
)
expect(feed.requests[1]).toHaveProperty(
'requestId',
resultRequestExample2.requestId
resultRequestExample1.requestId
)
expect(feed.requests[1]).toHaveProperty(
'timestamp',
resultRequestExample2.timestamp
resultRequestExample1.timestamp
)
})

Expand All @@ -240,7 +240,7 @@ describe('feeds', function () {
result: '2222.0',
feedFullName,
requestId: '1',
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(),
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(),
drTxHash:
'666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a'
}
Expand Down Expand Up @@ -322,7 +322,7 @@ describe('feeds', function () {
result: '2222.0',
feedFullName,
requestId: '1',
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 10).toString(),
timestamp: (getTimestampByRange(CHART_RANGE.m.value) + 11).toString(),
address: '0x58995FaD03158fB9cd64397347bA97714EF9fC12',
drTxHash:
'666f4735c3cbfb71d6e2f06cd13e4705751c50500c1720162b16532072bae88a',
Expand Down
64 changes: 36 additions & 28 deletions packages/ui/components/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@update-selected="updateSelected"
/>
</div>
<div v-if="feeds && feeds.total > 0" class="list-container">
<div v-if="allFeeds.length > 0" class="list-container">
<DataFeeds :feeds="allFeeds" />
<el-pagination
v-if="numberOfPages > 1"
Expand Down Expand Up @@ -56,35 +56,43 @@ export default {
return Math.ceil(this.feeds.total / this.itemsPerPage)
},
allFeeds() {
return this.feeds.feeds
.map((feed) => {
return {
detailsPath: {
name: 'feeds-id',
params: { id: feed.feedFullName },
},
decimals: parseInt(feed.feedFullName.split('_').pop()) || 3,
name: feed.name,
value: feed.lastResult,
label: feed.label,
img: {
name: formatSvgName(feed.name),
alt: feed.name,
},
network: feed.network,
color: feed.color,
blockExplorer: feed.blockExplorer,
}
})
.sort((feed1, feed2) => feed1.network < feed2.network)
if (this.feeds) {
return this.feeds.feeds
.map((feed) => {
return {
detailsPath: {
name: 'feeds-id',
params: { id: feed.feedFullName },
},
decimals: parseInt(feed.feedFullName.split('_').pop()) || 3,
name: feed.name,
value: feed.lastResult,
label: feed.label,
img: {
name: formatSvgName(feed.name),
alt: feed.name,
},
network: feed.network,
color: feed.color,
blockExplorer: feed.blockExplorer,
}
})
.sort((feed1, feed2) => feed1.network < feed2.network)
} else {
return []
}
},
options() {
return [
{ label: 'all', key: 'All' },
...generateSelectOptions(
this.allFeeds.map((feed) => feed.network)
).sort((option1, option2) => option1.label < option2.label),
]
if (this.feeds) {
return [
{ label: 'all', key: 'All' },
...generateSelectOptions(
this.allFeeds.map((feed) => feed.network)
).sort((option1, option2) => option1.label < option2.label),
]
} else {
return [{ label: 'all', key: 'All' }]
}
},
},
methods: {
Expand Down