FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

202
node_modules/@wallet-standard/app/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,202 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

5
node_modules/@wallet-standard/app/README.md generated vendored Normal file
View File

@@ -0,0 +1,5 @@
# `@wallet-standard/app`
This package defines functions to help apps support Wallets that implement the Wallet Standard.
This package contains TypeScript types and executable JavaScript code.

18
node_modules/@wallet-standard/app/lib/cjs/index.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./wallets.js"), exports);
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,+CAA6B"}

View File

@@ -0,0 +1 @@
{ "type": "commonjs" }

172
node_modules/@wallet-standard/app/lib/cjs/wallets.js generated vendored Normal file
View File

@@ -0,0 +1,172 @@
"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _AppReadyEvent_detail;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DEPRECATED_getWallets = exports.getWallets = void 0;
let wallets = undefined;
const registeredWalletsSet = new Set();
function addRegisteredWallet(wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.add(wallet);
}
function removeRegisteredWallet(wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.delete(wallet);
}
const listeners = {};
/**
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* When called for the first time --
*
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
* to register it.
*
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
* from each Wallet that the Wallet is ready to be registered by the app.
*
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
* as the app is ready whether the app loads before or after each Wallet.
*
* @return API for getting, listening for, and registering Wallets.
*
* @group App
*/
function getWallets() {
if (wallets)
return wallets;
wallets = Object.freeze({ register, get, on });
if (typeof window === 'undefined')
return wallets;
const api = Object.freeze({ register });
try {
window.addEventListener('wallet-standard:register-wallet', ({ detail: callback }) => callback(api));
}
catch (error) {
console.error('wallet-standard:register-wallet event listener could not be added\n', error);
}
try {
window.dispatchEvent(new AppReadyEvent(api));
}
catch (error) {
console.error('wallet-standard:app-ready event could not be dispatched\n', error);
}
return wallets;
}
exports.getWallets = getWallets;
function register(...wallets) {
var _a;
// Filter out wallets that have already been registered.
// This prevents the same wallet from being registered twice, but it also prevents wallets from being
// unregistered by reusing a reference to the wallet to obtain the unregister function for it.
wallets = wallets.filter((wallet) => !registeredWalletsSet.has(wallet));
// If there are no new wallets to register, just return a no-op unregister function.
// eslint-disable-next-line @typescript-eslint/no-empty-function
if (!wallets.length)
return () => { };
wallets.forEach((wallet) => addRegisteredWallet(wallet));
(_a = listeners['register']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => guard(() => listener(...wallets)));
// Return a function that unregisters the registered wallets.
return function unregister() {
var _a;
wallets.forEach((wallet) => removeRegisteredWallet(wallet));
(_a = listeners['unregister']) === null || _a === void 0 ? void 0 : _a.forEach((listener) => guard(() => listener(...wallets)));
};
}
let cachedWalletsArray;
function get() {
if (!cachedWalletsArray) {
cachedWalletsArray = [...registeredWalletsSet];
}
return cachedWalletsArray;
}
function on(event, listener) {
var _a;
((_a = listeners[event]) === null || _a === void 0 ? void 0 : _a.push(listener)) || (listeners[event] = [listener]);
// Return a function that removes the event listener.
return function off() {
var _a;
listeners[event] = (_a = listeners[event]) === null || _a === void 0 ? void 0 : _a.filter((existingListener) => listener !== existingListener);
};
}
function guard(callback) {
try {
callback();
}
catch (error) {
console.error(error);
}
}
class AppReadyEvent extends Event {
get detail() {
return __classPrivateFieldGet(this, _AppReadyEvent_detail, "f");
}
get type() {
return 'wallet-standard:app-ready';
}
constructor(api) {
super('wallet-standard:app-ready', {
bubbles: false,
cancelable: false,
composed: false,
});
_AppReadyEvent_detail.set(this, void 0);
__classPrivateFieldSet(this, _AppReadyEvent_detail, api, "f");
}
/** @deprecated */
preventDefault() {
throw new Error('preventDefault cannot be called');
}
/** @deprecated */
stopImmediatePropagation() {
throw new Error('stopImmediatePropagation cannot be called');
}
/** @deprecated */
stopPropagation() {
throw new Error('stopPropagation cannot be called');
}
}
_AppReadyEvent_detail = new WeakMap();
/**
* @deprecated Use {@link getWallets} instead.
*
* @group Deprecated
*/
function DEPRECATED_getWallets() {
if (wallets)
return wallets;
wallets = getWallets();
if (typeof window === 'undefined')
return wallets;
const callbacks = window.navigator.wallets || [];
if (!Array.isArray(callbacks)) {
console.error('window.navigator.wallets is not an array');
return wallets;
}
const { register } = wallets;
const push = (...callbacks) => callbacks.forEach((callback) => guard(() => callback({ register })));
try {
Object.defineProperty(window.navigator, 'wallets', {
value: Object.freeze({ push }),
});
}
catch (error) {
console.error('window.navigator.wallets could not be set');
return wallets;
}
push(...callbacks);
return wallets;
}
exports.DEPRECATED_getWallets = DEPRECATED_getWallets;
//# sourceMappingURL=wallets.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wallets.js","sourceRoot":"","sources":["../../src/wallets.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AASA,IAAI,OAAO,GAAwB,SAAS,CAAC;AAC7C,MAAM,oBAAoB,GAAG,IAAI,GAAG,EAAU,CAAC;AAC/C,SAAS,mBAAmB,CAAC,MAAc;IACvC,kBAAkB,GAAG,SAAS,CAAC;IAC/B,oBAAoB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACrC,CAAC;AACD,SAAS,sBAAsB,CAAC,MAAc;IAC1C,kBAAkB,GAAG,SAAS,CAAC;IAC/B,oBAAoB,CAAC,MAAM,CAAC,M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,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,IAAI,GAAG,CAAC,GAAG,SAAuC,EAAQ,EAAE,CAC9D,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC;QACD,MAAM,CAAC,cAAc,CAAE,MAAmC,CAAC,SAAS,EAAE,SAAS,EAAE;YAC7E,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;SACjC,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC3D,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACnB,OAAO,OAAO,CAAC;AACnB,CAAC;AAzBD,sDAyBC"}

