fix: trois coûts qui revenaient à l'appelant reviennent au paquet
Le contrat faisait porter à l'application trois choses qui sont des artefacts de notre implémentation, pas de la cible. Le rechargement de page. Au retour depuis le cache du navigateur, la barrière se rechargeait pour rejouer init() — et détruisait au passage l'état de l'application, qui ne pouvait ni s'y opposer ni nettoyer avant. Le paquet détenait pourtant ce qu'il fallait : la fonction init injectée et le callback de l'appelant. Il enregistre désormais sa délégation, ranime sa barrière au retour — champ conservé, bouton réactivé — et redélègue à la confirmation. Rien hors de la barrière n'est touché. Vérifié dans le bundle amont : en page de tête, init navigue à chaque appel, sa garde « une seule fois » ne portant que sur la branche iframe. L'ordre d'appel silencieux. ensureIdentity() attendu avant init() ne se résolvait jamais, sans erreur. Le paquet possédant la session, il distingue maintenant les deux cas sans délai ni heuristique : session pas encore arrivée → il attend ; init jamais appelé → elle n'arrivera pas, il lève en nommant l'appel à faire d'abord. Et la clause qui annonçait la barrière était rangée dans les exigences de déploiement, alors qu'une application n'y peut rien. Elle passe dans les garanties, avec ce qui la remplace : la page n'est jamais rechargée. Il reste deux lignes d'exigences : servir le fichier de portefeuille, et appeler init avant d'attendre l'identité — ce qui échoue désormais bruyamment.
This commit is contained in:
@@ -20,9 +20,9 @@
|
||||
* (`shared-wallet/access-gate.ts`, {@link settleIdentity}).
|
||||
*/
|
||||
|
||||
import { getConfig } from "../shared-wallet/bootstrap";
|
||||
import { getConfig, rememberHandOver } from "../shared-wallet/bootstrap";
|
||||
import { settleIdentity } from "../shared-wallet/access-gate";
|
||||
import { captureSession } from "../shared-wallet/session";
|
||||
import { captureSession, expectSession } from "../shared-wallet/session";
|
||||
|
||||
/**
|
||||
* Forwards to the real `@ng-org/web` `init`, once the identifier is in the address bar.
|
||||
@@ -66,7 +66,27 @@ export function init(...args: any[]): any {
|
||||
captureSession(event);
|
||||
return typeof callback === "function" ? callback(event) : undefined;
|
||||
};
|
||||
return settleIdentity().then(() => f(listen, ...rest));
|
||||
const delegate = (): unknown => f(listen, ...rest);
|
||||
// Two notes taken on the way in, both about what only this call can know.
|
||||
//
|
||||
// The hand-over, first: this delegation is the whole of it, and a person who reaches the
|
||||
// broker without a wallet comes back to THIS document with it already spent. The barrier
|
||||
// revives there and needs something to hand the page over with — this, exactly as it
|
||||
// would have run the first time (`shared-wallet/access-gate.ts`).
|
||||
rememberHandOver((): void => {
|
||||
// Un-awaited, and it has to be: the promise this call returned was answered on the way
|
||||
// out, so a rejection here has no caller to reach. Reported rather than dropped as an
|
||||
// unhandled rejection — the page is on its way to the broker either way.
|
||||
void Promise.resolve(delegate()).catch((failure: unknown) => {
|
||||
console.error("[ng-eventually] the hand-over to the broker failed", failure);
|
||||
});
|
||||
});
|
||||
// And that it RAN. The session arrives through this call and through no other, so
|
||||
// "`init()` has not been called" is the same statement as "no session can ever arrive" —
|
||||
// which is what lets `ensureIdentity()` refuse an impossible wait instead of hanging on it
|
||||
// (`shared-wallet/session.ts`, `shared-wallet/access-gate.ts`).
|
||||
expectSession();
|
||||
return settleIdentity().then(delegate);
|
||||
}
|
||||
|
||||
/** Forwards to the real `@ng-org/orm` `initNg` (ORM signals). */
|
||||
|
||||
Reference in New Issue
Block a user