Skip to content

Commit

Permalink
feat(ui): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gabaldon committed Aug 17, 2021
1 parent edae6fe commit 793633c
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 96 deletions.
116 changes: 116 additions & 0 deletions packages/api/src/abi/ConfluxEthUsd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
[
{
"inputs": [
{ "internalType": "address", "name": "_wrb", "type": "address" }
],
"stateMutability": "nonpayable",
"type": "constructor"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "uint64",
"name": "",
"type": "uint64"
}
],
"name": "PriceUpdated",
"type": "event"
},
{
"anonymous": false,
"inputs": [
{
"indexed": false,
"internalType": "string",
"name": "",
"type": "string"
}
],
"name": "ResultError",
"type": "event"
},
{
"inputs": [],
"name": "ETHUSD3ID",
"outputs": [{ "internalType": "bytes32", "name": "", "type": "bytes32" }],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "lastPrice",
"outputs": [{ "internalType": "uint64", "name": "", "type": "uint64" }],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "lastRequestId",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "pending",
"outputs": [{ "internalType": "bool", "name": "", "type": "bool" }],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "request",
"outputs": [
{
"internalType": "contract WitnetRequest",
"name": "",
"type": "address"
}
],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "timestamp",
"outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }],
"stateMutability": "view",
"type": "function",
"constant": true
},
{
"inputs": [],
"name": "requestUpdate",
"outputs": [],
"stateMutability": "payable",
"type": "function",
"payable": true
},
{
"inputs": [],
"name": "completeUpdate",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
},
{
"inputs": [{ "internalType": "bytes32", "name": "_id", "type": "bytes32" }],
"name": "valueFor",
"outputs": [
{ "internalType": "int256", "name": "", "type": "int256" },
{ "internalType": "uint256", "name": "", "type": "uint256" },
{ "internalType": "uint256", "name": "", "type": "uint256" }
],
"stateMutability": "view",
"type": "function",
"constant": true
}
]
24 changes: 24 additions & 0 deletions packages/api/src/dataFeeds.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,29 @@
"address": "0x0C4be6AA667df48de54BA174bE7948875fdf152B",
"abi": "./src/abi/WitnetRequestBoardProxy.json"
}
},
{
"abi": "./src/abi/ConfluxBtcUsd.json",
"address": "0x8934bfeFb0d5d7d4f1fbEf558562f6487787b6cC",
"witnetRequestBoard": {
"address": "0x84f3342E460265D1A271Fc1Bd678A361a9208e72",
"abi": "./src/abi/ConfluxWitnetRequestBoardProxy.json"
},
"network": "conflux",
"name": "btc/usd",
"label": "$",
"pollingPeriod": 900000
},
{
"abi": "./src/abi/ConfluxEthUsd.json",
"address": "0x8E5C614bA4DA97E823D4C3f0DCB02c872C84E6C3",
"witnetRequestBoard": {
"address": "0x84f3342E460265D1A271Fc1Bd678A361a9208e72",
"abi": "./src/abi/ConfluxWitnetRequestBoardProxy.json"
},
"network": "conflux",
"name": "eth/usd",
"label": "$",
"pollingPeriod": 900000
}
]
19 changes: 10 additions & 9 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,25 @@ async function main () {
function readDataFeeds (): Array<FeedInfo> {
console.log('DIRNAME', __dirname)
console.log('DATA_FEED_CONFIG_PATH:>', process.env.DATA_FEED_CONFIG_PATH)
console.log('resolve path: ', path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json'))
console.log(
'resolve path: ',
path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json')
)

const dataFeeds: Array<FeedInfoConfig> = JSON.parse(
fs.readFileSync(path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json'), 'utf-8')
fs.readFileSync(
path.resolve(process.env.DATA_FEED_CONFIG_PATH || './dataFeeds.json'),
'utf-8'
)
)

return dataFeeds.map(dataFeed => ({
...dataFeed,
abi: JSON.parse(
fs.readFileSync(path.resolve(dataFeed.abi), 'utf-8')
),
abi: JSON.parse(fs.readFileSync(path.resolve(dataFeed.abi), 'utf-8')),
witnetRequestBoard: {
...dataFeed.witnetRequestBoard,
abi: JSON.parse(
fs.readFileSync(
path.resolve(dataFeed.witnetRequestBoard.abi),
'utf-8'
)
fs.readFileSync(path.resolve(dataFeed.witnetRequestBoard.abi), 'utf-8')
)
}
}))
Expand Down
16 changes: 12 additions & 4 deletions packages/api/src/repository/Feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ export class FeedRepository {
).map(this.normalizeId)
}

async insert (feed: Omit<FeedDbObject, '_id'>): Promise<FeedDbObjectNormalized | null> {
async insert (
feed: Omit<FeedDbObject, '_id'>
): Promise<FeedDbObjectNormalized | null> {
if (this.isValidFeed(feed)) {
const response = await this.collection.insertOne(feed)

Expand All @@ -38,7 +40,10 @@ export class FeedRepository {
}
}

async addResultRequest (feedId: ObjectId, resultRequestId: ObjectId): Promise<FeedDbObjectNormalized> {
async addResultRequest (
feedId: ObjectId,
resultRequestId: ObjectId
): Promise<FeedDbObjectNormalized> {
const response = await this.collection.findOneAndUpdate(
{ _id: feedId },
{ $push: { requests: resultRequestId } },
Expand All @@ -54,7 +59,10 @@ export class FeedRepository {
)
}

async getFeeds (page: number, size: number): Promise<Array<FeedDbObjectNormalized>> {
async getFeeds (
page: number,
size: number
): Promise<Array<FeedDbObjectNormalized>> {
return (
await this.collection
.find({ address: { $in: this.dataFeedsAddresses } })
Expand Down Expand Up @@ -82,6 +90,6 @@ export class FeedRepository {
}

private isValidFeed (feed: Omit<FeedDbObject, '_id'>): boolean {
return !containFalsyValues(feed)
return !containFalsyValues(feed)
}
}
18 changes: 14 additions & 4 deletions packages/api/src/repository/ResultRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ export class ResultRequestRepository {
this.dataFeedsAddresses = dataFeeds.map(dataFeed => dataFeed.address)
}

async getFeedRequests (feedId: ObjectId): Promise<Array<ResultRequestDbObjectNormalized>> {
async getFeedRequests (
feedId: ObjectId
): Promise<Array<ResultRequestDbObjectNormalized>> {
return (
await this.collection
.find({
Expand All @@ -29,7 +31,11 @@ export class ResultRequestRepository {
).map(this.normalizeId)
}

async getFeedRequestsPage (feedId: ObjectId, page: number, size: number): Promise<Array<ResultRequestDbObjectNormalized>> {
async getFeedRequestsPage (
feedId: ObjectId,
page: number,
size: number
): Promise<Array<ResultRequestDbObjectNormalized>> {
return (
await this.collection
.find({
Expand All @@ -42,7 +48,9 @@ export class ResultRequestRepository {
).map(this.normalizeId)
}

async getLastResult (feedId: ObjectId): Promise<ResultRequestDbObjectNormalized> {
async getLastResult (
feedId: ObjectId
): Promise<ResultRequestDbObjectNormalized> {
const lastResultRequest = await this.collection.findOne(
{
feedId: feedId.toString()
Expand All @@ -61,7 +69,9 @@ export class ResultRequestRepository {
return this.normalizeId(lastResultRequest)
}

async insert (resultRequest: Omit<ResultRequestDbObject, '_id'>): Promise<ResultRequestDbObjectNormalized | null> {
async insert (
resultRequest: Omit<ResultRequestDbObject, '_id'>
): Promise<ResultRequestDbObjectNormalized | null> {
if (this.isValidResultRequest(resultRequest)) {
const response = await this.collection.insertOne(resultRequest)

Expand Down
4 changes: 2 additions & 2 deletions packages/api/src/repository/containFalsyValues.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export function containFalsyValues(obj: Object): boolean {
export function containFalsyValues (obj: Object): boolean {
return !Object.values(obj).reduce((prev, val) => prev && val)
}
}
68 changes: 0 additions & 68 deletions packages/api/src/web3Middleware/dataFeeds.ts

This file was deleted.

6 changes: 1 addition & 5 deletions packages/api/src/web3Middleware/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,7 @@ export class Web3Middleware {
return feed
})

try {
return await Promise.all(promises)
} catch (err) {
console.error('[ERROR]', err.message)
}
return await Promise.all(promises)
}

async listen () {
Expand Down
6 changes: 3 additions & 3 deletions packages/api/test/containFalsyValues.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ describe('containFalsyValues', () => {
it('should return FALSE when no falsy value is found on the object', () => {
const obj = {
a: 'a',
b: 'b',
b: 'b'
}

expect(containFalsyValues(obj)).toBe(false)
Expand All @@ -13,9 +13,9 @@ describe('containFalsyValues', () => {
it('should return TRUE when falsy value is found on the object', () => {
const obj = {
a: 'a',
b: null,
b: null
}

expect(containFalsyValues(obj)).toBe(true)
})
})
})
2 changes: 1 addition & 1 deletion packages/api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"noImplicitReturns": true,
"noImplicitReturns": true
},
"include": ["src/"],
"exclude": ["node_modules", "test"]
Expand Down

0 comments on commit 793633c

Please sign in to comment.