2
node_modules/@wallet-standard/app/lib/esm/index.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
export * from './wallets.js';
//# sourceMappingURL=index.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}

163
node_modules/@wallet-standard/app/lib/esm/wallets.js generated vendored Normal file
View File

@@ -0,0 +1,163 @@
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
if (kind === "m") throw new TypeError("Private method is not writable");
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
};
var _AppReadyEvent_detail;
let wallets = undefined;
const registeredWalletsSet = new Set();
function addRegisteredWallet(wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.add(wallet);
}
function removeRegisteredWallet(wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.delete(wallet);
}
const listeners = {};
/**
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* When called for the first time --
*
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
* to register it.
*
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
* from each Wallet that the Wallet is ready to be registered by the app.
*
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
* as the app is ready whether the app loads before or after each Wallet.
*
* @return API for getting, listening for, and registering Wallets.
*
* @group App
*/
export function getWallets() {
if (wallets)
return wallets;
wallets = Object.freeze({ register, get, on });
if (typeof window === 'undefined')
return wallets;
const api = Object.freeze({ register });
try {
window.addEventListener('wallet-standard:register-wallet', ({ detail: callback }) => callback(api));
}
catch (error) {
console.error('wallet-standard:register-wallet event listener could not be added\n', error);
}
try {
window.dispatchEvent(new AppReadyEvent(api));
}
catch (error) {
console.error('wallet-standard:app-ready event could not be dispatched\n', error);
}
return wallets;
}
function register(...wallets) {
// Filter out wallets that have already been registered.
// This prevents the same wallet from being registered twice, but it also prevents wallets from being
// unregistered by reusing a reference to the wallet to obtain the unregister function for it.
wallets = wallets.filter((wallet) => !registeredWalletsSet.has(wallet));
// If there are no new wallets to register, just return a no-op unregister function.
// eslint-disable-next-line @typescript-eslint/no-empty-function
if (!wallets.length)
return () => { };
wallets.forEach((wallet) => addRegisteredWallet(wallet));
listeners['register']?.forEach((listener) => guard(() => listener(...wallets)));
// Return a function that unregisters the registered wallets.
return function unregister() {
wallets.forEach((wallet) => removeRegisteredWallet(wallet));
listeners['unregister']?.forEach((listener) => guard(() => listener(...wallets)));
};
}
let cachedWalletsArray;
function get() {
if (!cachedWalletsArray) {
cachedWalletsArray = [...registeredWalletsSet];
}
return cachedWalletsArray;
}
function on(event, listener) {
listeners[event]?.push(listener) || (listeners[event] = [listener]);
// Return a function that removes the event listener.
return function off() {
listeners[event] = listeners[event]?.filter((existingListener) => listener !== existingListener);
};
}
function guard(callback) {
try {
callback();
}
catch (error) {
console.error(error);
}
}
class AppReadyEvent extends Event {
get detail() {
return __classPrivateFieldGet(this, _AppReadyEvent_detail, "f");
}
get type() {
return 'wallet-standard:app-ready';
}
constructor(api) {
super('wallet-standard:app-ready', {
bubbles: false,
cancelable: false,
composed: false,
});
_AppReadyEvent_detail.set(this, void 0);
__classPrivateFieldSet(this, _AppReadyEvent_detail, api, "f");
}
/** @deprecated */
preventDefault() {
throw new Error('preventDefault cannot be called');
}
/** @deprecated */
stopImmediatePropagation() {
throw new Error('stopImmediatePropagation cannot be called');
}
/** @deprecated */
stopPropagation() {
throw new Error('stopPropagation cannot be called');
}
}
_AppReadyEvent_detail = new WeakMap();
/**
* @deprecated Use {@link getWallets} instead.
*
* @group Deprecated
*/
export function DEPRECATED_getWallets() {
if (wallets)
return wallets;
wallets = getWallets();
if (typeof window === 'undefined')
return wallets;
const callbacks = window.navigator.wallets || [];
if (!Array.isArray(callbacks)) {
console.error('window.navigator.wallets is not an array');
return wallets;
}
const { register } = wallets;
const push = (...callbacks) => callbacks.forEach((callback) => guard(() => callback({ register })));
try {
Object.defineProperty(window.navigator, 'wallets', {
value: Object.freeze({ push }),
});
}
catch (error) {
console.error('window.navigator.wallets could not be set');
return wallets;
}
push(...callbacks);
return wallets;
}
//# sourceMappingURL=wallets.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wallets.js","sourceRoot":"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,CAAC;IACvB,IAAI,OAAO,MAAM,KAAK,WAAW;QAAE,OAAO,OAAO,CAAC;IAElD,MAAM,SAAS,GAAI,MAAmC,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC;IAC/E,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;QAC5B,OAAO,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;QAC1D,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,MAAM,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC;IAC7B,MAAM,IAAI,GAAG,CAAC,GAAG,SAAuC,EAAQ,EAAE,CAC9D,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;IACzE,IAAI,CAAC;QACD,MAAM,CAAC,cAAc,CAAE,MAAmC,CAAC,SAAS,EAAE,SAAS,EAAE;YAC7E,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC;SACjC,CAAC,CAAC;IACP,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACb,OAAO,CAAC,KAAK,CAAC,2CAA2C,CAAC,CAAC;QAC3D,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,GAAG,SAAS,CAAC,CAAC;IACnB,OAAO,OAAO,CAAC;AACnB,CAAC"}

