@rainlanguage/ui-components 0.0.1-alpha.46 → 0.0.1-alpha.48

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.
@@ -1,22 +1,25 @@
1
1
  <script>import { Button } from "flowbite-svelte";
2
2
  import Hash, { HashType } from "./Hash.svelte";
3
+ import {
4
+ constructHashLink,
5
+ isOrderOrVaultActive,
6
+ extractHash
7
+ } from "../utils/constructHashLink";
3
8
  export let orderOrVault;
4
9
  export let type;
5
10
  export let network;
6
11
  export let updateActiveNetworkAndOrderbook;
7
- let hash;
8
- $: isOrder = "orderHash" in (orderOrVault || {});
9
- $: slug = isOrder ? orderOrVault.orderHash : orderOrVault?.id;
10
- $: hash = isOrder ? orderOrVault.orderHash : orderOrVault?.id || "";
11
- $: isActive = isOrder ? orderOrVault.active : false;
12
+ $: hash = extractHash(orderOrVault);
13
+ $: isActive = isOrderOrVaultActive(orderOrVault);
14
+ $: linkPath = constructHashLink(orderOrVault, type, network);
12
15
  </script>
13
16
 
14
- <a href={`/${type}/${network}-${slug}`}>
17
+ <a data-testid="order-or-vault-hash" href={linkPath}>
15
18
  <Button
16
19
  class="mr-1 mt-1 px-2 py-1 text-sm"
17
20
  color={isActive ? 'green' : 'yellow'}
18
21
  data-testid="vault-order-input"
19
- data-id={slug}
22
+ data-id={hash}
20
23
  on:click={() => {
21
24
  updateActiveNetworkAndOrderbook(network);
22
25
  }}><Hash type={HashType.Identifier} value={hash} copyOnClick={false} /></Button
@@ -27,6 +27,7 @@ export let deployment;
27
27
  export let strategyDetail;
28
28
  export let handleDeployModal;
29
29
  export let handleDisclaimerModal;
30
+ export let registryUrl;
30
31
  let allDepositFields = [];
31
32
  let allTokenOutputs = [];
32
33
  let allFieldDefinitionsWithoutDefaults = [];
@@ -123,7 +124,7 @@ async function updateFields() {
123
124
  }
124
125
  }
125
126
  async function _handleShareChoices() {
126
- await handleShareChoices(gui);
127
+ await handleShareChoices(gui, registryUrl);
127
128
  }
