@block-auth.io/angular 0.3.2 → 0.4.1

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.
Files changed (153) hide show
  1. package/fesm2022/block-auth.io-angular.mjs +9828 -0
  2. package/fesm2022/block-auth.io-angular.mjs.map +1 -0
  3. package/index.d.ts +1144 -0
  4. package/package.json +16 -37
  5. package/.turbo/turbo-build.log +0 -37
  6. package/.turbo/turbo-lint.log +0 -4
  7. package/.turbo/turbo-test.log +0 -2001
  8. package/.turbo/turbo-typecheck.log +0 -19
  9. package/CHANGELOG.md +0 -245
  10. package/ng-package.json +0 -6
  11. package/scripts/css-to-ts.mjs +0 -14
  12. package/src/lib/__tests__/integration.test.ts +0 -45
  13. package/src/lib/block-auth.service.test.ts +0 -69
  14. package/src/lib/block-auth.service.ts +0 -81
  15. package/src/lib/components/btns/btn-base-provider.component.test.ts +0 -22
  16. package/src/lib/components/btns/btn-base-provider.component.ts +0 -55
  17. package/src/lib/components/btns/btn-block-auth.component.test.ts +0 -105
  18. package/src/lib/components/btns/btn-block-auth.component.ts +0 -117
  19. package/src/lib/components/btns/btn-gmail.component.test.ts +0 -16
  20. package/src/lib/components/btns/btn-gmail.component.ts +0 -41
  21. package/src/lib/components/btns/btn-google-base.component.test.ts +0 -16
  22. package/src/lib/components/btns/btn-google-base.component.ts +0 -73
  23. package/src/lib/components/btns/btn-metamask.component.test.ts +0 -20
  24. package/src/lib/components/btns/btn-metamask.component.ts +0 -98
  25. package/src/lib/components/btns/btn-microsoft.component.test.ts +0 -16
  26. package/src/lib/components/btns/btn-microsoft.component.ts +0 -77
  27. package/src/lib/components/btns/btn-phantom.component.test.ts +0 -20
  28. package/src/lib/components/btns/btn-phantom.component.ts +0 -93
  29. package/src/lib/components/btns/btn-signin.component.test.ts +0 -55
  30. package/src/lib/components/btns/btn-signin.component.ts +0 -108
  31. package/src/lib/components/btns/btn-wallet-connect.component.test.ts +0 -20
  32. package/src/lib/components/btns/btn-wallet-connect.component.ts +0 -109
  33. package/src/lib/components/btns/index.ts +0 -11
  34. package/src/lib/components/contents/content-signin.component.test.ts +0 -33
  35. package/src/lib/components/contents/content-signin.component.ts +0 -68
  36. package/src/lib/components/contents/content-signup.component.test.ts +0 -86
  37. package/src/lib/components/contents/content-signup.component.ts +0 -234
  38. package/src/lib/components/dds/change-account.component.test.ts +0 -66
  39. package/src/lib/components/dds/change-account.component.ts +0 -112
  40. package/src/lib/components/dds/dropdown-profile-btn.component.test.ts +0 -66
  41. package/src/lib/components/dds/dropdown-profile-btn.component.ts +0 -170
  42. package/src/lib/components/dds/dropdown-profile-item.component.test.ts +0 -75
  43. package/src/lib/components/dds/dropdown-profile-item.component.ts +0 -74
  44. package/src/lib/components/dds/dropdown-profile.component.test.ts +0 -110
  45. package/src/lib/components/dds/dropdown-profile.component.ts +0 -264
  46. package/src/lib/components/flow-block-auth.component.test.ts +0 -93
  47. package/src/lib/components/flow-block-auth.component.ts +0 -226
  48. package/src/lib/components/modals/modal-overlay.component.test.ts +0 -81
  49. package/src/lib/components/modals/modal-overlay.component.ts +0 -43
  50. package/src/lib/components/modals/modal-restoration-expired.component.test.ts +0 -71
  51. package/src/lib/components/modals/modal-restoration-expired.component.ts +0 -83
  52. package/src/lib/components/modals/modal-restore.component.test.ts +0 -74
  53. package/src/lib/components/modals/modal-restore.component.ts +0 -104
  54. package/src/lib/components/modals/modal-signin.component.test.ts +0 -66
  55. package/src/lib/components/modals/modal-signin.component.ts +0 -44
  56. package/src/lib/components/modals/modal-signup.component.test.ts +0 -56
  57. package/src/lib/components/modals/modal-signup.component.ts +0 -40
  58. package/src/lib/components/sections/footer-section.component.test.ts +0 -19
  59. package/src/lib/components/sections/footer-section.component.ts +0 -49
  60. package/src/lib/components/sections/internals/providers-buttons.component.test.ts +0 -27
  61. package/src/lib/components/sections/internals/providers-buttons.component.ts +0 -290
  62. package/src/lib/components/sections/internals/providers-filters.component.test.ts +0 -25
  63. package/src/lib/components/sections/internals/providers-filters.component.ts +0 -139
  64. package/src/lib/components/sections/internals/selected-button.component.test.ts +0 -36
  65. package/src/lib/components/sections/internals/selected-button.component.ts +0 -92
  66. package/src/lib/components/sections/login-section.component.test.ts +0 -49
  67. package/src/lib/components/sections/login-section.component.ts +0 -120
  68. package/src/lib/components/sections/providers-section.component.test.ts +0 -22
  69. package/src/lib/components/sections/providers-section.component.ts +0 -187
  70. package/src/lib/components/txns/internals/permissions-required-modal.component.test.ts +0 -36
  71. package/src/lib/components/txns/internals/permissions-required-modal.component.ts +0 -43
  72. package/src/lib/components/txns/internals/phone-input.component.test.ts +0 -119
  73. package/src/lib/components/txns/internals/phone-input.component.ts +0 -301
  74. package/src/lib/components/txns/internals/solicited-data-modal.component.test.ts +0 -661
  75. package/src/lib/components/txns/internals/solicited-data-modal.component.ts +0 -415
  76. package/src/lib/components/txns/internals/txn-error.component.test.ts +0 -127
  77. package/src/lib/components/txns/internals/txn-error.component.ts +0 -144
  78. package/src/lib/components/txns/internals/txn-type.component.test.ts +0 -52
  79. package/src/lib/components/txns/internals/txn-type.component.ts +0 -51
  80. package/src/lib/components/txns/internals/txn.component.test.ts +0 -580
  81. package/src/lib/components/txns/internals/txn.component.ts +0 -461
  82. package/src/lib/components/txns/txns-overview.component.test.ts +0 -421
  83. package/src/lib/components/txns/txns-overview.component.ts +0 -424
  84. package/src/lib/icons/ai-outline-disconnect.component.ts +0 -21
  85. package/src/lib/icons/bi-logo-gmail.component.ts +0 -21
  86. package/src/lib/icons/cg-profile.component.ts +0 -31
  87. package/src/lib/icons/check-icon.component.ts +0 -27
  88. package/src/lib/icons/ci-clock2.component.ts +0 -31
  89. package/src/lib/icons/fa-arrow-right.component.ts +0 -21
  90. package/src/lib/icons/fa-times.component.ts +0 -21
  91. package/src/lib/icons/fa-undo.component.ts +0 -21
  92. package/src/lib/icons/icons.test.ts +0 -25
  93. package/src/lib/icons/index.ts +0 -22
  94. package/src/lib/icons/io-ios-arrow-back.component.ts +0 -21
  95. package/src/lib/icons/io-ios-arrow-forward.component.ts +0 -21
  96. package/src/lib/icons/io-md-arrow-back.component.ts +0 -19
  97. package/src/lib/icons/io-md-arrow-forward.component.ts +0 -19
  98. package/src/lib/icons/pi-warning-fill.component.ts +0 -21
  99. package/src/lib/icons/tb-arrows-exchange2.component.ts +0 -30
  100. package/src/lib/icons/tb-copy-check-filled.component.ts +0 -21
  101. package/src/lib/icons/tb-copy.component.ts +0 -34
  102. package/src/lib/icons/ti-vendor-microsoft.component.ts +0 -21
  103. package/src/lib/inject-store.test.ts +0 -26
  104. package/src/lib/inject-store.ts +0 -16
  105. package/src/lib/primitives/arrow-icon.component.test.ts +0 -25
  106. package/src/lib/primitives/arrow-icon.component.ts +0 -45
  107. package/src/lib/primitives/btn-arrow-dir.component.test.ts +0 -22
  108. package/src/lib/primitives/btn-arrow-dir.component.ts +0 -65
  109. package/src/lib/primitives/btn-base.component.test.ts +0 -38
  110. package/src/lib/primitives/btn-base.component.ts +0 -140
  111. package/src/lib/primitives/divider-base.component.test.ts +0 -12
  112. package/src/lib/primitives/divider-base.component.ts +0 -74
  113. package/src/lib/primitives/dropdown-arrow.component.test.ts +0 -12
  114. package/src/lib/primitives/dropdown-arrow.component.ts +0 -46
  115. package/src/lib/primitives/dropdown-base.component.test.ts +0 -49
  116. package/src/lib/primitives/dropdown-base.component.ts +0 -329
  117. package/src/lib/primitives/helpers.ts +0 -151
  118. package/src/lib/primitives/horizontal-loader.component.test.ts +0 -19
  119. package/src/lib/primitives/horizontal-loader.component.ts +0 -70
  120. package/src/lib/primitives/icon-base.component.test.ts +0 -19
  121. package/src/lib/primitives/icon-base.component.ts +0 -58
  122. package/src/lib/primitives/img-loader.component.test.ts +0 -12
  123. package/src/lib/primitives/img-loader.component.ts +0 -118
  124. package/src/lib/primitives/index.ts +0 -29
  125. package/src/lib/primitives/input-base.component.test.ts +0 -20
  126. package/src/lib/primitives/input-base.component.ts +0 -210
  127. package/src/lib/primitives/lifetime-slider-base.component.test.ts +0 -88
  128. package/src/lib/primitives/lifetime-slider-base.component.ts +0 -75
  129. package/src/lib/primitives/oval-spinner.component.test.ts +0 -9
  130. package/src/lib/primitives/oval-spinner.component.ts +0 -158
  131. package/src/lib/primitives/pickers/dropdown-picker-animated-base.component.ts +0 -220
  132. package/src/lib/primitives/pickers/picker-button.component.ts +0 -74
  133. package/src/lib/primitives/pickers/time-picker-dropdown-selector.component.ts +0 -188
  134. package/src/lib/primitives/pickers/time-picker.component.ts +0 -124
  135. package/src/lib/primitives/pickers/time-unit-selector.component.ts +0 -82
  136. package/src/lib/primitives/progressbar.component.test.ts +0 -18
  137. package/src/lib/primitives/progressbar.component.ts +0 -93
  138. package/src/lib/primitives/providersStyles.ts +0 -268
  139. package/src/lib/primitives/slider-base.component.ts +0 -56
  140. package/src/lib/provide-block-auth.test.ts +0 -43
  141. package/src/lib/provide-block-auth.ts +0 -43
  142. package/src/lib/runtime/block-auth-runtime.directive.test.ts +0 -89
  143. package/src/lib/runtime/block-auth-runtime.directive.ts +0 -68
  144. package/src/lib/teleport-body.directive.test.ts +0 -29
  145. package/src/lib/teleport-body.directive.ts +0 -21
  146. package/src/lib/testing.ts +0 -15
  147. package/src/lib/transitions.css +0 -23
  148. package/src/public-api.ts +0 -86
  149. package/src/vitest.setup.ts +0 -8
  150. package/tailwind.config.cjs +0 -6
  151. package/tsconfig.json +0 -15
  152. package/tsconfig.lib.json +0 -9
  153. package/vite.config.mts +0 -44
