@rainlanguage/ui-components 0.0.1-alpha.24 → 0.0.1-alpha.26

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.
@@ -152,7 +152,7 @@ onDestroy(() => {
152
152
  <CardProperty>
153
153
  <svelte:fragment slot="key">Orders as output</svelte:fragment>
154
154
  <svelte:fragment slot="value">
155
- <p data-testid="vaulDetailOrdersAsOutput" class="flex flex-wrap justify-start">
155
+ <p data-testid="vaultDetailOrdersAsOutput" class="flex flex-wrap justify-start">
156
156
  {#if data.ordersAsOutput && data.ordersAsOutput.length > 0}
157
157
  {#each data.ordersAsOutput as order}
158
158
  <OrderOrVaultHash
package/dist/index.d.ts CHANGED
@@ -87,5 +87,7 @@ export { default as transactionStore } from './stores/transactionStore';
87
87
  export { mockTransactionStore } from './__mocks__/mockTransactionStore';
88
88
  export { default as logoLight } from './assets/logo-light.svg';
89
89
  export { default as logoDark } from './assets/logo-dark.svg';
90
- export { useGui } from './hooks/useGui';
91
90
  export { default as GuiProvider } from './providers/GuiProvider.svelte';
91
+ export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
92
+ export { useGui } from './hooks/useGui';
93
+ export { useAccount } from './providers/wallet/useAccount';
package/dist/index.js CHANGED
@@ -87,7 +87,9 @@ export { mockTransactionStore } from './__mocks__/mockTransactionStore';
87
87
  // Assets
88
88
  export { default as logoLight } from './assets/logo-light.svg';
89
89
  export { default as logoDark } from './assets/logo-dark.svg';
90
- // Hooks
91
- export { useGui } from './hooks/useGui';
92
90
  // Providers
93
91
  export { default as GuiProvider } from './providers/GuiProvider.svelte';
92
+ export { default as WalletProvider } from './providers/wallet/WalletProvider.svelte';
93
+ // Hooks
94
+ export { useGui } from './hooks/useGui';
95
+ export { useAccount } from './providers/wallet/useAccount';
@@ -0,0 +1,7 @@
1
+ <script>import { readable } from "svelte/store";
2
+ import { setAccountContext } from "./context";
3
+ export let account = readable(null);
4
+ setAccountContext(account);
5
+ </script>
6
+
7
+ <slot />
@@ -0,0 +1,21 @@
1
+ import { SvelteComponent } from "svelte";
2
+ import type { Account } from '../../types/account';
3
+ declare const __propDef: {
4
+ props: {
5
+ account?: Account;
6
+ };
7
+ events: {
8
+ [evt: string]: CustomEvent<any>;
9
+ };
10
+ slots: {
11
+ default: {};
12
+ };
13
+ exports?: {} | undefined;
14
+ bindings?: string | undefined;
15
+ };
16
+ export type WalletProviderProps = typeof __propDef.props;
17
+ export type WalletProviderEvents = typeof __propDef.events;
18
+ export type WalletProviderSlots = typeof __propDef.slots;
19
+ export default class WalletProvider extends SvelteComponent<WalletProviderProps, WalletProviderEvents, WalletProviderSlots> {
20
+ }
21
+ export {};
@@ -0,0 +1,10 @@
1
+ import type { Account } from '../../types/account';
2
+ export declare const ACCOUNT_KEY = "account_key";
3
+ /**
4
+ * Retrieves the account store directly from Svelte's context
5
+ */
6
+ export declare const getAccountContext: () => Account;
7
+ /**
8
+ * Sets the account store in Svelte's context
9
+ */
10
+ export declare const setAccountContext: (account: Account) => void;
@@ -0,0 +1,47 @@
1
+ import { getContext, setContext } from 'svelte';
2
+ import { readable } from 'svelte/store';
3
+ export const ACCOUNT_KEY = 'account_key';
4
+ /**
5
+ * Retrieves the account store directly from Svelte's context
6
+ */
7
+ export const getAccountContext = () => {
8
+ const account = getContext(ACCOUNT_KEY);
9
+ if (!account) {
10
+ throw new Error('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
11
+ }
12
+ return account;
13
+ };
14
+ /**
15
+ * Sets the account store in Svelte's context
16
+ */
17
+ export const setAccountContext = (account) => {
18
+ setContext(ACCOUNT_KEY, account);
19
+ };
20
+ if (import.meta.vitest) {
21
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
22
+ vi.mock('svelte', async (importOriginal) => ({
23
+ ...(await importOriginal()),
24
+ getContext: vi.fn()
25
+ }));
26
+ describe('getAccountContext', () => {
27
+ const mockGetContext = vi.mocked(getContext);
28
+ beforeEach(() => {
29
+ mockGetContext.mockReset();
30
+ });
31
+ it('should return the account from context when it exists', () => {
32
+ const mockAccount = readable('0x456');
33
+ mockGetContext.mockImplementation((key) => {
34
+ if (key === ACCOUNT_KEY)
35
+ return mockAccount;
36
+ return undefined;
37
+ });
38
+ const result = getAccountContext();
39
+ expect(mockGetContext).toHaveBeenCalledWith(ACCOUNT_KEY);
40
+ expect(result).toEqual(mockAccount);
41
+ });
42
+ it('should throw an error when account is not in context', () => {
43
+ mockGetContext.mockReturnValue(undefined);
44
+ expect(() => getAccountContext()).toThrow('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
45
+ });
46
+ });
47
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Hook to access wallet account information from context
3
+ * Must be used within a component that is a child of WalletProvider
4
+ */
5
+ export declare function useAccount(): {
6
+ account: import("../../types/account").Account;
7
+ };
@@ -0,0 +1,33 @@
1
+ import { getAccountContext } from './context';
2
+ import { readable } from 'svelte/store';
3
+ /**
4
+ * Hook to access wallet account information from context
5
+ * Must be used within a component that is a child of WalletProvider
6
+ */
7
+ export function useAccount() {
8
+ const account = getAccountContext();
9
+ return {
10
+ account
11
+ };
12
+ }
13
+ if (import.meta.vitest) {
14
+ const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
15
+ vi.mock('./context', () => ({
16
+ getAccountContext: vi.fn()
17
+ }));
18
+ describe('useAccount', () => {
19
+ const mockGetAccountContext = vi.mocked(getAccountContext);
20
+ beforeEach(() => {
21
+ mockGetAccountContext.mockReset();
22
+ });
23
+ it('should return account wrapped in an object', () => {
24
+ const mockAccount = readable('0x123');
25
+ mockGetAccountContext.mockReturnValue(mockAccount);
26
+ const result = useAccount();
27
+ expect(mockGetAccountContext).toHaveBeenCalled();
28
+ expect(result).toEqual({
29
+ account: mockAccount
30
+ });
31
+ });
32
+ });
33
+ }
@@ -0,0 +1,3 @@
1
+ import type { Readable } from 'svelte/store';
2
+ import type { Hex } from 'viem';
3
+ export type Account = Readable<Hex | null>;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.24",
3
+ "version": "0.0.1-alpha.26",
4
4
  "description": "A component library for building Svelte applications to be used with Raindex.",
5
5
  "license": "LicenseRef-DCL-1.0",
6
6
  "author": "Rain Open Source Software Ltd",
@@ -49,38 +49,38 @@
49
49
  "types": "./dist/index.d.ts",
50
50
  "type": "module",
51
51
  "dependencies": {
52
- "@codemirror/lang-yaml": "^6.0.0",
53
- "@fontsource/dm-sans": "^5.0.18",
54
- "@imask/svelte": "^7.3.0",
55
- "@observablehq/plot": "^0.6.13",
56
- "@rainlanguage/orderbook": "0.0.1-alpha.24",
57
- "@reown/appkit": "^1.6.4",
58
- "@reown/appkit-adapter-wagmi": "^1.6.4",
59
- "@sentry/sveltekit": "^7.107.0",
60
- "@square/svelte-store": "^1.0.18",
61
- "@sveltejs/kit": "^2.0.0",
62
- "@tanstack/svelte-query": "^5.59.20",
63
- "@wagmi/core": "^2.16.3",
64
- "@walletconnect/ethereum-provider": "^2.11.3",
65
- "@walletconnect/modal": "^2.6.2",
66
- "@web3modal/ethers5": "^4.1.1",
67
- "camelcase-keys": "^9.1.3",
68
- "codemirror-rainlang": "^3.0.13",
69
- "dayjs": "^1.11.13",
70
- "ethers": "^5.7.2",
71
- "flowbite": "^2.2.1",
72
- "flowbite-svelte": "^0.44.21",
73
- "flowbite-svelte-icons": "^0.4.5",
74
- "fuse.js": "^7.0.0",
75
- "lightweight-charts": "^4.1.3",
76
- "lodash": "^4.17.21",
77
- "svelte": "^4.2.7",
78
- "svelte-codemirror-editor": "^1.3.0",
79
- "svelte-markdown": "^0.4.1",
80
- "tailwind-merge": "^2.5.4",
81
- "thememirror": "^2.0.1",
82
- "uuid": "^9.0.1",
83
- "viem": "^2.22.8",
84
- "wagmi": "^2.14.7"
52
+ "@codemirror/lang-yaml": "6.1.1",
53
+ "@fontsource/dm-sans": "5.1.0",
54
+ "@imask/svelte": "7.6.1",
55
+ "@observablehq/plot": "0.6.16",
56
+ "@rainlanguage/orderbook": "0.0.1-alpha.26",
57
+ "@reown/appkit": "1.6.4",
58
+ "@reown/appkit-adapter-wagmi": "1.6.4",
59
+ "@sentry/sveltekit": "7.120.0",
60
+ "@square/svelte-store": "1.0.18",
61
+ "@sveltejs/kit": "2.8.1",
62
+ "@tanstack/svelte-query": "5.59.20",
63
+ "@wagmi/core": "2.16.3",
64
+ "@walletconnect/ethereum-provider": "2.17.2",
65
+ "@walletconnect/modal": "2.7.0",
66
+ "@web3modal/ethers5": "4.2.3",
67
+ "camelcase-keys": "9.1.3",
68
+ "codemirror-rainlang": "3.0.13",
69
+ "dayjs": "1.11.13",
70
+ "ethers": "5.7.2",
71
+ "flowbite": "2.5.2",
72
+ "flowbite-svelte": "0.44.24",
73
+ "flowbite-svelte-icons": "0.4.5",
74
+ "fuse.js": "7.0.0",
75
+ "lightweight-charts": "4.2.1",
76
+ "lodash": "4.17.21",
77
+ "svelte": "4.2.19",
78
+ "svelte-codemirror-editor": "1.4.1",
79
+ "svelte-markdown": "0.4.1",
80
+ "tailwind-merge": "2.5.4",
81
+ "thememirror": "2.0.1",
82
+ "uuid": "9.0.1",
83
+ "viem": "2.22.8",
84
+ "wagmi": "2.14.7"
85
85
  }
86
86
  }