View File

@@ -0,0 +1,2 @@
export * from './wallets.js';
//# sourceMappingURL=index.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}

View File

@@ -0,0 +1,101 @@
import type { Wallet } from '@wallet-standard/base';
/**
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* When called for the first time --
*
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
* to register it.
*
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
* from each Wallet that the Wallet is ready to be registered by the app.
*
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
* as the app is ready whether the app loads before or after each Wallet.
*
* @return API for getting, listening for, and registering Wallets.
*
* @group App
*/
export declare function getWallets(): Wallets;
/**
* API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* @group App
*/
export interface Wallets {
/**
* Get all Wallets that have been registered.
*
* @return Registered Wallets.
*/
get(): readonly Wallet[];
/**
* Add an event listener and subscribe to events for Wallets that are
* {@link WalletsEventsListeners.register | registered} and
* {@link WalletsEventsListeners.unregister | unregistered}.
*
* @param event Event type to listen for. {@link WalletsEventsListeners.register | `register`} and
* {@link WalletsEventsListeners.unregister | `unregister`} are the only event types.
* @param listener Function that will be called when an event of the type is emitted.
*
* @return
* `off` function which may be called to remove the event listener and unsubscribe from events.
*
* As with all event listeners, be careful to avoid memory leaks.
*/
on<E extends WalletsEventNames>(event: E, listener: WalletsEventsListeners[E]): () => void;
/**
* Register Wallets. This can be used to programmatically wrap non-standard wallets as Standard Wallets.
*
* Apps generally do not need to, and should not, call this.
*
* @param wallets Wallets to register.
*
* @return
* `unregister` function which may be called to programmatically unregister the registered Wallets.
*
* Apps generally do not need to, and should not, call this.
*/
register(...wallets: Wallet[]): () => void;
}
/**
* Types of event listeners of the {@link Wallets} API.
*
* @group App
*/
export interface WalletsEventsListeners {
/**
* Emitted when Wallets are registered.
*
* @param wallets Wallets that were registered.
*/
register(...wallets: Wallet[]): void;
/**
* Emitted when Wallets are unregistered.
*
* @param wallets Wallets that were unregistered.
*/
unregister(...wallets: Wallet[]): void;
}
/**
* Names of {@link WalletsEventsListeners} that can be listened for.
*
* @group App
*/
export type WalletsEventNames = keyof WalletsEventsListeners;
/**
* @deprecated Use {@link WalletsEventsListeners} instead.
*
* @group Deprecated
*/
export type WalletsEvents = WalletsEventsListeners;
/**
* @deprecated Use {@link getWallets} instead.
*
* @group Deprecated
*/
export declare function DEPRECATED_getWallets(): Wallets;
//# sourceMappingURL=wallets.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"wallets.d.ts","sourceRoot":"","sources":["../../src/wallets.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGR,MAAM,EAIT,MAAM,uBAAuB,CAAC;AAc/B;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,IAAI,OAAO,CAoBpC;AAED;;;;;GAKG;AACH,MAAM,WAAW,OAAO;IACpB;;;;OAIG;IACH,GAAG,IAAI,SAAS,MAAM,EAAE,CAAC;IAEzB;;;;;;;;;;;;;OAaG;IACH,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,sBAAsB,CAAC,CAAC,CAAC,GAAG,MAAM,IAAI,CAAC;IAE3F;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,IAAI,CAAC;CAC9C;AAED;;;;GAIG;AACH,MAAM,WAAW,sBAAsB;IACnC;;;;OAIG;IACH,QAAQ,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;IAErC;;;;OAIG;IACH,UAAU,CAAC,GAAG,OAAO,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC;CAC1C;AAED;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,MAAM,sBAAsB,CAAC;AAE7D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAgFnD;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAyB/C"}