@@ -1,264 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- DestroyRef,
5
- ElementRef,
6
- HostListener,
7
- Type,
8
- computed,
9
- inject,
10
- input,
11
- signal,
12
- viewChild,
13
- } from '@angular/core';
14
- import { $locale } from '@block-auth.io/core';
15
- import { injectBlockAuthClient } from '../../provide-block-auth';
16
- import { injectStore } from '../../inject-store';
17
- import { CgProfileComponent, AiOutlineDisconnectComponent } from '../../icons';
18
- import { ChangeAccountComponent } from './change-account.component';
19
- import { DropdownProfileItemComponent } from './dropdown-profile-item.component';
20
- import { DropdownProfileBtnComponent } from './dropdown-profile-btn.component';
21
-
22
- // Decisiones de diseño:
23
- // - `onLogout`/`onNavigate` son INPUTS DE FUNCIÓN (no outputs): `onLogout` se
24
- // hace `await` DESPUÉS de `client.logout()` (orden crítico, un output no se
25
- // puede "esperar"); `onNavigate` es un hook de host con rama alternativa
26
- // (`window.location.href`) cuando es null. El resto de callbacks son outputs
27
- // (`clicked`/`changeAccountClicked`).
28
- // - Refs `profileBtnEl`/`dropdownPanelEl` (viewChild) sobre `<div>`s propios de
29
- // este componente para el click-outside.
30
- // - La animación de apertura es `@if` + clase `ba-pop`. Al abrir, un
31
- // `setTimeout(200)` marca `isAnimationCompleted` (habilita `overflow-y-auto`).
32
- // - `additionalDropdownItems[].firstIcon` es un tipo de componente
33
- // (`Type<unknown>`) renderizado por `dropdown-profile-item` vía NgComponentOutlet.
34
- // - "Disconnect": `client.logout()` PRIMERO y `onLogout()` DESPUÉS (verificado
35
- // en el test).
36
- export interface DropdownProfileAdditionalItem {
37
- onClick: () => void;
38
- /** String plano o mapa de locale (`{ es, en }`). */
39
- text: string | Record<string, string>;
40
- firstIcon?: Type<unknown> | null;
41
- disabled?: boolean;
42
- }
43
-
44
- @Component({
45
- selector: 'ba-dropdown-profile',
46
- standalone: true,
47
- changeDetection: ChangeDetectionStrategy.OnPush,
48
- imports: [DropdownProfileBtnComponent, DropdownProfileItemComponent, ChangeAccountComponent],
49
- template: `
50
- <div
51
- data-testid="dropdown-profile"
52
- class="bas-flex bas-w-fit bas-flex-col bas-items-center bas-justify-start"
53
- [style.height.px]="getHeight(dropdownBtnSize())"
54
- >
55
- <div #profileBtnEl>
56
- <ba-dropdown-profile-btn
57
- [serviceName]="serviceName()"
58
- [dropdownBtnBgClassNames]="dropdownBtnBgClassNames()"
59
- [dropdownBtnSize]="dropdownBtnSize()"
60
- [dropdownBtnBorderClassNames]="dropdownBtnBorderClassNames()"
61
- [dropdownBtnTextColorClassNames]="dropdownBtnTextColorClassNames()"
62
- [height]="getHeight(dropdownBtnSize())"
63
- [isProfileOpen]="isProfileOpen()"
64
- (clicked)="onProfileClicked()"
65
- />
66
- </div>
67
- @if (isProfileOpen()) {
68
- <div
69
- #dropdownPanelEl
70
- class="ba-pop bal-ba-transition-2 bal-ba-shadow-base bal-ba-hover-shadow-md bas-z-50 bas-mt-2 bas-box-border bas-w-full bas-overflow-hidden bas-rounded-md bas-border bas-border-solid bas-border-[var(--bal-primary-100)] bas-bg-white hover:bas-border-[var(--bal-primary-300)]"
71
- [style.minHeight.px]="dropdownHeight() ?? totalDropdownItems() * 36 + 2"
72
- >
73
- <ul
74
- [class]="
75
- 'bas-flex bas-h-full bas-w-full bas-box-border bas-flex-col bas-items-center bas-justify-start bas-text-base bas-text-[var(--bal-primary-700)] bal-ba-transition-2 hover:bas-text-[var(--bal-primary-900)] bal-ba-scroll-base bas-p-0 bas-m-0 ' +
76
- (isAnimationCompleted() && isProfileOpen() ? 'bas-overflow-y-auto' : '')
77
- "
78
- [style.maxHeight.px]="dropdownHeight() ?? totalDropdownItems() * 36"
79
- >
80
- <!-- ADDITIONAL ITEMS -->
81
- @for (item of itemsToShow(); track $index; let index = $index) {
82
- <ba-dropdown-profile-item
83
- [id]="'ba-ddi-additional-item-' + index"
84
- [text]="localized(item.text, '')"
85
- [firstIcon]="item.firstIcon ?? null"
86
- [isTopBorder]="index !== 0"
87
- [disabled]="item.disabled ?? false"
88
- (clicked)="item.onClick()"
89
- />
90
- }
91
- <!-- CHANGE ACCOUNT + DISCONNECT — hidden until the login transaction is signed -->
92
- @if (isSigned()) {
93
- <ba-change-account
94
- [serviceName]="serviceName()"
95
- [text]="localized(btnsTexts().changeAccount, 'Change account')"
96
- [disabled]="disabled()"
97
- [isTopBorder]="isWeb3Service() || itemsToShow().length > 0"
98
- (changeAccountClicked)="onChangeAccountClicked()"
99
- />
100
- <ba-dropdown-profile-item
101
- id="ba-dd8-disconnect-0"
102
- [text]="localized(btnsTexts().disconnect, 'Disconnect')"
103
- [firstIcon]="disconnectIcon"
104
- [isTopBorder]="true"
105
- (clicked)="onDisconnectClicked()"
106
- />
107
- }
108
- </ul>
109
- </div>
110
- }
111
- </div>
112
- `,
113
- styles: [
114
- `
115
- .ba-pop {
116
- animation: ba-pop-in 0.15s ease;
117
- transform-origin: top right;
118
- }
119
- @keyframes ba-pop-in {
120
- from { opacity: 0; transform: scale(0.95); }
121
- to { opacity: 1; transform: scale(1); }
122
- }
123
- `,
124
- ],
125
- })
126
- export class DropdownProfileComponent {
127
- onLogout = input<() => void | Promise<void>>(async () => {});
128
- /** Host-app navigation for "My profile" when already on the identity origin. */
129
- onNavigate = input<((path: string) => void) | null>(null);
130
- isInsideModal = input(false);
131
- /** Modal container that scopes the click-outside listener when `isInsideModal`. */
132
- container = input<HTMLElement | null>(null);
133
- /** Disables the "Change account" row (default: disabled — not functional yet). */
134
- disabled = input(true);
135
- dropdownBtnSize = input<'xs' | 'small' | 'base' | 'large'>('base');
136
- dropdownBtnBgClassNames = input('bas-bg-transparent');
137
- dropdownBtnTextColorClassNames = input(
138
- 'bas-text-[var(--bal-primary-700)] group-hover:bas-text-[var(--bal-primary-900)]',
139
- );
140
- dropdownBtnBorderClassNames = input<string | undefined>(undefined);
141
- dropdownHeight = input<number | null>(null);
142
- additionalDropdownItems = input<DropdownProfileAdditionalItem[] | null>(null);
143
-
144
- private readonly profileBtnEl = viewChild<ElementRef<HTMLDivElement>>('profileBtnEl');
145
- private readonly dropdownPanelEl = viewChild<ElementRef<HTMLDivElement>>('dropdownPanelEl');
146
-
147
- private readonly client = injectBlockAuthClient();
148
- private readonly ui = injectStore(this.client.state.$ui);
149
- private readonly locale = injectStore($locale);
150
-
151
- protected readonly disconnectIcon = AiOutlineDisconnectComponent;
152
- protected readonly isProfileOpen = signal(false);
153
- protected readonly isAnimationCompleted = signal(false);
154
- private animTimeout: ReturnType<typeof setTimeout> | undefined;
155
-
156
- protected readonly serviceName = computed(() => this.ui().serviceName ?? 'blockauth');
157
- protected readonly isSigned = computed(() => this.ui().isSigned);
158
-
159
- private readonly uiConfigContent = computed(
160
- () =>
161
- this.ui().uiConfig as
162
- | { config?: { content?: { btns?: Record<string, Record<string, string>> } } }
163
- | null,
164
- );
165
- private readonly isUiConfig = computed(
166
- () => this.uiConfigContent() != null && Object.keys(this.uiConfigContent()!).length > 0,
167
- );
168
- protected readonly btnsTexts = computed(
169
- () =>
170
- (this.isUiConfig() && this.uiConfigContent()?.config?.content?.btns) || {
171
- disconnect: { es: 'Desconectar', en: 'Disconnect' },
172
- changeAccount: { es: 'Cambiar cuenta', en: 'Change account' },
173
- },
174
- );
175
-
176
- private readonly defaultAdditionalDropdownItems = computed<DropdownProfileAdditionalItem[]>(() => [
177
- {
178
- onClick: () => {
179
- const url = 'https://identity.block-auth.io';
180
- const identityOrigin = 'https://identity.block-auth.io';
181
- if (typeof window === 'undefined') return;
182
- if (window.location.origin === identityOrigin) {
183
- const navigate = this.onNavigate();
184
- if (navigate) navigate('/user/profile');
185
- else window.location.href = url;
186
- } else {
187
- window.open(url, '_blank');
188
- }
189
- },
190
- text: { es: 'Mi perfil', en: 'My profile' },
191
- firstIcon: CgProfileComponent,
192
- disabled: false,
193
- },
194
- ]);
195
-
196
- // Not fully authenticated yet (connected but transaction unsigned): only the
197
- // "Copy DID" row in `DropdownProfileBtnComponent` is a valid action, so the
198
- // item list (My profile / Change account / Disconnect) stays empty.
199
- protected readonly itemsToShow = computed(() =>
200
- this.isSigned() ? this.additionalDropdownItems() ?? this.defaultAdditionalDropdownItems() : [],
201
- );
202
- private readonly web2Services = ['google', 'microsoft'];
203
- protected readonly isWeb3Service = computed(() => !this.web2Services.includes(this.serviceName()));
204
- protected readonly totalDropdownItems = computed(() => (this.isSigned() ? 2 + this.itemsToShow().length : 0));
205
-
206
- private readonly heightBySize: Record<string, number> = { xs: 46, small: 52, base: 58, large: 64 };
207
-
208
- constructor() {
209
- inject(DestroyRef).onDestroy(() => {
210
- if (this.animTimeout) clearTimeout(this.animTimeout);
211
- });
212
- }
213
-
214
- getHeight(size: string): number {
215
- return this.heightBySize[size];
216
- }
217
-
218
- localized(text: string | Record<string, string> | undefined, fallback: string): string {
219
- if (!text) return fallback;
220
- if (typeof text === 'string') return text;
221
- return text[this.locale()] ?? text['en'] ?? fallback;
222
- }
223
-
224
- onProfileClicked(): void {
225
- if (!this.isSigned()) return;
226
- this.isAnimationCompleted.set(false);
227
- const next = !this.isProfileOpen();
228
- this.isProfileOpen.set(next);
229
- if (this.animTimeout) clearTimeout(this.animTimeout);
230
- if (next) this.animTimeout = setTimeout(() => this.isAnimationCompleted.set(true), 200);
231
- }
232
-
233
- async onDisconnectClicked(): Promise<void> {
234
- this.isAnimationCompleted.set(false);
235
- this.isProfileOpen.set(false);
236
- // Clear BlockAuth state first, then let the host app tear down — otherwise
237
- // onLogout could read stale storage. Order is critical (verified in test).
238
- await this.client.logout();
239
- await this.onLogout()();
240
- }
241
-
242
- onChangeAccountClicked(): void {
243
- if (this.disabled()) return;
244
- this.isAnimationCompleted.set(false);
245
- this.isProfileOpen.set(false);
246
- }
247
-
248
- // Click-outside. Con @HostListener el listener vive siempre en document; para
249
- // respetar la
250
- // semántica "escuchar sobre `container` cuando `isInsideModal && container`"
251
- // se ignora todo click fuera de ese contenedor. Un click sobre el propio
252
- // botón de perfil nunca cuenta como "fuera". "Fuera" se calcula vs el panel.
253
- @HostListener('document:click', ['$event'])
254
- onDocumentClick(e: MouseEvent): void {
255
- if (!this.isProfileOpen()) return;
256
- const target = e.target as Node;
257
- const container = this.container();
258
- if (this.isInsideModal() && container && !container.contains(target)) return;
259
- const btnEl = this.profileBtnEl()?.nativeElement;
260
- if (btnEl && btnEl.contains(target)) return;
261
- const panel = this.dropdownPanelEl()?.nativeElement;
262
- if (panel && !panel.contains(target)) this.isProfileOpen.set(false);
263
- }
264
- }
@@ -1,93 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { Component } from '@angular/core';
3
- import { render, screen, fireEvent, waitFor } from '@testing-library/angular';
4
- import { map, atom } from 'nanostores';
5
-
6
- vi.mock('@wagmi/core', () => ({
7
- createConfig: vi.fn(() => ({ connectors: [] })),
8
- connect: vi.fn(), disconnect: vi.fn(), getAccount: vi.fn(() => ({})),
9
- signMessage: vi.fn(), watchAccount: vi.fn(() => () => undefined), http: vi.fn(),
10
- }));
11
- vi.mock('@wagmi/connectors', () => ({
12
- injected: vi.fn(() => ({ id: 'injected' })), walletConnect: vi.fn(() => ({ id: 'walletConnect' })),
13
- }));
14
-
15
- import { FlowBlockAuthComponent } from './flow-block-auth.component';
16
- import { provideBlockAuthClientForTest } from '../testing';
17
-
18
- // Port de packages/react/src/components/FlowBlockAuth.test.tsx. El `initializeSdk`
19
- // se pone en `false` donde no se quiere arrancar el runtime real (el arranque
20
- // del runtime lo cubre block-auth-runtime.directive.test.ts). Client falso con
21
- // stores nanostores y spies de acción.
22
- function makeClient(ui: Record<string, unknown> = {}) {
23
- return {
24
- requestSignin: vi.fn(),
25
- openModal: vi.fn(),
26
- closeModal: vi.fn(),
27
- cancelTxns: vi.fn(),
28
- logout: vi.fn(async () => {}),
29
- web3: { signup: vi.fn() },
30
- oauth: { signupGoogle: vi.fn(), signupMicrosoft: vi.fn() },
31
- state: {
32
- $ws: map<Record<string, unknown>>({ ready: false }),
33
- $ui: map<Record<string, unknown>>({ ...ui }),
34
- $wallet: map({}),
35
- $openModals: atom<string[]>([]),
36
- },
37
- } as any;
38
- }
39
-
40
- describe('FlowBlockAuth', () => {
41
- it('renderiza el contenedor del orquestador sin romperse', async () => {
42
- @Component({
43
- standalone: true,
44
- imports: [FlowBlockAuthComponent],
45
- template: `<ba-flow-block-auth [initializeSdk]="false" />`,
46
- })
47
- class Host {}
48
- await render(Host, { providers: [provideBlockAuthClientForTest(makeClient())] });
49
- expect(screen.getByTestId('flow-blockauth')).toBeTruthy();
50
- });
51
-
52
- it('no se rompe cuando initializeSdk esta desactivado', async () => {
53
- @Component({
54
- standalone: true,
55
- imports: [FlowBlockAuthComponent],
56
- template: `<ba-flow-block-auth [initializeSdk]="false" />`,
57
- })
58
- class Host {}
59
- await render(Host, { providers: [provideBlockAuthClientForTest(makeClient())] });
60
- expect(screen.getByTestId('flow-blockauth')).toBeTruthy();
61
- });
62
-
63
- it('en estado log-in, click en el boton de estado llama a client.requestSignin', async () => {
64
- const client = makeClient({
65
- isSdkSignedIn: true,
66
- isServiceConnected: true,
67
- isSigned: false,
68
- isSignedFirstCheck: true,
69
- isOnDeletion: false,
70
- serviceName: 'blockauth',
71
- uiConfig: { config: { content: { btns: { logIn: { en: 'Log in', es: 'Iniciar sesion' } } } } },
72
- });
73
- client.state.$ws.setKey('ready', true);
74
-
75
- @Component({
76
- standalone: true,
77
- imports: [FlowBlockAuthComponent],
78
- template: `<ba-flow-block-auth [initializeSdk]="false" [showDropdownWhenConnected]="false" />`,
79
- })
80
- class Host {}
81
- const { container } = await render(Host, {
82
- providers: [provideBlockAuthClientForTest(client)],
83
- });
84
-
85
- const btn = container.querySelector('#btn-flow-blockauth') as HTMLButtonElement;
86
- expect(btn).toBeTruthy();
87
- expect(btn.disabled).toBe(false);
88
- await fireEvent.click(btn);
89
-
90
- await waitFor(() => expect(client.requestSignin).toHaveBeenCalled());
91
- expect(client.openModal).toHaveBeenCalledWith('signin');
92
- });
93
- });
@@ -1,226 +0,0 @@
1
- import { ChangeDetectionStrategy, Component, computed, inject, input, output } from '@angular/core';
2
- import { setIsSigningLoader } from '@block-auth.io/core';
3
- import { BlockAuthService } from '../block-auth.service';
4
- import { BtnBaseComponent } from '../primitives/btn-base.component';
5
- import { BlockAuthRuntimeDirective } from '../runtime/block-auth-runtime.directive';
6
- import {
7
- DropdownProfileComponent,
8
- type DropdownProfileAdditionalItem,
9
- } from './dds/dropdown-profile.component';
10
- import { ModalSigninComponent } from './modals/modal-signin.component';
11
- import { ModalSignupComponent } from './modals/modal-signup.component';
12
- import { ModalRestoreComponent } from './modals/modal-restore.component';
13
- import { ModalRestorationExpiredComponent } from './modals/modal-restoration-expired.component';
14
-
15
- @Component({
16
- selector: 'ba-flow-block-auth',
17
- standalone: true,
18
- changeDetection: ChangeDetectionStrategy.OnPush,
19
- imports: [
20
- BtnBaseComponent,
21
- BlockAuthRuntimeDirective,
22
- DropdownProfileComponent,
23
- ModalSigninComponent,
24
- ModalSignupComponent,
25
- ModalRestoreComponent,
26
- ModalRestorationExpiredComponent,
27
- ],
28
- template: `
29
- <div
30
- data-testid="flow-blockauth"
31
- [class]="
32
- 'bas-flex bas-w-full bas-items-center bas-justify-center ' +
33
- (showDDP() ? 'bas-h-fit bas-flex-col bas-gap-2.5' : ' bas-h-[52px]')
34
- "
35
- >
36
- @if (initializeSdk()) {
37
- <ng-container
38
- baRuntime
39
- (success)="success.emit($event)"
40
- (errored)="errored.emit()"
41
- (loggedOut)="loggedOut.emit()"
42
- />
43
- }
44
-
45
- @if (!ui().isSigned || !ui().isSignedFirstCheck) {
46
- <ba-btn-base
47
- btnId="btn-flow-blockauth"
48
- type="button-outlined"
49
- size="base"
50
- [disabled]="isLoading()"
51
- [isLoader]="isLoading()"
52
- loaderColor="#ffffff"
53
- [isIcon]="ws().ready"
54
- [text]="buttonText() || label()"
55
- [bgClassNames]="bgClassNames()"
56
- [textClassNames]="btnTextClassNames()"
57
- [classNames]="'bas-justify-center ' + btnClassNames()"
58
- [isFocusOutlinedEnabled]="false"
59
- (action)="onFlowBAClicked()"
60
- >
61
- @if (ws().ready && ui().isSdkSignedIn) {
62
- <img
63
- slot="icon"
64
- src="https://dashboard.block-auth.io/img/blockauth_logo.png"
65
- width="26"
66
- height="26"
67
- alt="BlockAuth"
68
- />
69
- } @else if (ws().ready) {
70
- <svg
71
- slot="icon"
72
- class="bas-h-6 bas-w-6 bas-text-white"
73
- viewBox="0 0 24 24"
74
- fill="currentColor"
75
- aria-hidden="true"
76
- >
77
- <path
78
- d="M12 2 1 21h22L12 2Zm0 6c.55 0 1 .45 1 1v5a1 1 0 1 1-2 0V9c0-.55.45-1 1-1Zm0 9.5a1.25 1.25 0 1 1 0 2.5 1.25 1.25 0 0 1 0-2.5Z"
79
- />
80
- </svg>
81
- }
82
- </ba-btn-base>
83
- }
84
-
85
- @if (showDDP()) {
86
- <ba-dropdown-profile
87
- [onLogout]="onLogoutForwarder"
88
- [isInsideModal]="isInsideModal()"
89
- [container]="container()"
90
- [dropdownBtnSize]="dropdownBtnSize()"
91
- [dropdownBtnBgClassNames]="dropdownBtnBgClassNames()"
92
- [dropdownBtnTextColorClassNames]="dropdownBtnTextColorClassNames()"
93
- [dropdownBtnBorderClassNames]="dropdownBtnBorderClassNames()"
94
- [dropdownHeight]="dropdownHeight()"
95
- [additionalDropdownItems]="additionalDropdownItems()"
96
- />
97
- }
98
-
99
- <!-- Orden fijo: signin (modal de txn) se renderiza por encima de signup;
100
- la card de signup queda detrás. Cada modal se auto-oculta según el
101
- stack openModals del core. -->
102
- <ba-modal-signup />
103
- <ba-modal-restore />
104
- <ba-modal-restoration-expired />
105
- <ba-modal-signin />
106
- </div>
107
- `,
108
- })
109
- export class FlowBlockAuthComponent {
110
- showDropdownWhenConnected = input(true);
111
- isInsideModal = input(false);
112
- /** Modal container that scopes the dropdown's click-outside listener when `isInsideModal`. */
113
- container = input<HTMLElement | null>(null);
114
- btnClassNames = input('bas-w-full bas-justify-center');
115
- btnTextClassNames = input('bas-font-semibold bas-leading-6 bas-text-base bas-text-white');
116
- dropdownBtnSize = input<'xs' | 'small' | 'base' | 'large'>('small');
117
- dropdownBtnBgClassNames = input('bas-bg-transparent');
118
- dropdownBtnTextColorClassNames = input(
119
- 'bas-text-[var(--bal-primary-700)] group-hover:bas-text-[var(--bal-primary-900)]',
120
- );
121
- dropdownBtnBorderClassNames = input<string | undefined>(undefined);
122
- dropdownHeight = input<number | null>(null);
123
- initializeSdk = input(true);
124
- additionalDropdownItems = input<DropdownProfileAdditionalItem[] | null>(null);
125
- /** Status-button label override. */
126
- buttonText = input('');
127
-
128
- success = output<string | undefined>();
129
- errored = output<void>();
130
- loggedOut = output<void>();
131
-
132
- private readonly ba = inject(BlockAuthService);
133
- protected readonly ws = this.ba.ws;
134
- protected readonly ui = this.ba.ui;
135
- private readonly locale = this.ba.locale;
136
-
137
- private readonly isUiConfig = computed(
138
- () => this.ui().uiConfig != null && Object.keys(this.ui().uiConfig as object).length > 0,
139
- );
140
- // Copia localizada del backend (`app()` -> uiConfig.config.content.btns):
141
- // { reviewApi, signUp, logIn, restore } cada una keyed por locale (en/es).
142
- private readonly btnsTexts = computed(
143
- () =>
144
- (
145
- this.ui().uiConfig as
146
- | { config?: { content?: { btns?: Record<string, Record<string, string>> } } }
147
- | null
148
- )?.config?.content?.btns,
149
- );
150
-
151
- protected readonly showDDP = computed(
152
- () =>
153
- this.ws().ready &&
154
- this.ui().isSdkSignedIn &&
155
- this.ui().isServiceConnected &&
156
- this.showDropdownWhenConnected() &&
157
- this.ui().isSignedFirstCheck,
158
- );
159
-
160
- // Azul mientras arranca, transparente una vez firmado en el SDK, naranja en
161
- // on-deletion, rojo si la api key es inválida.
162
- protected readonly bgClassNames = computed(() =>
163
- !(this.ws().ready && this.isUiConfig())
164
- ? 'bas-bg-[rgba(0,78,152,0.8)] hover:bas-bg-[rgba(0,62,121,0.8)]'
165
- : this.ui().isSdkSignedIn
166
- ? undefined
167
- : this.ui().isOnDeletion
168
- ? 'bas-bg-orange-500 hover:bas-bg-orange-600'
169
- : 'bas-bg-red-500 hover:bas-bg-red-600',
170
- );
171
-
172
- protected readonly isLoading = computed(
173
- () => !(this.ws().ready && this.isUiConfig() && this.ui().isSignedFirstCheck),
174
- );
175
-
176
- // Label localizado desde el mapa de texto del backend; `buttonText` sigue
177
- // pudiendo sobreescribirlo.
178
- private readonly restoreDefault: Record<string, string> = {
179
- es: 'Restaurar cuenta',
180
- en: 'Restore account',
181
- };
182
- protected readonly label = computed<string>(() => {
183
- if (this.isLoading()) return '';
184
- if (!this.ui().isSdkSignedIn) return this.btnsTexts()?.reviewApi?.[this.locale()] ?? '';
185
- if (this.ui().isOnDeletion) {
186
- return (
187
- this.btnsTexts()?.restore?.[this.locale()] ??
188
- this.restoreDefault[this.locale()] ??
189
- this.restoreDefault['en']
190
- );
191
- }
192
- if (!this.ui().isServiceConnected && !this.ui().isSigned) {
193
- return this.btnsTexts()?.signUp?.[this.locale()] ?? '';
194
- }
195
- if (this.ui().isServiceConnected && !this.ui().isSigned) {
196
- return this.btnsTexts()?.logIn?.[this.locale()] ?? '';
197
- }
198
- return '';
199
- });
200
-
201
- /** Reenvía el logout manual del dropdown al output `loggedOut`. */
202
- protected readonly onLogoutForwarder = (): void => this.loggedOut.emit();
203
-
204
- onFlowBAClicked(): void {
205
- if (!(this.ui().isSdkSignedIn && this.ws().ready)) return;
206
- if (this.ui().isOnDeletion) {
207
- this.ba.openModal('restore');
208
- return;
209
- }
210
- if (!this.ui().isServiceConnected && !this.ui().isSigned) {
211
- this.ba.openModal('signup');
212
- return;
213
- }
214
- if (this.ui().isServiceConnected && !this.ui().isSigned) {
215
- // LOG-IN branch: emit the signin transaction, then open the signin modal
216
- // and flag the signing loader. The runtime clears the loader once
217
- // `user:txns` reports no pending txns.
218
- this.ba.requestSignin();
219
- const known = ['google', 'metamask', 'phantom', 'microsoft', 'blockauth'];
220
- if (known.includes(this.ui().serviceName ?? '')) {
221
- this.ba.openModal('signin');
222
- setIsSigningLoader(true);
223
- }
224
- }
225
- }
226
- }
@@ -1,81 +0,0 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { Component, input } from '@angular/core';
3
- import { render, screen, fireEvent } from '@testing-library/angular';
4
- import { ModalOverlayComponent } from './modal-overlay.component';
5
-
6
- // Port de packages/react/src/components/modals/ModalOverlay.tsx (mapa:
7
- // packages/vue/src/components/modals/ModalOverlay.test.ts): verifica el
8
- // contrato de portal + backdrop-click + slot que comparten los 4 modales.
9
- // Los signal inputs no se pueden fijar por `componentInputs` de forma fiable,
10
- // así que se usa un host component con binding de template.
11
- @Component({
12
- selector: 'ba-overlay-host',
13
- standalone: true,
14
- imports: [ModalOverlayComponent],
15
- template: `
16
- <ba-modal-overlay [open]="open()" testId="modal-x" (closed)="onClose()">
17
- <div data-testid="panel-content">hola</div>
18
- </ba-modal-overlay>
19
- `,
20
- })
21
- class OverlayHostComponent {
22
- open = input(false);
23
- onClose = (): void => undefined;
24
- }
25
-
26
- describe('ModalOverlay', () => {
27
- it('no renderiza nada cuando open es false', async () => {
28
- await render(OverlayHostComponent);
29
- expect(screen.queryByTestId('modal-x')).toBeNull();
30
- });
31
-
32
- it('se monta en document.body (portal) y renderiza el slot cuando open es true', async () => {
33
- @Component({
34
- selector: 'ba-overlay-host-open',
35
- standalone: true,
36
- imports: [ModalOverlayComponent],
37
- template: `
38
- <ba-modal-overlay [open]="true" testId="modal-x">
39
- <div data-testid="panel-content">hola</div>
40
- </ba-modal-overlay>
41
- `,
42
- })
43
- class HostOpen {}
44
- await render(HostOpen);
45
- const overlay = screen.getByTestId('modal-x');
46
- expect(overlay).toBeDefined();
47
- expect(overlay.parentElement).toBe(document.body);
48
- expect(screen.getByTestId('panel-content').textContent).toBe('hola');
49
- });
50
-
51
- it('el panel tiene role="dialog" y aria-modal="true"', async () => {
52
- @Component({
53
- selector: 'ba-overlay-host-dialog',
54
- standalone: true,
55
- imports: [ModalOverlayComponent],
56
- template: `<ba-modal-overlay [open]="true" testId="modal-x" />`,
57
- })
58
- class HostDialog {}
59
- await render(HostDialog);
60
- const dialog = screen.getByRole('dialog');
61
- expect(dialog.getAttribute('aria-modal')).toBe('true');
62
- });
63
-
64
- it('al hacer click en el backdrop emite closed', async () => {
65
- const onClose = vi.fn();
66
- @Component({
67
- selector: 'ba-overlay-host-close',
68
- standalone: true,
69
- imports: [ModalOverlayComponent],
70
- template: `<ba-modal-overlay [open]="true" testId="modal-x" (closed)="onClose()" />`,
71
- })
72
- class HostClose {
73
- onClose = onClose;
74
- }
75
- await render(HostClose);
76
- const backdrop = screen.getByTestId('modal-x').querySelector('[aria-hidden="true"]');
77
- expect(backdrop).not.toBeNull();
78
- await fireEvent.click(backdrop!);
79
- expect(onClose).toHaveBeenCalledOnce();
80
- });
81
- });