@xrpl-wallet-kit/vue 0.0.0-stage → 0.1.23

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.
package/README.md CHANGED
@@ -1,3 +1,23 @@
1
- # Temporary Holding Version
1
+ # @xrpl-wallet-kit/vue
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Vue 3 bindings with app-scoped state, a wallet button and awaitable modal.
4
+ This package is implemented locally; npm publication is a separate release step.
5
+
6
+ ```ts
7
+ import { createWalletKitPlugin } from '@xrpl-wallet-kit/vue';
8
+ app.use(createWalletKitPlugin({ manager, autoReconnect: true }));
9
+ ```
10
+
11
+ ```vue
12
+ <script setup lang="ts">
13
+ import { WalletButton, useWalletKit } from '@xrpl-wallet-kit/vue';
14
+ const { account, status, signTransaction } = useWalletKit();
15
+ </script>
16
+ <template><WalletButton /><span>{{ account?.address }}</span></template>
17
+ ```
18
+
19
+ State is readonly and scoped to each application. DOM, availability checks and
20
+ optional restoration start on mount, not on import or during SSR. App unmount
21
+ detaches listeners and destroys the modal without disconnecting the caller-owned
22
+ manager. `useWalletModal().openAndWait()` preserves core errors and result types.
23
+ Do not reuse a manager between server requests. See the website Vue/Nuxt guides.
@@ -0,0 +1,193 @@
1
+ import type { InjectionKey, Plugin, PropType } from "vue";
2
+ import type { WalletAccount, WalletManager, WalletSession } from "@xrpl-wallet-kit/core";
3
+ import type { WalletButtonOptions, WalletModal, WalletUiConfig } from "@xrpl-wallet-kit/ui";
4
+ export interface WalletKitVueOptions {
5
+ manager: WalletManager;
6
+ ui?: WalletUiConfig;
7
+ /** Explicit opt-in; restoration never occurs during server rendering. */
8
+ autoReconnect?: boolean;
9
+ }
10
+ declare function createState(options: WalletKitVueOptions): {
11
+ buttonOptions: (overrides: Partial<Omit<WalletButtonOptions, "manager" | "modal" | "target">>) => Partial<Omit<WalletButtonOptions, "manager" | "modal" | "target">>;
12
+ manager: WalletManager;
13
+ session: Readonly<import("vue").Ref<{
14
+ readonly adapterId: string;
15
+ readonly wallet?: {
16
+ readonly id: string;
17
+ readonly name: string;
18
+ readonly type: import("@xrpl-wallet-kit/core").WalletAdapterType;
19
+ readonly icon?: string | undefined;
20
+ readonly group?: string | undefined;
21
+ readonly recommended?: boolean | undefined;
22
+ readonly homepage?: string | undefined;
23
+ readonly walletConnect?: {
24
+ readonly deeplink?: ((uri: string) => string) | undefined;
25
+ } | undefined;
26
+ } | undefined;
27
+ readonly account: {
28
+ readonly address: string;
29
+ readonly publicKey?: string | undefined;
30
+ readonly network?: {
31
+ readonly id: import("@xrpl-wallet-kit/core").WalletNetworkId;
32
+ readonly name: string;
33
+ readonly family?: import("@xrpl-wallet-kit/core").WalletNetworkFamily | undefined;
34
+ readonly networkType: "MAINNET" | "TESTNET" | "DEVNET" | "CUSTOM";
35
+ readonly nativeAsset?: string | undefined;
36
+ readonly nativeAssetDecimals?: number | undefined;
37
+ readonly rpcUrl: string;
38
+ readonly httpRpcUrl?: string | undefined;
39
+ readonly walletConnectChainId?: string | undefined;
40
+ readonly networkId?: number | undefined;
41
+ readonly definitionsUrl?: string | undefined;
42
+ readonly explorerTxUrl?: string | undefined;
43
+ readonly explorerAccountUrl?: string | undefined;
44
+ } | undefined;
45
+ readonly networkType?: string | undefined;
46
+ readonly activationStatus?: ("active" | "unfunded" | "unknown") | undefined;
47
+ };
48
+ readonly connectedAt: number;
49
+ readonly expiresAt?: number | undefined;
50
+ readonly balance?: {
51
+ readonly value: string;
52
+ readonly formatted: string;
53
+ readonly symbol?: string | undefined;
54
+ readonly activationStatus?: ("active" | "unfunded" | "unknown") | undefined;
55
+ readonly spendable?: boolean | undefined;
56
+ readonly reserveLocked?: boolean | undefined;
57
+ readonly available?: string | undefined;
58
+ readonly availableFormatted?: string | undefined;
59
+ readonly total?: string | undefined;
60
+ readonly totalFormatted?: string | undefined;
61
+ readonly reserve?: string | undefined;
62
+ readonly ownerCount?: number | undefined;
63
+ readonly raw?: Readonly<unknown> | undefined;
64
+ } | undefined;
65
+ readonly metadata?: {
66
+ readonly [x: string]: Readonly<unknown>;
67
+ } | undefined;
68
+ } | null, {
69
+ readonly adapterId: string;
70
+ readonly wallet?: {
71
+ readonly id: string;
72
+ readonly name: string;
73
+ readonly type: import("@xrpl-wallet-kit/core").WalletAdapterType;
74
+ readonly icon?: string | undefined;
75
+ readonly group?: string | undefined;
76
+ readonly recommended?: boolean | undefined;
77
+ readonly homepage?: string | undefined;
78
+ readonly walletConnect?: {
79
+ readonly deeplink?: ((uri: string) => string) | undefined;
80
+ } | undefined;
81
+ } | undefined;
82
+ readonly account: {
83
+ readonly address: string;
84
+ readonly publicKey?: string | undefined;
85
+ readonly network?: {
86
+ readonly id: import("@xrpl-wallet-kit/core").WalletNetworkId;
87
+ readonly name: string;
88
+ readonly family?: import("@xrpl-wallet-kit/core").WalletNetworkFamily | undefined;
89
+ readonly networkType: "MAINNET" | "TESTNET" | "DEVNET" | "CUSTOM";
90
+ readonly nativeAsset?: string | undefined;
91
+ readonly nativeAssetDecimals?: number | undefined;
92
+ readonly rpcUrl: string;
93
+ readonly httpRpcUrl?: string | undefined;
94
+ readonly walletConnectChainId?: string | undefined;
95
+ readonly networkId?: number | undefined;
96
+ readonly definitionsUrl?: string | undefined;
97
+ readonly explorerTxUrl?: string | undefined;
98
+ readonly explorerAccountUrl?: string | undefined;
99
+ } | undefined;
100
+ readonly networkType?: string | undefined;
101
+ readonly activationStatus?: ("active" | "unfunded" | "unknown") | undefined;
102
+ };
103
+ readonly connectedAt: number;
104
+ readonly expiresAt?: number | undefined;
105
+ readonly balance?: {
106
+ readonly value: string;
107
+ readonly formatted: string;
108
+ readonly symbol?: string | undefined;
109
+ readonly activationStatus?: ("active" | "unfunded" | "unknown") | undefined;
110
+ readonly spendable?: boolean | undefined;
111
+ readonly reserveLocked?: boolean | undefined;
112
+ readonly available?: string | undefined;
113
+ readonly availableFormatted?: string | undefined;
114
+ readonly total?: string | undefined;
115
+ readonly totalFormatted?: string | undefined;
116
+ readonly reserve?: string | undefined;
117
+ readonly ownerCount?: number | undefined;
118
+ readonly raw?: Readonly<unknown> | undefined;
119
+ } | undefined;
120
+ readonly metadata?: {
121
+ readonly [x: string]: Readonly<unknown>;
122
+ } | undefined;
123
+ } | null>>;
124
+ status: Readonly<import("vue").Ref<"disconnected" | "connecting" | "connected", "disconnected" | "connecting" | "connected">>;
125
+ wallets: Readonly<import("vue").Ref<readonly {
126
+ readonly id: string;
127
+ readonly name: string;
128
+ readonly type: import("@xrpl-wallet-kit/core").WalletAdapterType;
129
+ readonly icon?: string | undefined;
130
+ readonly group?: string | undefined;
131
+ readonly recommended?: boolean | undefined;
132
+ readonly homepage?: string | undefined;
133
+ readonly walletConnect?: {
134
+ readonly deeplink?: ((uri: string) => string) | undefined;
135
+ } | undefined;
136
+ }[], readonly {
137
+ readonly id: string;
138
+ readonly name: string;
139
+ readonly type: import("@xrpl-wallet-kit/core").WalletAdapterType;
140
+ readonly icon?: string | undefined;
141
+ readonly group?: string | undefined;
142
+ readonly recommended?: boolean | undefined;
143
+ readonly homepage?: string | undefined;
144
+ readonly walletConnect?: {
145
+ readonly deeplink?: ((uri: string) => string) | undefined;
146
+ } | undefined;
147
+ }[]>>;
148
+ availability: Readonly<import("vue").Ref<{
149
+ readonly [x: string]: boolean | "unknown";
150
+ }, {
151
+ readonly [x: string]: boolean | "unknown";
152
+ }>>;
153
+ modal: Readonly<import("vue").ShallowRef<WalletModal | null, WalletModal | null>>;
154
+ account: import("vue").ComputedRef<WalletAccount | null>;
155
+ start: () => void;
156
+ dispose: () => void;
157
+ refreshAvailability: () => Promise<void>;
158
+ connect: (id: string) => Promise<WalletSession>;
159
+ disconnect: () => Promise<void>;
160
+ signTransaction: <TTransaction extends import("@xrpl-wallet-kit/core").TransactionPayload = import("@xrpl-wallet-kit/core").TransactionPayload>(request: import("@xrpl-wallet-kit/core").SignTransactionRequest<TTransaction>) => Promise<import("@xrpl-wallet-kit/core").SignTransactionResult>;
161
+ signAndSubmit: <TTransaction extends import("@xrpl-wallet-kit/core").TransactionPayload = import("@xrpl-wallet-kit/core").TransactionPayload>(request: import("@xrpl-wallet-kit/core").SignAndSubmitRequest<TTransaction>) => Promise<import("@xrpl-wallet-kit/core").TxResult>;
162
+ signMessage: (request: import("@xrpl-wallet-kit/core").SignMessageRequest) => Promise<import("@xrpl-wallet-kit/core").SignMessageResult>;
163
+ openModal: () => void;
164
+ openAndWait: () => Promise<WalletSession>;
165
+ closeModal: () => void | undefined;
166
+ };
167
+ export type WalletKitVue = ReturnType<typeof createState>;
168
+ export declare const WalletKitKey: InjectionKey<WalletKitVue>;
169
+ export declare function createWalletKitPlugin(options: WalletKitVueOptions): Plugin;
170
+ export declare function useWalletKit(): WalletKitVue;
171
+ export declare function useWalletModal(): {
172
+ modal: Readonly<import("vue").ShallowRef<WalletModal | null, WalletModal | null>>;
173
+ open: () => void;
174
+ openAndWait: () => Promise<WalletSession>;
175
+ close: () => void | undefined;
176
+ };
177
+ export declare const WalletButton: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
178
+ options: {
179
+ type: PropType<Partial<Omit<WalletButtonOptions, "manager" | "modal" | "target">>>;
180
+ default: () => {};
181
+ };
182
+ }>, () => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
183
+ [key: string]: any;
184
+ }>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
185
+ options: {
186
+ type: PropType<Partial<Omit<WalletButtonOptions, "manager" | "modal" | "target">>>;
187
+ default: () => {};
188
+ };
189
+ }>> & Readonly<{}>, {
190
+ options: Partial<Omit<WalletButtonOptions, "manager" | "modal" | "target">>;
191
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
192
+ export {};
193
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/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C;;;;;;;cAA5E,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,mBAAmB,EAAE,SAAS,GAAG,OAAO,GAAG,QAAQ,CAAC,CAAC,CAAC;;;;;4EAchH,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,121 @@
1
+ import { computed, defineComponent, h, inject, onBeforeUnmount, onMounted, readonly, shallowReadonly, shallowRef, watch } from "vue";
2
+ import { createWalletButton, createWalletModal, resolveWalletButtonOptions } from "@xrpl-wallet-kit/ui";
3
+ function createState(options) {
4
+ const session = shallowRef(null);
5
+ const status = shallowRef("disconnected");
6
+ const wallets = shallowRef(options.manager.getWallets());
7
+ const availability = shallowRef({});
8
+ const modal = shallowRef(null);
9
+ let started = false;
10
+ let disposed = false;
11
+ let refreshVersion = 0;
12
+ const off = [];
13
+ const sync = () => {
14
+ session.value = options.manager.getSession();
15
+ status.value = session.value ? "connected" : "disconnected";
16
+ };
17
+ const refreshAvailability = async () => {
18
+ if (!started || disposed)
19
+ return;
20
+ const version = ++refreshVersion;
21
+ try {
22
+ const value = await options.manager.getWalletAvailability({ refresh: true });
23
+ if (!disposed && version === refreshVersion)
24
+ availability.value = value;
25
+ }
26
+ catch {
27
+ if (!disposed && version === refreshVersion)
28
+ availability.value = {};
29
+ }
30
+ };
31
+ const start = () => {
32
+ if (started || disposed || typeof document === "undefined")
33
+ return;
34
+ started = true;
35
+ sync();
36
+ modal.value = createWalletModal({ manager: options.manager, ...options.ui });
37
+ off.push(options.manager.on("connecting", () => { status.value = "connecting"; }));
38
+ for (const event of ["connected", "disconnected", "session_restored", "session_stale", "session_expired", "accountChanged", "networkChanged", "error"]) {
39
+ off.push(options.manager.on(event, sync));
40
+ }
41
+ off.push(options.manager.on("walletsChanged", () => {
42
+ wallets.value = options.manager.getWallets();
43
+ availability.value = Object.fromEntries(wallets.value.map(wallet => [wallet.id, "unknown"]));
44
+ void refreshAvailability();
45
+ }));
46
+ availability.value = Object.fromEntries(wallets.value.map(wallet => [wallet.id, "unknown"]));
47
+ void refreshAvailability();
48
+ if (options.autoReconnect)
49
+ void options.manager.autoReconnect().catch(sync);
50
+ };
51
+ const dispose = () => {
52
+ if (disposed)
53
+ return;
54
+ disposed = true;
55
+ refreshVersion++;
56
+ off.splice(0).forEach(stop => stop());
57
+ modal.value?.destroy();
58
+ modal.value = null;
59
+ session.value = null;
60
+ status.value = "disconnected";
61
+ // The caller owns the manager; unmount must not revoke wallet authorization.
62
+ };
63
+ const manager = options.manager;
64
+ return {
65
+ buttonOptions: (overrides) => resolveWalletButtonOptions(options.ui, overrides),
66
+ manager, session: readonly(session), status: readonly(status), wallets: readonly(wallets),
67
+ availability: readonly(availability), modal: shallowReadonly(modal),
68
+ account: computed(() => session.value?.account ?? null),
69
+ start, dispose, refreshAvailability,
70
+ connect: (id) => manager.connect(id), disconnect: () => manager.disconnect(),
71
+ signTransaction: manager.signTransaction.bind(manager), signAndSubmit: manager.signAndSubmit.bind(manager),
72
+ signMessage: manager.signMessage.bind(manager),
73
+ openModal: () => { start(); modal.value?.open(); },
74
+ openAndWait: () => {
75
+ start();
76
+ if (!modal.value)
77
+ return Promise.reject(new Error("Wallet modal is available only in the browser."));
78
+ return modal.value.openAndWait();
79
+ },
80
+ closeModal: () => modal.value?.close()
81
+ };
82
+ }
83
+ export const WalletKitKey = Symbol("XRPLWalletKit");
84
+ export function createWalletKitPlugin(options) {
85
+ return { install(app) {
86
+ const state = createState(options);
87
+ app.provide(WalletKitKey, state);
88
+ const unmount = app.unmount.bind(app);
89
+ app.unmount = () => { state.dispose(); unmount(); };
90
+ } };
91
+ }
92
+ export function useWalletKit() {
93
+ const state = inject(WalletKitKey);
94
+ if (!state)
95
+ throw new Error("Install createWalletKitPlugin before using useWalletKit.");
96
+ onMounted(state.start);
97
+ return state;
98
+ }
99
+ export function useWalletModal() {
100
+ const kit = useWalletKit();
101
+ return { modal: kit.modal, open: kit.openModal, openAndWait: kit.openAndWait, close: kit.closeModal };
102
+ }
103
+ export const WalletButton = defineComponent({
104
+ name: "WalletKitButton",
105
+ inheritAttrs: false,
106
+ props: { options: { type: Object, default: () => ({}) } },
107
+ setup(props, { attrs, expose }) {
108
+ const kit = useWalletKit();
109
+ const element = shallowRef(null);
110
+ let controller;
111
+ onMounted(() => {
112
+ if (!element.value || !kit.modal.value)
113
+ return;
114
+ controller = createWalletButton({ ...kit.buttonOptions(props.options), manager: kit.manager, modal: kit.modal.value, target: element.value });
115
+ });
116
+ watch(() => props.options, options => controller?.updateOptions(kit.buttonOptions(options)), { deep: true });
117
+ onBeforeUnmount(() => controller?.destroy());
118
+ expose({ element, get controller() { return controller; } });
119
+ return () => h("span", { ...attrs, ref: element });
120
+ }
121
+ });
package/package.json CHANGED
@@ -1,6 +1,17 @@
1
1
  {
2
2
  "name": "@xrpl-wallet-kit/vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.23",
4
+ "description": "App-scoped Vue 3 and Nuxt bindings for XRPL Wallet Kit.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "sideEffects": false,
8
+ "main": "./dist/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.js" } },
11
+ "files": ["dist", "README.md"],
12
+ "scripts": { "build": "tsc -p tsconfig.json" },
13
+ "dependencies": { "@xrpl-wallet-kit/core": "0.1.23", "@xrpl-wallet-kit/ui": "0.1.23" },
14
+ "peerDependencies": { "vue": "^3.3.0" },
15
+ "publishConfig": { "access": "public" },
16
+ "repository": { "type": "git", "url": "git+https://github.com/XRPDomains/xrpl-wallet-kit.git" }
17
+ }