38
node_modules/@wallet-standard/app/package.json generated vendored Normal file
View File

@@ -0,0 +1,38 @@
{
"name": "@wallet-standard/app",
"version": "1.1.0",
"author": "Solana Maintainers <maintainers@solana.foundation>",
"repository": "https://github.com/wallet-standard/wallet-standard",
"license": "Apache-2.0",
"publishConfig": {
"access": "public"
},
"files": [
"lib",
"src",
"LICENSE"
],
"engines": {
"node": ">=16"
},
"type": "module",
"sideEffects": false,
"main": "./lib/cjs/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts",
"exports": {
"require": "./lib/cjs/index.js",
"import": "./lib/esm/index.js",
"types": "./lib/types/index.d.ts"
},
"dependencies": {
"@wallet-standard/base": "^1.1.0"
},
"devDependencies": {
"shx": "^0.3.4"
},
"scripts": {
"clean": "shx mkdir -p lib && shx rm -rf lib",
"package": "shx mkdir -p lib/cjs && shx echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json"
}
}

1
node_modules/@wallet-standard/app/src/index.ts generated vendored Normal file
View File

@@ -0,0 +1 @@
export * from './wallets.js';

251
node_modules/@wallet-standard/app/src/wallets.ts generated vendored Normal file
View File