128
129
  async function onSelectTokenSelect() {
129
130
  await areAllTokensSelected();
@@ -17,6 +17,7 @@ declare const __propDef: {
17
17
  strategyDetail: NameAndDescriptionCfg;
18
18
  handleDeployModal: (args: DeployModalProps) => void;
19
19
  handleDisclaimerModal: (args: DisclaimerModalProps) => void;
20
+ registryUrl: string;
20
21
  wagmiConfig: Writable<Config | undefined>;
21
22
  wagmiConnected: Writable<boolean>;
22
23
  appKitModal: Writable<AppKit>;
@@ -1,2 +1,2 @@
1
1
  import type { DotrainOrderGui } from '@rainlanguage/orderbook/js_api';
2
- export declare function handleShareChoices(gui: DotrainOrderGui): Promise<void>;
2
+ export declare function handleShareChoices(gui: DotrainOrderGui, registryUrl: string): Promise<void>;
@@ -1,6 +1,6 @@
1
1
  import { page } from '$app/stores';
2
2
  import { get } from 'svelte/store';
3
- export async function handleShareChoices(gui) {
3
+ export async function handleShareChoices(gui, registryUrl) {
4
4
  // get the current url
5
5
  const url = get(page).url;
6
6
  // get the current state
@@ -10,5 +10,6 @@ export async function handleShareChoices(gui) {
10
10
  }
11
11
  const state = result.value;
12
12
  url.searchParams.set('state', state || '');
13
+ url.searchParams.set('registry', registryUrl);
13
14
  navigator.clipboard.writeText(url.toString());
14
15
  }
@@ -0,0 +1,23 @@
1
+ import type { SgOrder, SgOrderAsIO, SgVault } from '@rainlanguage/orderbook/js_api';
2
+ type OrderOrVault = SgOrder | SgOrderAsIO | SgVault;
3
+ /**
4
+ * Constructs a link path for an order or vault based on its type and network
5
+ * @param orderOrVault - The order or vault object
6
+ * @param type - The type of resource ('orders' or 'vaults')
7
+ * @param network - The network name
8
+ * @returns The constructed link path
9
+ */
10
+ export declare function constructHashLink(orderOrVault: OrderOrVault, type: 'orders' | 'vaults', network: string): string;
11
+ /**
12
+ * Determines if an order or vault is active
13
+ * @param orderOrVault - The order or vault object
14
+ * @returns True if the order is active, false otherwise
15
+ */
16
+ export declare function isOrderOrVaultActive(orderOrVault: OrderOrVault): boolean;
17
+ /**
18
+ * Extracts the hash value from an order or vault
19
+ * @param orderOrVault - The order or vault object
20
+ * @returns The hash value
21
+ */
22
+ export declare function extractHash(orderOrVault: OrderOrVault): string;
23
+ export {};
@@ -0,0 +1,110 @@
1
+ import fc from 'fast-check';
2
+ import { test } from '@fast-check/vitest';
3
+ function isOrder(obj) {
4
+ return obj && 'orderHash' in obj;
5
+ }
6
+ /**
7
+ * Constructs a link path for an order or vault based on its type and network
8
+ * @param orderOrVault - The order or vault object
9
+ * @param type - The type of resource ('orders' or 'vaults')
10
+ * @param network - The network name
11
+ * @returns The constructed link path
12
+ */
13
+ export function constructHashLink(orderOrVault, type, network) {
14
+ if (!orderOrVault) {
15
+ return `/${type}/${network}`;
16
+ }
17
+ const slug = isOrder(orderOrVault) ? orderOrVault.orderHash : orderOrVault?.id;
18
+ return `/${type}/${network}-${slug || ''}`;
19
+ }
20
+ /**
21
+ * Determines if an order or vault is active
22
+ * @param orderOrVault - The order or vault object
23
+ * @returns True if the order is active, false otherwise
24
+ */
25
+ export function isOrderOrVaultActive(orderOrVault) {
26
+ const _isOrder = isOrder(orderOrVault);
27
+ return _isOrder ? orderOrVault.active : false;
28
+ }
29
+ /**
30
+ * Extracts the hash value from an order or vault
31
+ * @param orderOrVault - The order or vault object
32
+ * @returns The hash value
33
+ */
34
+ export function extractHash(orderOrVault) {
35
+ const _isOrder = isOrder(orderOrVault);
36
+ return _isOrder ? orderOrVault.orderHash : orderOrVault?.id || '';
37
+ }
38
+ if (import.meta.vitest) {
39
+ const { expect, it, describe } = import.meta.vitest;
40
+ describe('constructHashLink', () => {
41
+ test.prop([
42
+ fc.record({
43
+ orderHash: fc.string(),
44
+ active: fc.boolean()
45
+ }),
46
+ fc.oneof(fc.constant('orders'), fc.constant('vaults')),
47
+ fc.string()
48
+ ])('constructs correct link for orders', (order, type, network) => {
49
+ const result = constructHashLink(order, type, network);
50
+ expect(result).toBe(`/${type}/${network}-${order.orderHash}`);
51
+ });
52
+ test.prop([
53
+ fc.record({
54
+ id: fc.string(),
55
+ owner: fc.string()
56
+ }),
57
+ fc.oneof(fc.constant('orders'), fc.constant('vaults')),
58
+ fc.string()
59
+ ])('constructs correct link for vaults', (vault, type, network) => {
60
+ const result = constructHashLink(vault, type, network);
61
+ expect(result).toBe(`/${type}/${network}-${vault.id}`);
62
+ });
63
+ });
64
+ describe('isOrderOrVaultActive', () => {
65
+ test.prop([
66
+ fc.record({
67
+ orderHash: fc.string(),
68
+ active: fc.boolean()
69
+ })
70
+ ])('returns correct active status for orders', (order) => {
71
+ const result = isOrderOrVaultActive(order);
72
+ expect(result).toBe(order.active);
73
+ });
74
+ test.prop([
75
+ fc.record({
76
+ id: fc.string(),
77
+ owner: fc.string()
78
+ })
79
+ ])('returns false for vaults', (vault) => {
80
+ const result = isOrderOrVaultActive(vault);
81
+ expect(result).toBe(false);
82
+ });
83
+ });
84
+ describe('extractHash', () => {
85
+ test.prop([
86
+ fc.record({
87
+ orderHash: fc.string(),
88
+ active: fc.boolean()
89
+ })
90
+ ])('extracts hash from orders', (order) => {
91
+ const result = extractHash(order);
92
+ expect(result).toBe(order.orderHash);
93
+ });
94
+ test.prop([
95
+ fc.record({
96
+ id: fc.string(),
97
+ owner: fc.string()
98
+ })
99
+ ])('extracts hash from vaults', (vault) => {
100
+ const result = extractHash(vault);
101
+ expect(result).toBe(vault.id);
102
+ });
103
+ it('handles undefined vault id', () => {
104
+ // Create a partial vault object with undefined id
105
+ const vault = { id: undefined };
106
+ const result = extractHash(vault);
107
+ expect(result).toBe('');
108
+ });
109
+ });
110
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rainlanguage/ui-components",
3
- "version": "0.0.1-alpha.46",
3
+ "version": "0.0.1-alpha.48",
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",
@@ -53,7 +53,7 @@
53
53
  "@fontsource/dm-sans": "5.1.0",
54
54
  "@imask/svelte": "7.6.1",
55
55
  "@observablehq/plot": "0.6.16",
56
- "@rainlanguage/orderbook": "0.0.1-alpha.46",
56
+ "@rainlanguage/orderbook": "0.0.1-alpha.48",
57
57
  "@reown/appkit": "1.6.4",
58
58
  "@reown/appkit-adapter-wagmi": "1.6.4",
59
59
  "@sentry/sveltekit": "7.120.0",