@ethisyscore/plugin-ui 1.94.1 → 1.95.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.
@@ -203,6 +203,50 @@ function useOrgFormatSync() {
203
203
  return () => controller.abort();
204
204
  }, [transport, organisationId]);
205
205
  }
206
+ var warnedAboutMissingAccessor2 = false;
207
+ var useOptionalExtensionRuntimeTransport4 = typeof extensionRuntime__namespace.useOptionalExtensionRuntimeTransport === "function" ? extensionRuntime__namespace.useOptionalExtensionRuntimeTransport : () => {
208
+ if (!warnedAboutMissingAccessor2) {
209
+ warnedAboutMissingAccessor2 = true;
210
+ console.warn(
211
+ "[plugin-ui] The host realm does not expose useOptionalExtensionRuntimeTransport (host SDK predates 1.88.0). The organisation reporting currency falls back to GBP for this bundle. Bump the host's @ethisyscore/extension-runtime pin to restore it."
212
+ );
213
+ }
214
+ return null;
215
+ };
216
+ var REPORTING_CURRENCY_TOOL = "settings:get-organisation-reporting-currency";
217
+ function useReportingCurrencySync() {
218
+ const transport = useOptionalExtensionRuntimeTransport4();
219
+ const organisationId = extensionRuntime__namespace.useHostIdentity()?.organisationId ?? null;
220
+ const [, bumpVersion] = react.useState(0);
221
+ const previousOrganisationId = react.useRef(void 0);
222
+ if (previousOrganisationId.current !== organisationId) {
223
+ previousOrganisationId.current = organisationId;
224
+ money.setOrgReportingCurrency(null);
225
+ }
226
+ react.useEffect(() => {
227
+ money.setOrgReportingCurrency(null);
228
+ bumpVersion((v) => v + 1);
229
+ if (!transport) return;
230
+ const controller = new AbortController();
231
+ transport.invokeTool(
232
+ REPORTING_CURRENCY_TOOL,
233
+ {},
234
+ controller.signal
235
+ ).then((result) => {
236
+ if (controller.signal.aborted) return;
237
+ const currency = result?.currency ?? null;
238
+ money.setOrgReportingCurrency(
239
+ currency ? { code: currency.code, decimalPlaces: currency.decimalPlaces } : null
240
+ );
241
+ bumpVersion((v) => v + 1);
242
+ }).catch(() => {
243
+ if (controller.signal.aborted) return;
244
+ money.setOrgReportingCurrency(null);
245
+ bumpVersion((v) => v + 1);
246
+ });
247
+ return () => controller.abort();
248
+ }, [transport, organisationId]);
249
+ }
206
250
 
207
251
  // src/platform-react/definePlatformReactPluginPage.tsx
208
252
  function makeDefaultQueryClient() {
@@ -229,6 +273,7 @@ function definePlatformReactPluginPage(Page, options) {
229
273
  } = options;
230
274
  function PluginPage(props) {
231
275
  useOrgFormatSync();
276
+ useReportingCurrencySync();
232
277
  const page = react.createElement(Page, props);
233
278
  const body = wrapPage ? wrapPage(page) : page;
234
279
  const surfaceTree = react.createElement(
@@ -390,7 +435,7 @@ function useAuthenticatedQuery(options) {
390
435
  function useAuthenticatedQueries(queries) {
391
436
  return reactQuery.useQueries({ queries });
392
437
  }
393
- var REPORTING_CURRENCY_TOOL = "settings:get-organisation-reporting-currency";
438
+ var REPORTING_CURRENCY_TOOL2 = "settings:get-organisation-reporting-currency";
394
439
  var LIST_CURRENCIES_TOOL = "settings:list-currencies";
395
440
  var emptyCatalogue = () => /* @__PURE__ */ new Map();
396
441
  var SETTLED_FULFILLED = "fulfilled";
@@ -411,7 +456,7 @@ function useCurrency() {
411
456
  const controller = new AbortController();
412
457
  Promise.allSettled([
413
458
  transport.invokeTool(
414
- REPORTING_CURRENCY_TOOL,
459
+ REPORTING_CURRENCY_TOOL2,
415
460
  {},
416
461
  controller.signal
417
462
  ),
@@ -423,7 +468,8 @@ function useCurrency() {
423
468
  ]).then(([reporting, list]) => {
424
469
  if (controller.signal.aborted) return;
425
470
  if (reporting.status === SETTLED_FULFILLED) {
426
- setReportingCurrency(reporting.value?.currency ?? null);
471
+ const resolved = reporting.value?.currency ?? null;
472
+ setReportingCurrency(resolved);
427
473
  }
428
474
  if (list.status === SETTLED_FULFILLED && Array.isArray(list.value)) {
429
475
  setCurrencies(new Map(list.value.map((currency) => [currency.id, currency])));
@@ -721,6 +767,7 @@ function definePlatformReactPluginOverlay(Overlay, options) {
721
767
  const { rootClassName, styleId, css, manifest = {}, queryClient = defaultQueryClient2, wrapOverlay } = options;
722
768
  return function MountedOverlay(props) {
723
769
  useOrgFormatSync();
770
+ useReportingCurrencySync();
724
771
  const tree = react.createElement(
725
772
  OverlayHostContext.Provider,
726
773
  { value: props.overlayHost },
@@ -1057,7 +1104,7 @@ exports.OVERLAY_HOST_CONTRACT_VERSION = OVERLAY_HOST_CONTRACT_VERSION;
1057
1104
  exports.OverlayHostContext = OverlayHostContext;
1058
1105
  exports.PluginPortalScope = PluginPortalScope;
1059
1106
  exports.PluginStyleScope = PluginStyleScope;
1060
- exports.REPORTING_CURRENCY_TOOL = REPORTING_CURRENCY_TOOL;
1107
+ exports.REPORTING_CURRENCY_TOOL = REPORTING_CURRENCY_TOOL2;
1061
1108
  exports.SIDEBAR_MODE = SIDEBAR_MODE;
1062
1109
  exports.SurfaceBaseContext = SurfaceBaseContext;
1063
1110
  exports.TemplateContext = TemplateContext;
@@ -1091,6 +1138,7 @@ exports.useMcpUpload = useMcpUpload;
1091
1138
  exports.useOrgFormatSync = useOrgFormatSync;
1092
1139
  exports.useOverlayHost = useOverlayHost;
1093
1140
  exports.usePluginRealtime = usePluginRealtime;
1141
+ exports.useReportingCurrencySync = useReportingCurrencySync;
1094
1142
  exports.useSurfaceUrl = useSurfaceUrl;
1095
1143
  exports.useToolInvoker = useToolInvoker;
1096
1144
  exports.useToolInvokerMap = useToolInvokerMap;