| 335 | * @public |
| 336 | */ |
| 337 | export class ReadOnlyAccessMiddleware extends BasePresentationMiddleware implements PresentationMiddleware { |
| 338 | private constructor (client: Client, next?: PresentationMiddleware) { |
| 339 | super(client, next) |
| 340 | } |
| 341 | |
| 342 | async notifyTx (...tx: Tx[]): Promise<void> { |
| 343 | await this.provideNotifyTx(...tx) |
| 344 | } |
| 345 | |
| 346 | async close (): Promise<void> { |
| 347 | await this.provideClose() |
| 348 | } |
| 349 | |
| 350 | static create (client: Client, next?: PresentationMiddleware): ReadOnlyAccessMiddleware { |
| 351 | return new ReadOnlyAccessMiddleware(client, next) |
| 352 | } |
| 353 | |
| 354 | async tx (tx: Tx): Promise<TxResult> { |
| 355 | if (getCurrentAccount()?.role === AccountRole.ReadOnlyGuest) { |
| 356 | addNotification( |
| 357 | await translate(view.string.ReadOnlyWarningTitle, {}, getCurrentLanguage()), |
| 358 | await translate(view.string.ReadOnlyWarningMessage, {}, getCurrentLanguage()), |
| 359 | ReadOnlyNotification, |
| 360 | undefined, |
| 361 | NotificationSeverity.Info, |
| 362 | 'readOnlyNotification' |
| 363 | ) |
| 364 | return {} |
| 365 | } |
| 366 | try { |
| 367 | return await this.provideTx(tx) |
| 368 | } catch (err: any) { |
| 369 | if (err instanceof PlatformError && err.status.code === platform.status.Forbidden) { |
| 370 | addNotification( |
| 371 | await translate(view.string.PermissionWarningTitle, {}, getCurrentLanguage()), |
| 372 | await translate(view.string.PermissionWarningMessage, {}, getCurrentLanguage()), |
| 373 | ForbiddenNotification, |
| 374 | { |
| 375 | onClose: () => {} |
| 376 | }, |
| 377 | NotificationSeverity.Info |
| 378 | ) |
| 379 | return {} |
| 380 | } else { |
| 381 | throw err |
| 382 | } |
| 383 | } |
| 384 | } |
| 385 | } |
nothing calls this directly
no outgoing calls
no test coverage detected