mirror of
https://github.com/FlipsideCrypto/flipside-js.git
synced 2026-02-06 10:48:11 +00:00
Update asset interface of dynamic widget.
This commit is contained in:
parent
124d14c2a1
commit
2d51db81ec
16
index.html
16
index.html
@ -40,6 +40,10 @@
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<div id="widget"></div>
|
||||
</div>
|
||||
|
||||
<div class="wrapper"><div id="chart"></div></div>
|
||||
|
||||
<div class="wrapper dark" style="background-color:#000000">
|
||||
@ -63,17 +67,15 @@
|
||||
<div id="multiTableFcas"></div>
|
||||
</div>
|
||||
|
||||
<div class="wrapper">
|
||||
<div id="widget"></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
const flipside = new Flipside("6b7a8b4f-4d50-437f-ac29-47a0323c5842");
|
||||
const flipside = new Flipside("a7936778-4f87-4790-889f-3ab617271458");
|
||||
|
||||
flipside.dynamic("widget", {
|
||||
widgetId: "d25902d6-c4be-4445-a5bd-003b9f320b31"
|
||||
widgetId: "578375af-3467-4742-9863-5ca6f2fa30d1",
|
||||
asset: {
|
||||
symbol: "BTC"
|
||||
}
|
||||
});
|
||||
|
||||
flipside.chart("chart", {
|
||||
title: "Flipside 25 - Overall Industry Health",
|
||||
chart: {
|
||||
|
||||
@ -59,7 +59,7 @@ export default class API {
|
||||
}
|
||||
|
||||
async fetchDynamic(id: string) {
|
||||
return this._fetch("GET", `/widgets/dynamic/${id}`)
|
||||
return this._fetch("GET", `/widgets/dynamic/${id}`);
|
||||
}
|
||||
|
||||
async fetchMetrics(payload: {
|
||||
|
||||
@ -4,9 +4,14 @@ import Flipside from "..";
|
||||
import template from "lodash/template";
|
||||
import mapValues from "lodash/mapValues";
|
||||
|
||||
type Asset = {
|
||||
id?: number;
|
||||
symbol?: string;
|
||||
};
|
||||
|
||||
type DynamicOpts = {
|
||||
widgetId: string;
|
||||
assetId: string;
|
||||
asset: Asset;
|
||||
};
|
||||
|
||||
export default async function dynamic(api: API, el: string, opts: DynamicOpts) {
|
||||
@ -22,8 +27,6 @@ export default async function dynamic(api: API, el: string, opts: DynamicOpts) {
|
||||
}
|
||||
]);
|
||||
|
||||
const { function_name, function_config } = res.data;
|
||||
|
||||
const flipside = new window.Flipside(api.key);
|
||||
const fn: any = (flipside as any)[res.data.function_name];
|
||||
if (!fn) {
|
||||
@ -32,19 +35,21 @@ export default async function dynamic(api: API, el: string, opts: DynamicOpts) {
|
||||
);
|
||||
}
|
||||
|
||||
const config = interpolateConfig(opts.assetId, res.data.function_config);
|
||||
const config = interpolateConfig(opts.asset, res.data.function_config);
|
||||
fn.call(flipside, el, config);
|
||||
}
|
||||
|
||||
// Replaces instances of ${asset_id} in the config with the assetId
|
||||
function interpolateConfig(assetId: string, config: Object): any {
|
||||
return mapValues(config, value => {
|
||||
function interpolateConfig(asset: any, config: Object): any {
|
||||
return mapValues(config, (value: any) => {
|
||||
const targetAsset =
|
||||
typeof asset == "string" ? asset : asset.id || asset.symbol;
|
||||
if (typeof value === "string") {
|
||||
const compiled = template(value);
|
||||
return compiled({ asset_id: assetId });
|
||||
return compiled({ asset_id: targetAsset });
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
return interpolateConfig(assetId, value);
|
||||
return interpolateConfig(targetAsset, value);
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
@ -118,7 +118,7 @@ class Spectrum extends Component<Props, State> {
|
||||
_update() {
|
||||
this.interval = window.setInterval(async () => {
|
||||
await this._getData();
|
||||
}, 300000);
|
||||
}, 90000);
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user