@ethisyscore/plugin-ui 1.90.0 → 1.91.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/platform-react/index.cjs +87 -0
- package/dist/platform-react/index.cjs.map +1 -1
- package/dist/platform-react/index.d.cts +44 -1
- package/dist/platform-react/index.d.ts +44 -1
- package/dist/platform-react/index.js +87 -3
- package/dist/platform-react/index.js.map +1 -1
- package/package.json +1 -1
|
@@ -7,6 +7,7 @@ var extensionRuntime = require('@ethisyscore/extension-runtime/plugin');
|
|
|
7
7
|
var material = require('@mui/material');
|
|
8
8
|
var jsxRuntime = require('react/jsx-runtime');
|
|
9
9
|
var orgFormat = require('@ethisyscore/core-utils/date/org-format');
|
|
10
|
+
var money = require('@ethisyscore/core-utils/money');
|
|
10
11
|
|
|
11
12
|
function _interopNamespace(e) {
|
|
12
13
|
if (e && e.__esModule) return e;
|
|
@@ -389,6 +390,89 @@ function useAuthenticatedQuery(options) {
|
|
|
389
390
|
function useAuthenticatedQueries(queries) {
|
|
390
391
|
return reactQuery.useQueries({ queries });
|
|
391
392
|
}
|
|
393
|
+
var REPORTING_CURRENCY_TOOL = "settings:get-organisation-reporting-currency";
|
|
394
|
+
var LIST_CURRENCIES_TOOL = "settings:list-currencies";
|
|
395
|
+
var emptyCatalogue = () => /* @__PURE__ */ new Map();
|
|
396
|
+
var SETTLED_FULFILLED = "fulfilled";
|
|
397
|
+
function useCurrency() {
|
|
398
|
+
const transport = extensionRuntime.useOptionalExtensionRuntimeTransport();
|
|
399
|
+
const organisationId = extensionRuntime.useHostIdentity()?.organisationId ?? null;
|
|
400
|
+
const [reportingCurrency, setReportingCurrency] = react.useState(null);
|
|
401
|
+
const [currencies, setCurrencies] = react.useState(emptyCatalogue);
|
|
402
|
+
const [ready, setReady] = react.useState(false);
|
|
403
|
+
react.useEffect(() => {
|
|
404
|
+
setReportingCurrency(null);
|
|
405
|
+
setCurrencies(emptyCatalogue());
|
|
406
|
+
setReady(false);
|
|
407
|
+
if (!transport) {
|
|
408
|
+
setReady(true);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
const controller = new AbortController();
|
|
412
|
+
Promise.allSettled([
|
|
413
|
+
transport.invokeTool(
|
|
414
|
+
REPORTING_CURRENCY_TOOL,
|
|
415
|
+
{},
|
|
416
|
+
controller.signal
|
|
417
|
+
),
|
|
418
|
+
transport.invokeTool(
|
|
419
|
+
LIST_CURRENCIES_TOOL,
|
|
420
|
+
{},
|
|
421
|
+
controller.signal
|
|
422
|
+
)
|
|
423
|
+
]).then(([reporting, list]) => {
|
|
424
|
+
if (controller.signal.aborted) return;
|
|
425
|
+
if (reporting.status === SETTLED_FULFILLED) {
|
|
426
|
+
setReportingCurrency(reporting.value?.currency ?? null);
|
|
427
|
+
}
|
|
428
|
+
if (list.status === SETTLED_FULFILLED && Array.isArray(list.value)) {
|
|
429
|
+
setCurrencies(new Map(list.value.map((currency) => [currency.id, currency])));
|
|
430
|
+
}
|
|
431
|
+
setReady(true);
|
|
432
|
+
});
|
|
433
|
+
return () => controller.abort();
|
|
434
|
+
}, [transport, organisationId]);
|
|
435
|
+
const format = react.useCallback(
|
|
436
|
+
(amount, selector) => {
|
|
437
|
+
const currency = resolveCurrency(selector, currencies, reportingCurrency);
|
|
438
|
+
if (currency === null) {
|
|
439
|
+
return new Intl.NumberFormat(money.MONEY_FALLBACK_LOCALE).format(amount);
|
|
440
|
+
}
|
|
441
|
+
if (typeof currency === "string") {
|
|
442
|
+
return money.formatMoney(amount, { currencyCode: currency });
|
|
443
|
+
}
|
|
444
|
+
return money.formatMoney(amount, {
|
|
445
|
+
currencyCode: currency.code,
|
|
446
|
+
decimalPlaces: currency.decimalPlaces,
|
|
447
|
+
symbol: currency.symbol
|
|
448
|
+
});
|
|
449
|
+
},
|
|
450
|
+
[currencies, reportingCurrency]
|
|
451
|
+
);
|
|
452
|
+
return react.useMemo(
|
|
453
|
+
() => ({ reportingCurrency, currencies, ready, format }),
|
|
454
|
+
[reportingCurrency, currencies, ready, format]
|
|
455
|
+
);
|
|
456
|
+
}
|
|
457
|
+
function resolveCurrency(selector, currencies, reportingCurrency) {
|
|
458
|
+
if (selector === null || selector === void 0) {
|
|
459
|
+
return reportingCurrency;
|
|
460
|
+
}
|
|
461
|
+
if (typeof selector !== "string") {
|
|
462
|
+
return selector;
|
|
463
|
+
}
|
|
464
|
+
const byId = currencies.get(selector);
|
|
465
|
+
if (byId) {
|
|
466
|
+
return byId;
|
|
467
|
+
}
|
|
468
|
+
const upper = selector.toUpperCase();
|
|
469
|
+
for (const currency of currencies.values()) {
|
|
470
|
+
if (currency.code.toUpperCase() === upper) {
|
|
471
|
+
return currency;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
return selector;
|
|
475
|
+
}
|
|
392
476
|
function matchRouteParams(pathname, routes, basePath) {
|
|
393
477
|
const prefix = basePath.length > 1 && basePath.endsWith("/") ? basePath.slice(0, -1) : basePath;
|
|
394
478
|
const norm = pathname.length > 1 && pathname.endsWith("/") ? pathname.slice(0, -1) : pathname;
|
|
@@ -966,12 +1050,14 @@ exports.EHX_PLUGIN_PORTAL_CLASS = EHX_PLUGIN_PORTAL_CLASS;
|
|
|
966
1050
|
exports.EHX_PLUGIN_ROOT_CLASS = EHX_PLUGIN_ROOT_CLASS;
|
|
967
1051
|
exports.HOST_CHROME_CONTRACT_VERSION = HOST_CHROME_CONTRACT_VERSION;
|
|
968
1052
|
exports.HostSidebarActionsContext = HostSidebarActionsContext;
|
|
1053
|
+
exports.LIST_CURRENCIES_TOOL = LIST_CURRENCIES_TOOL;
|
|
969
1054
|
exports.MissingViewFallback = MissingViewFallback;
|
|
970
1055
|
exports.ORGANISATION_SETTINGS_URI = ORGANISATION_SETTINGS_URI;
|
|
971
1056
|
exports.OVERLAY_HOST_CONTRACT_VERSION = OVERLAY_HOST_CONTRACT_VERSION;
|
|
972
1057
|
exports.OverlayHostContext = OverlayHostContext;
|
|
973
1058
|
exports.PluginPortalScope = PluginPortalScope;
|
|
974
1059
|
exports.PluginStyleScope = PluginStyleScope;
|
|
1060
|
+
exports.REPORTING_CURRENCY_TOOL = REPORTING_CURRENCY_TOOL;
|
|
975
1061
|
exports.SIDEBAR_MODE = SIDEBAR_MODE;
|
|
976
1062
|
exports.SurfaceBaseContext = SurfaceBaseContext;
|
|
977
1063
|
exports.TemplateContext = TemplateContext;
|
|
@@ -998,6 +1084,7 @@ exports.surfacePathFor = surfacePathFor;
|
|
|
998
1084
|
exports.toHostSidebarInput = toHostSidebarInput;
|
|
999
1085
|
exports.useAuthenticatedQueries = useAuthenticatedQueries;
|
|
1000
1086
|
exports.useAuthenticatedQuery = useAuthenticatedQuery;
|
|
1087
|
+
exports.useCurrency = useCurrency;
|
|
1001
1088
|
exports.useHostSidebarActions = useHostSidebarActions;
|
|
1002
1089
|
exports.useManagedLifecycle = useManagedLifecycle;
|
|
1003
1090
|
exports.useMcpUpload = useMcpUpload;
|