Line data Source code
1 : import { effectScope } from 'vue'
2 :
3 : import { refreshBilling } from '@/platform/billing/billingRefresh'
4 : import { useBillingCapabilities } from '@/platform/billing/composables/useBillingCapabilities'
5 :
6 2356 : let latest:
7 : | { readonly returned: Event; readonly read: Promise<unknown> }
8 : | undefined
9 :
10 0 : async function refreshCapabilities(): Promise<void> {
11 0 : const scope = effectScope(true)
12 0 : try {
13 0 : await scope.run(useBillingCapabilities)?.refresh()
14 : } finally {
15 0 : scope.stop()
16 : }
17 : }
18 :
19 : /** Re-reads plan, balance and capabilities once for `returned`, the return to this tab, however many listeners saw it. */
20 0 : export function refreshBillingAccount(returned: Event): Promise<unknown> {
21 0 : if (latest?.returned !== returned) {
22 0 : latest = {
23 : returned,
24 : read: Promise.allSettled([
25 : refreshBilling('account'),
26 : refreshCapabilities()
27 : ])
28 : }
29 : }
30 0 : return latest.read
31 : }
|