@@ -0,0 +1,251 @@
import type {
DEPRECATED_WalletsCallback,
DEPRECATED_WalletsWindow,
Wallet,
WalletEventsWindow,
WindowAppReadyEvent,
WindowAppReadyEventAPI,
} from '@wallet-standard/base';
let wallets: Wallets | undefined = undefined;
const registeredWalletsSet = new Set<Wallet>();
function addRegisteredWallet(wallet: Wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.add(wallet);
}
function removeRegisteredWallet(wallet: Wallet) {
cachedWalletsArray = undefined;
registeredWalletsSet.delete(wallet);
}
const listeners: { [E in WalletsEventNames]?: WalletsEventsListeners[E][] } = {};
/**
* Get an API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* When called for the first time --
*
* This dispatches a {@link "@wallet-standard/base".WindowAppReadyEvent} to notify each Wallet that the app is ready
* to register it.
*
* This also adds a listener for {@link "@wallet-standard/base".WindowRegisterWalletEvent} to listen for a notification
* from each Wallet that the Wallet is ready to be registered by the app.
*
* This combination of event dispatch and listener guarantees that each Wallet will be registered synchronously as soon
* as the app is ready whether the app loads before or after each Wallet.
*
* @return API for getting, listening for, and registering Wallets.
*
* @group App
*/
export function getWallets(): Wallets {
if (wallets) return wallets;
wallets = Object.freeze({ register, get, on });
if (typeof window === 'undefined') return wallets;
const api = Object.freeze({ register });
try {
(window as WalletEventsWindow).addEventListener('wallet-standard:register-wallet', ({ detail: callback }) =>
callback(api)
);
} catch (error) {
console.error('wallet-standard:register-wallet event listener could not be added\n', error);
}
try {
(window as WalletEventsWindow).dispatchEvent(new AppReadyEvent(api));
} catch (error) {
console.error('wallet-standard:app-ready event could not be dispatched\n', error);
}
return wallets;
}
/**
* API for {@link Wallets.get | getting}, {@link Wallets.on | listening for}, and
* {@link Wallets.register | registering} {@link "@wallet-standard/base".Wallet | Wallets}.
*
* @group App
*/
export interface Wallets {
/**
* Get all Wallets that have been registered.
*
* @return Registered Wallets.
*/
get(): readonly Wallet[];
/**
* Add an event listener and subscribe to events for Wallets that are
* {@link WalletsEventsListeners.register | registered} and
* {@link WalletsEventsListeners.unregister | unregistered}.
*
* @param event Event type to listen for. {@link WalletsEventsListeners.register | `register`} and
* {@link WalletsEventsListeners.unregister | `unregister`} are the only event types.
* @param listener Function that will be called when an event of the type is emitted.
*
* @return
* `off` function which may be called to remove the event listener and unsubscribe from events.
*
* As with all event listeners, be careful to avoid memory leaks.
*/
on<E extends WalletsEventNames>(event: E, listener: WalletsEventsListeners[E]): () => void;
/**
* Register Wallets. This can be used to programmatically wrap non-standard wallets as Standard Wallets.
*
* Apps generally do not need to, and should not, call this.
*
* @param wallets Wallets to register.
*
* @return
* `unregister` function which may be called to programmatically unregister the registered Wallets.
*
* Apps generally do not need to, and should not, call this.
*/
register(...wallets: Wallet[]): () => void;
}
/**
* Types of event listeners of the {@link Wallets} API.
*
* @group App
*/
export interface WalletsEventsListeners {
/**
* Emitted when Wallets are registered.
*
* @param wallets Wallets that were registered.
*/
register(...wallets: Wallet[]): void;
/**
* Emitted when Wallets are unregistered.
*
* @param wallets Wallets that were unregistered.
*/
unregister(...wallets: Wallet[]): void;
}
/**
* Names of {@link WalletsEventsListeners} that can be listened for.
*
* @group App
*/
export type WalletsEventNames = keyof WalletsEventsListeners;
/**
* @deprecated Use {@link WalletsEventsListeners} instead.
*
* @group Deprecated
*/
export type WalletsEvents = WalletsEventsListeners;
function register(...wallets: Wallet[]): () => void {
// Filter out wallets that have already been registered.
// This prevents the same wallet from being registered twice, but it also prevents wallets from being
// unregistered by reusing a reference to the wallet to obtain the unregister function for it.
wallets = wallets.filter((wallet) => !registeredWalletsSet.has(wallet));
// If there are no new wallets to register, just return a no-op unregister function.
// eslint-disable-next-line @typescript-eslint/no-empty-function
if (!wallets.length) return () => {};
wallets.forEach((wallet) => addRegisteredWallet(wallet));
listeners['register']?.forEach((listener) => guard(() => listener(...wallets)));
// Return a function that unregisters the registered wallets.
return function unregister(): void {
wallets.forEach((wallet) => removeRegisteredWallet(wallet));
listeners['unregister']?.forEach((listener) => guard(() => listener(...wallets)));
};
}
let cachedWalletsArray: readonly Wallet[] | undefined;
function get(): readonly Wallet[] {
if (!cachedWalletsArray) {
cachedWalletsArray = [...registeredWalletsSet];
}
return cachedWalletsArray;
}
function on<E extends WalletsEventNames>(event: E, listener: WalletsEventsListeners[E]): () => void {
listeners[event]?.push(listener) || (listeners[event] = [listener]);
// Return a function that removes the event listener.
return function off(): void {
listeners[event] = listeners[event]?.filter((existingListener) => listener !== existingListener);
};
}
function guard(callback: () => void) {
try {
callback();
} catch (error) {
console.error(error);
}
}
class AppReadyEvent extends Event implements WindowAppReadyEvent {
readonly #detail: WindowAppReadyEventAPI;
get detail() {
return this.#detail;
}
get type() {
return 'wallet-standard:app-ready' as const;
}
constructor(api: WindowAppReadyEventAPI) {
super('wallet-standard:app-ready', {
bubbles: false,
cancelable: false,
composed: false,
});
this.#detail = api;
}
/** @deprecated */
preventDefault(): never {
throw new Error('preventDefault cannot be called');
}
/** @deprecated */
stopImmediatePropagation(): never {
throw new Error('stopImmediatePropagation cannot be called');
}
/** @deprecated */
stopPropagation(): never {
throw new Error('stopPropagation cannot be called');
}
}
/**
* @deprecated Use {@link getWallets} instead.
*
* @group Deprecated
*/
export function DEPRECATED_getWallets(): Wallets {
if (wallets) return wallets;
wallets = getWallets();
if (typeof window === 'undefined') return wallets;
const callbacks = (window as DEPRECATED_WalletsWindow).navigator.wallets || [];
if (!Array.isArray(callbacks)) {
console.error('window.navigator.wallets is not an array');
return wallets;
}
const { register } = wallets;
const push = (...callbacks: DEPRECATED_WalletsCallback[]): void =>
callbacks.forEach((callback) => guard(() => callback({ register })));
try {
Object.defineProperty((window as DEPRECATED_WalletsWindow).navigator, 'wallets', {
value: Object.freeze({ push }),
});
} catch (error) {
console.error('window.navigator.wallets could not be set');
return wallets;
}
push(...callbacks);
return wallets;
}