-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Add burned mana to slot (#1317)
* feat: Add novaTimeService for convenience and use it. * feat: Add route (and influx support) to get slot burned mana. Add client hook and use it on slot page. * chore: Silence eslint 'unresolved' on CI (api) * feat: Cache last 20 ManaBurned requests fetched on api * fix: Fix formatAmount for '0' values. Add tests for it. * feat: Ensure mana burned is shown on slot page * feat: Add burned mana to Slot feed on Landing * fix: Fix field name in novaTimeService Co-authored-by: JCNoguera <[email protected]> --------- Co-authored-by: JCNoguera <[email protected]> Co-authored-by: Branko Bosnic <[email protected]>
- Loading branch information
1 parent
248d915
commit 564ea92
Showing
19 changed files
with
381 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
api/src/models/api/nova/stats/slot/ISlotManaBurnedRequest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export interface ISlotManaBurnedRequest { | ||
/** | ||
* The network to search on. | ||
*/ | ||
network: string; | ||
|
||
/** | ||
* The slot index to get the mana burned for. | ||
*/ | ||
slotIndex: string; | ||
} |
6 changes: 6 additions & 0 deletions
6
api/src/models/api/nova/stats/slot/ISlotManaBurnedResponse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { IResponse } from "../../IResponse"; | ||
|
||
export interface ISlotManaBurnedResponse extends IResponse { | ||
slotIndex?: number; | ||
manaBurned?: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { ServiceFactory } from "../../../../factories/serviceFactory"; | ||
import { ISlotManaBurnedRequest } from "../../../../models/api/nova/stats/slot/ISlotManaBurnedRequest"; | ||
import { ISlotManaBurnedResponse } from "../../../../models/api/nova/stats/slot/ISlotManaBurnedResponse"; | ||
import { IConfiguration } from "../../../../models/configuration/IConfiguration"; | ||
import { NOVA } from "../../../../models/db/protocolVersion"; | ||
import { NetworkService } from "../../../../services/networkService"; | ||
import { InfluxServiceNova } from "../../../../services/nova/influx/influxServiceNova"; | ||
import { ValidationHelper } from "../../../../utils/validationHelper"; | ||
|
||
/** | ||
* Fetch the slot mana burned from influx nova. | ||
* @param _ The configuration. | ||
* @param request The request. | ||
* @returns The response. | ||
*/ | ||
export async function get(_: IConfiguration, request: ISlotManaBurnedRequest): Promise<ISlotManaBurnedResponse> { | ||
const networkService = ServiceFactory.get<NetworkService>("network"); | ||
const networks = networkService.networkNames(); | ||
ValidationHelper.oneOf(request.network, networks, "network"); | ||
ValidationHelper.numberFromString(request.slotIndex, "slotIndex"); | ||
|
||
const networkConfig = networkService.get(request.network); | ||
|
||
if (networkConfig.protocolVersion !== NOVA) { | ||
return {}; | ||
} | ||
|
||
const influxService = ServiceFactory.get<InfluxServiceNova>(`influxdb-${networkConfig.network}`); | ||
|
||
if (influxService) { | ||
const slotIndex = Number.parseInt(request.slotIndex, 10); | ||
const manaBurnedInSlot = await influxService.getManaBurnedBySlotIndex(slotIndex); | ||
|
||
if (manaBurnedInSlot) { | ||
return { | ||
slotIndex: manaBurnedInSlot.slotIndex, | ||
manaBurned: manaBurnedInSlot.manaBurned, | ||
}; | ||
} | ||
|
||
return { error: `Could not fetch mana burned for slot ${request.slotIndex}` }; | ||
} | ||
|
||
return { error: "Influx service not found for this network." }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.