@rainlanguage/ui-components 0.0.1-alpha.21 → 0.0.1-alpha.210
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/dist/__fixtures__/settings.yaml +125 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
- package/dist/__mocks__/MockComponent.svelte +4 -0
- package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
- package/dist/__mocks__/stores.d.ts +47 -33
- package/dist/__mocks__/stores.js +61 -38
- package/dist/components/ButtonLoading.svelte +1 -1
- package/dist/components/ButtonVaultLink.svelte +11 -11
- package/dist/components/ButtonVaultLink.svelte.d.ts +4 -3
- package/dist/components/CheckboxInactiveOrdersVault.svelte +20 -0
- package/dist/components/CheckboxInactiveOrdersVault.svelte.d.ts +19 -0
- package/dist/components/CheckboxMyItemsOnly.svelte +3 -2
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +2 -3
- package/dist/components/CheckboxZeroBalanceVault.svelte.d.ts +2 -2
- package/dist/components/CodeMirrorDotrain.svelte +4 -0
- package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
- package/dist/components/CodeMirrorRainlang.svelte +3 -12
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +2 -2
- package/dist/components/EditableSpan.svelte +3 -14
- package/dist/components/EditableSpan.svelte.d.ts +0 -1
- package/dist/components/Hash.svelte +3 -3
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewOrderbookFilters.svelte +45 -23
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +27 -22
- package/dist/components/LocalDbStatusBadge.svelte +27 -0
- package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
- package/dist/components/LocalDbStatusCard.svelte +40 -0
- package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
- package/dist/components/LocalDbStatusModal.svelte +103 -0
- package/dist/components/LocalDbStatusModal.svelte.d.ts +21 -0
- package/dist/components/OrderOrVaultHash.svelte +12 -12
- package/dist/components/OrderOrVaultHash.svelte.d.ts +4 -4
- package/dist/components/PageHeader.svelte +1 -1
- package/dist/components/TanstackAppTable.svelte +179 -28
- package/dist/components/TanstackAppTable.svelte.d.ts +14 -8
- package/dist/components/ToastDetail.svelte +42 -0
- package/dist/components/ToastDetail.svelte.d.ts +20 -0
- package/dist/components/Tooltip.svelte +8 -0
- package/dist/components/Tooltip.svelte.d.ts +21 -0
- package/dist/components/VaultBalanceChangeTypeFilter.svelte +23 -0
- package/dist/components/VaultBalanceChangeTypeFilter.svelte.d.ts +19 -0
- package/dist/components/VaultCard.svelte +18 -0
- package/dist/components/VaultCard.svelte.d.ts +19 -0
- package/dist/components/charts/LightweightChart.svelte +1 -1
- package/dist/components/charts/LightweightChart.svelte.d.ts +5 -5
- package/dist/components/charts/OrderTradesChart.svelte +300 -28
- package/dist/components/charts/OrderTradesChart.svelte.d.ts +4 -4
- package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
- package/dist/components/charts/VaultBalanceChart.svelte +8 -26
- package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -7
- package/dist/components/charts/transformAndSortData.d.ts +24 -0
- package/dist/components/charts/transformAndSortData.js +111 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte +11 -0
- package/dist/components/checkbox/CheckboxActiveOrders.svelte.d.ts +19 -0
- package/dist/components/deployment/ButtonSelectOption.svelte +2 -0
- package/dist/components/deployment/ButtonSelectOption.svelte.d.ts +1 -0
- package/dist/components/deployment/ComposedRainlangModal.svelte +2 -1
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +209 -216
- package/dist/components/deployment/DeploymentSteps.svelte.d.ts +6 -12
- package/dist/components/deployment/DeploymentTile.svelte +2 -2
- package/dist/components/deployment/DeploymentTile.svelte.d.ts +1 -1
- package/dist/components/deployment/DeploymentsSection.svelte +15 -22
- package/dist/components/deployment/DeploymentsSection.svelte.d.ts +3 -2
- package/dist/components/deployment/DepositInput.svelte +8 -10
- package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
- package/dist/components/deployment/DisclaimerModal.svelte +6 -7
- package/dist/components/deployment/FieldDefinitionInput.svelte +7 -11
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
- package/dist/components/deployment/InvalidOrdersSection.svelte +17 -0
- package/dist/components/deployment/InvalidOrdersSection.svelte.d.ts +19 -0
- package/dist/components/deployment/{StrategyPage.svelte → OrderPage.svelte} +15 -24
- package/dist/components/deployment/OrderPage.svelte.d.ts +21 -0
- package/dist/components/deployment/SelectToken.svelte +125 -48
- package/dist/components/deployment/SelectToken.svelte.d.ts +4 -3
- package/dist/components/deployment/TokenBalance.svelte +19 -0
- package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
- package/dist/components/deployment/TokenIOInput.svelte +25 -15
- package/dist/components/deployment/TokenIOInput.svelte.d.ts +3 -3
- package/dist/components/deployment/TokenSelectionModal.svelte +148 -0
- package/dist/components/deployment/TokenSelectionModal.svelte.d.ts +20 -0
- package/dist/components/deployment/{ValidStrategiesSection.svelte → ValidOrdersSection.svelte} +7 -7
- package/dist/components/deployment/ValidOrdersSection.svelte.d.ts +19 -0
- package/dist/components/deployment/VaultIdInformation.svelte +17 -0
- package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
- package/dist/components/detail/OrderDetail.svelte +184 -80
- package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
- package/dist/components/detail/TanstackOrderQuote.svelte +92 -46
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
- package/dist/components/detail/VaultDetail.svelte +78 -77
- package/dist/components/detail/VaultDetail.svelte.d.ts +12 -18
- package/dist/components/dropdown/DropdownActiveNetworks.svelte +44 -0
- package/dist/components/dropdown/DropdownActiveNetworks.svelte.d.ts +19 -0
- package/dist/components/dropdown/DropdownCheckbox.svelte +4 -4
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte +5 -2
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +2 -3
- package/dist/components/dropdown/DropdownOrderbooksFilter.svelte +172 -0
- package/dist/components/dropdown/DropdownOrderbooksFilter.svelte.d.ts +25 -0
- package/dist/components/dropdown/DropdownTokensFilter.svelte +152 -0
- package/dist/components/dropdown/DropdownTokensFilter.svelte.d.ts +28 -0
- package/dist/components/icon/Refresh.svelte +2 -1
- package/dist/components/icon/Refresh.svelte.d.ts +1 -0
- package/dist/components/input/InputOrderHash.svelte +1 -1
- package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
- package/dist/components/input/InputRegistryUrl.svelte +36 -14
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +16 -21
- package/dist/components/input/InputTokenAmount.svelte.d.ts +3 -3
- package/dist/components/tables/OrderAPY.svelte +6 -33
- package/dist/components/tables/OrderAPY.svelte.d.ts +1 -4
- package/dist/components/tables/OrderTradesListTable.svelte +84 -81
- package/dist/components/tables/OrderTradesListTable.svelte.d.ts +4 -4
- package/dist/components/tables/OrderVaultsVolTable.svelte +17 -22
- package/dist/components/tables/OrderVaultsVolTable.svelte.d.ts +2 -2
- package/dist/components/tables/OrdersListTable.svelte +200 -108
- package/dist/components/tables/OrdersListTable.svelte.d.ts +17 -21
- package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
- package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
- package/dist/components/tables/VaultsListTable.svelte +268 -145
- package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -32
- package/dist/components/transactions/FixedBottomTransaction.svelte +63 -0
- package/dist/components/transactions/FixedBottomTransaction.svelte.d.ts +16 -0
- package/dist/components/transactions/TransactionDetail.svelte +31 -0
- package/dist/components/transactions/TransactionDetail.svelte.d.ts +20 -0
- package/dist/components/transactions/TransactionList.svelte +17 -0
- package/dist/components/transactions/TransactionList.svelte.d.ts +16 -0
- package/dist/components/transactions/getStatusEmoji.d.ts +2 -0
- package/dist/components/transactions/getStatusEmoji.js +20 -0
- package/dist/components/wallet/WalletConnect.svelte +5 -4
- package/dist/components/wallet/WalletConnect.svelte.d.ts +0 -1
- package/dist/consts.d.ts +1 -0
- package/dist/consts.js +1 -0
- package/dist/errors/DeploymentStepsError.d.ts +8 -2
- package/dist/errors/DeploymentStepsError.js +7 -1
- package/dist/hooks/useGui.d.ts +1 -1
- package/dist/hooks/useGui.js +1 -1
- package/dist/hooks/useLocalDb.d.ts +3 -0
- package/dist/hooks/useLocalDb.js +10 -0
- package/dist/hooks/useRaindexClient.d.ts +3 -0
- package/dist/hooks/useRaindexClient.js +11 -0
- package/dist/index.d.ts +42 -19
- package/dist/index.js +41 -16
- package/dist/models/Transaction.d.ts +75 -0
- package/dist/models/Transaction.js +100 -0
- package/dist/providers/GuiProvider.svelte +1 -1
- package/dist/providers/GuiProvider.svelte.d.ts +1 -1
- package/dist/providers/LocalDbProvider.svelte +8 -0
- package/dist/providers/LocalDbProvider.svelte.d.ts +21 -0
- package/dist/providers/RaindexClientProvider.svelte +8 -0
- package/dist/providers/RaindexClientProvider.svelte.d.ts +21 -0
- package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte +8 -0
- package/dist/providers/dotrainRegistry/DotrainRegistryProvider.svelte.d.ts +24 -0
- package/dist/providers/dotrainRegistry/context.d.ts +9 -0
- package/dist/providers/dotrainRegistry/context.js +40 -0
- package/dist/providers/dotrainRegistry/useDotrainRegistry.d.ts +5 -0
- package/dist/providers/dotrainRegistry/useDotrainRegistry.js +35 -0
- package/dist/providers/registry/RegistryManager.d.ts +65 -0
- package/dist/providers/registry/RegistryManager.js +133 -0
- package/dist/providers/registry/RegistryProvider.svelte +6 -0
- package/dist/providers/registry/RegistryProvider.svelte.d.ts +21 -0
- package/dist/providers/registry/context.d.ts +10 -0
- package/dist/providers/registry/context.js +46 -0
- package/dist/providers/registry/useRegistry.d.ts +7 -0
- package/dist/providers/registry/useRegistry.js +29 -0
- package/dist/providers/toasts/ToastProvider.svelte +17 -0
- package/dist/providers/toasts/ToastProvider.svelte.d.ts +18 -0
- package/dist/providers/toasts/context.d.ts +14 -0
- package/dist/providers/toasts/context.js +22 -0
- package/dist/providers/toasts/useToasts.d.ts +16 -0
- package/dist/providers/toasts/useToasts.js +63 -0
- package/dist/providers/transactions/TransactionManager.d.ts +235 -0
- package/dist/providers/transactions/TransactionManager.js +509 -0
- package/dist/providers/transactions/TransactionProvider.svelte +11 -0
- package/dist/providers/transactions/TransactionProvider.svelte.d.ts +24 -0
- package/dist/providers/transactions/context.d.ts +19 -0
- package/dist/providers/transactions/context.js +28 -0
- package/dist/providers/transactions/useTransactions.d.ts +13 -0
- package/dist/providers/transactions/useTransactions.js +18 -0
- package/dist/providers/wallet/WalletProvider.svelte +7 -0
- package/dist/providers/wallet/WalletProvider.svelte.d.ts +21 -0
- package/dist/providers/wallet/context.d.ts +10 -0
- package/dist/providers/wallet/context.js +47 -0
- package/dist/providers/wallet/useAccount.d.ts +8 -0
- package/dist/providers/wallet/useAccount.js +148 -0
- package/dist/queries/keys.d.ts +1 -0
- package/dist/queries/keys.js +1 -0
- package/dist/queries/queryClient.d.ts +1 -1
- package/dist/queries/queryClient.js +11 -6
- package/dist/services/awaitTransactionIndexing.d.ts +107 -0
- package/dist/services/awaitTransactionIndexing.js +58 -0
- package/dist/services/getExplorerLink.d.ts +1 -1
- package/dist/services/getExplorerLink.js +2 -4
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +7 -2
- package/dist/services/historicalOrderCharts.d.ts +2 -2
- package/dist/services/historicalOrderCharts.js +267 -333
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +2 -1
- package/dist/services/loadRegistryUrl.d.ts +2 -0
- package/dist/services/loadRegistryUrl.js +22 -0
- package/dist/services/pairTradesChartData.d.ts +47 -0
- package/dist/services/pairTradesChartData.js +190 -0
- package/dist/services/registry.d.ts +5 -5
- package/dist/services/registry.js +8 -208
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +88 -6
- package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
- package/dist/storesGeneric/cachedWritableStore.js +93 -0
- package/dist/types/account.d.ts +3 -0
- package/dist/types/appStores.d.ts +9 -14
- package/dist/types/modal.d.ts +26 -14
- package/dist/types/{strategy.d.ts → order.d.ts} +3 -3
- package/dist/types/order.js +1 -0
- package/dist/types/toast.d.ts +11 -0
- package/dist/types/toast.js +1 -0
- package/dist/types/tokenBalance.d.ts +6 -0
- package/dist/types/tokenBalance.js +1 -0
- package/dist/types/transaction.d.ts +66 -21
- package/dist/types/transaction.js +31 -1
- package/dist/utils/configHelpers.d.ts +4 -0
- package/dist/utils/configHelpers.js +21 -0
- package/dist/utils/constructHashLink.d.ts +24 -0
- package/dist/utils/constructHashLink.js +115 -0
- package/dist/utils/getNetworkName.d.ts +1 -0
- package/dist/utils/getNetworkName.js +13 -0
- package/dist/utils/number.d.ts +0 -7
- package/dist/utils/number.js +0 -27
- package/dist/utils/tokens.d.ts +2 -0
- package/dist/utils/tokens.js +3 -0
- package/dist/utils/vaultBalanceChangeLabels.d.ts +4 -0
- package/dist/utils/vaultBalanceChangeLabels.js +18 -0
- package/package.json +39 -34
- package/dist/__fixtures__/orderDetail.d.ts +0 -99
- package/dist/__fixtures__/orderDetail.js +0 -204
- package/dist/__fixtures__/settings-12-11-24.json +0 -160
- package/dist/__mocks__/mockTransactionStore.d.ts +0 -22
- package/dist/__mocks__/mockTransactionStore.js +0 -56
- package/dist/__mocks__/settings.d.ts +0 -3
- package/dist/__mocks__/settings.js +0 -37
- package/dist/components/deployment/InvalidStrategiesSection.svelte +0 -19
- package/dist/components/deployment/InvalidStrategiesSection.svelte.d.ts +0 -19
- package/dist/components/deployment/StrategyPage.svelte.d.ts +0 -19
- package/dist/components/deployment/ValidStrategiesSection.svelte.d.ts +0 -19
- package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
- package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -28
- package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
- package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte +0 -38
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +0 -21
- package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
- package/dist/stores/transactionStore.d.ts +0 -98
- package/dist/stores/transactionStore.js +0 -303
- package/dist/utils/time.d.ts +0 -12
- package/dist/utils/time.js +0 -27
- package/dist/utils/vault.d.ts +0 -2
- package/dist/utils/vault.js +0 -29
- /package/dist/types/{strategy.js → account.js} +0 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a writable Svelte store that persists its value to localStorage.
|
|
3
|
+
*
|
|
4
|
+
* @template T - The type of the value stored in the store
|
|
5
|
+
* @param {string} key - The localStorage key used to store the value
|
|
6
|
+
* @param {T} defaultValue - The default value to use when no value is found in localStorage
|
|
7
|
+
* @param {function(T): string} serialize - Function to convert the store value to a string for storage
|
|
8
|
+
* @param {function(string): T} deserialize - Function to convert the stored string back to the original type
|
|
9
|
+
* @returns {import('svelte/store').Writable<T>} A writable store that automatically syncs with localStorage
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* // Create a store for a boolean value
|
|
13
|
+
* const darkMode = cachedWritableStore(
|
|
14
|
+
* 'darkMode',
|
|
15
|
+
* false,
|
|
16
|
+
* value => JSON.stringify(value),
|
|
17
|
+
* str => JSON.parse(str)
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* // Create a store for a complex object
|
|
21
|
+
* const userPreferences = cachedWritableStore(
|
|
22
|
+
* 'userPrefs',
|
|
23
|
+
* { theme: 'light', fontSize: 14 },
|
|
24
|
+
* value => JSON.stringify(value),
|
|
25
|
+
* str => JSON.parse(str)
|
|
26
|
+
* );
|
|
27
|
+
*/
|
|
28
|
+
export declare function cachedWritableStore<T>(key: string, defaultValue: T, serialize: (value: T) => string, deserialize: (serialized: string) => T): import("svelte/store").Writable<T>;
|
|
29
|
+
export declare const cachedWritableString: (key: string, defaultValue?: string) => import("svelte/store").Writable<string>;
|
|
30
|
+
export declare const cachedWritableInt: (key: string, defaultValue?: number) => import("svelte/store").Writable<number>;
|
|
31
|
+
/**
|
|
32
|
+
* Creates a writable store that can hold an optional value of type T and persists to localStorage.
|
|
33
|
+
*
|
|
34
|
+
* @template T - The type of the value stored
|
|
35
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
36
|
+
* @param {T | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
37
|
+
* @param {function} serialize - Function to convert the value to a string for storage
|
|
38
|
+
* @param {function} deserialize - Function to convert the stored string back to a value
|
|
39
|
+
* @returns A writable store that persists to localStorage and can hold undefined values
|
|
40
|
+
*/
|
|
41
|
+
export declare const cachedWritableOptionalStore: <T>(key: string, defaultValue: T | undefined, serialize: (value: T) => string, deserialize: (serialized: string) => T) => import("svelte/store").Writable<T | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Creates a writable store that can hold an optional number value and persists to localStorage.
|
|
44
|
+
*
|
|
45
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
46
|
+
* @param {number | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
47
|
+
* @returns A writable store that persists to localStorage and can hold an optional number
|
|
48
|
+
*/
|
|
49
|
+
export declare const cachedWritableIntOptional: (key: string, defaultValue?: undefined) => import("svelte/store").Writable<number | undefined>;
|
|
50
|
+
/**
|
|
51
|
+
* Creates a writable store that can hold an optional string value and persists to localStorage.
|
|
52
|
+
*
|
|
53
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
54
|
+
* @param {string | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
55
|
+
* @returns A writable store that persists to localStorage and can hold an optional string
|
|
56
|
+
*/
|
|
57
|
+
export declare const cachedWritableStringOptional: (key: string, defaultValue?: undefined) => import("svelte/store").Writable<string | undefined>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { writable } from 'svelte/store';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a writable Svelte store that persists its value to localStorage.
|
|
4
|
+
*
|
|
5
|
+
* @template T - The type of the value stored in the store
|
|
6
|
+
* @param {string} key - The localStorage key used to store the value
|
|
7
|
+
* @param {T} defaultValue - The default value to use when no value is found in localStorage
|
|
8
|
+
* @param {function(T): string} serialize - Function to convert the store value to a string for storage
|
|
9
|
+
* @param {function(string): T} deserialize - Function to convert the stored string back to the original type
|
|
10
|
+
* @returns {import('svelte/store').Writable<T>} A writable store that automatically syncs with localStorage
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* // Create a store for a boolean value
|
|
14
|
+
* const darkMode = cachedWritableStore(
|
|
15
|
+
* 'darkMode',
|
|
16
|
+
* false,
|
|
17
|
+
* value => JSON.stringify(value),
|
|
18
|
+
* str => JSON.parse(str)
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* // Create a store for a complex object
|
|
22
|
+
* const userPreferences = cachedWritableStore(
|
|
23
|
+
* 'userPrefs',
|
|
24
|
+
* { theme: 'light', fontSize: 14 },
|
|
25
|
+
* value => JSON.stringify(value),
|
|
26
|
+
* str => JSON.parse(str)
|
|
27
|
+
* );
|
|
28
|
+
*/
|
|
29
|
+
export function cachedWritableStore(key, defaultValue, serialize, deserialize) {
|
|
30
|
+
const getCache = () => {
|
|
31
|
+
try {
|
|
32
|
+
const cached = localStorage.getItem(key);
|
|
33
|
+
return cached !== null ? deserialize(cached) : defaultValue;
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return defaultValue;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const setCache = (value) => {
|
|
40
|
+
try {
|
|
41
|
+
if (value !== undefined) {
|
|
42
|
+
localStorage.setItem(key, serialize(value));
|
|
43
|
+
}
|
|
44
|
+
else {
|
|
45
|
+
localStorage.removeItem(key);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch {
|
|
49
|
+
// Silently ignore localStorage errors to allow the application to function
|
|
50
|
+
// without persistence in environments where localStorage is unavailable
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
const data = writable(getCache());
|
|
54
|
+
data.subscribe((value) => {
|
|
55
|
+
setCache(value);
|
|
56
|
+
});
|
|
57
|
+
return data;
|
|
58
|
+
}
|
|
59
|
+
export const cachedWritableString = (key, defaultValue = '') => cachedWritableStore(key, defaultValue, (v) => v, (v) => v);
|
|
60
|
+
export const cachedWritableInt = (key, defaultValue = 0) => cachedWritableStore(key, defaultValue, (v) => v.toString(), (v) => {
|
|
61
|
+
const parsed = Number.parseInt(v);
|
|
62
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
65
|
+
* Creates a writable store that can hold an optional value of type T and persists to localStorage.
|
|
66
|
+
*
|
|
67
|
+
* @template T - The type of the value stored
|
|
68
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
69
|
+
* @param {T | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
70
|
+
* @param {function} serialize - Function to convert the value to a string for storage
|
|
71
|
+
* @param {function} deserialize - Function to convert the stored string back to a value
|
|
72
|
+
* @returns A writable store that persists to localStorage and can hold undefined values
|
|
73
|
+
*/
|
|
74
|
+
export const cachedWritableOptionalStore = (key, defaultValue = undefined, serialize, deserialize) => cachedWritableStore(key, defaultValue, (v) => (v !== undefined ? serialize(v) : ''), (v) => (v !== '' ? deserialize(v) : undefined));
|
|
75
|
+
/**
|
|
76
|
+
* Creates a writable store that can hold an optional number value and persists to localStorage.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
79
|
+
* @param {number | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
80
|
+
* @returns A writable store that persists to localStorage and can hold an optional number
|
|
81
|
+
*/
|
|
82
|
+
export const cachedWritableIntOptional = (key, defaultValue = undefined) => cachedWritableOptionalStore(key, defaultValue, (v) => v.toString(), (v) => {
|
|
83
|
+
const parsed = Number.parseInt(v);
|
|
84
|
+
return isNaN(parsed) ? (defaultValue ?? 0) : parsed;
|
|
85
|
+
});
|
|
86
|
+
/**
|
|
87
|
+
* Creates a writable store that can hold an optional string value and persists to localStorage.
|
|
88
|
+
*
|
|
89
|
+
* @param {string} key - The localStorage key to use for persistence
|
|
90
|
+
* @param {string | undefined} defaultValue - The default value if nothing is found in localStorage
|
|
91
|
+
* @returns A writable store that persists to localStorage and can hold an optional string
|
|
92
|
+
*/
|
|
93
|
+
export const cachedWritableStringOptional = (key, defaultValue = undefined) => cachedWritableOptionalStore(key, defaultValue, (v) => v, (v) => v);
|
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'svelte/store';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AccountCfg, Address, Hex } from '@rainlanguage/orderbook';
|
|
3
3
|
export interface AppStoresInterface {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
orderHash: Writable<string>;
|
|
4
|
+
selectedChainIds: Writable<number[]>;
|
|
5
|
+
accounts: Readable<Record<string, AccountCfg>>;
|
|
6
|
+
activeAccountsItems: Writable<Record<string, Address>> | undefined;
|
|
7
|
+
showInactiveOrders: Writable<boolean>;
|
|
8
|
+
orderHash: Writable<Hex>;
|
|
10
9
|
hideZeroBalanceVaults: Writable<boolean>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
activeOrderbook: Readable<OrderbookConfigSource | undefined>;
|
|
14
|
-
subgraphUrl: Readable<string | undefined>;
|
|
15
|
-
activeAccounts: Readable<{
|
|
16
|
-
[k: string]: string;
|
|
17
|
-
}>;
|
|
10
|
+
hideInactiveOrdersVaults: Writable<boolean>;
|
|
11
|
+
activeTokens: Writable<Address[]>;
|
|
18
12
|
showMyItemsOnly: Writable<boolean>;
|
|
13
|
+
activeOrderbookAddresses: Writable<Address[]>;
|
|
19
14
|
}
|
package/dist/types/modal.d.ts
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
|
|
1
|
+
import type { Float, RaindexOrder, RaindexVault } from '@rainlanguage/orderbook';
|
|
2
|
+
import type { VaultActionArgs } from './transaction';
|
|
3
|
+
import type { Hex } from 'viem';
|
|
4
|
+
export type VaultActionModalProps = {
|
|
4
5
|
open: boolean;
|
|
5
|
-
args:
|
|
6
|
-
|
|
7
|
-
export type OrderRemoveModalProps = {
|
|
8
|
-
open: boolean;
|
|
9
|
-
args: OrderRemoveArgs;
|
|
10
|
-
};
|
|
11
|
-
export type DeployModalProps = {
|
|
12
|
-
open: boolean;
|
|
13
|
-
args: DeploymentArgs;
|
|
6
|
+
args: VaultActionArgs;
|
|
7
|
+
onSubmit: (amount: Float) => void;
|
|
14
8
|
};
|
|
15
9
|
export type DisclaimerModalProps = {
|
|
16
10
|
open: boolean;
|
|
17
11
|
onAccept: () => void;
|
|
18
12
|
};
|
|
19
|
-
export type
|
|
20
|
-
|
|
13
|
+
export type TransactionConfirmationProps = {
|
|
14
|
+
open: boolean;
|
|
15
|
+
modalTitle: string;
|
|
16
|
+
closeOnConfirm?: boolean;
|
|
17
|
+
args: {
|
|
18
|
+
chainId: number;
|
|
19
|
+
toAddress: Hex;
|
|
20
|
+
onConfirm: (hash: Hex) => void;
|
|
21
|
+
entity?: RaindexOrder | RaindexVault;
|
|
22
|
+
calldata: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export type QuoteDebugModalHandler = (order: RaindexOrder, inputIOIndex: number, outputIOIndex: number, pair: string, blockNumber?: bigint) => void;
|
|
26
|
+
export type DebugTradeModalHandler = (hash: string, rpcUrls: string[]) => void;
|
|
27
|
+
export type HandleTransactionConfirmationModal = (props: TransactionConfirmationProps, options?: {
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
hash?: string;
|
|
32
|
+
}>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { NameAndDescriptionCfg } from '@rainlanguage/orderbook
|
|
2
|
-
export type
|
|
1
|
+
import type { NameAndDescriptionCfg } from '@rainlanguage/orderbook';
|
|
2
|
+
export type ValidOrderDetail = {
|
|
3
3
|
details: NameAndDescriptionCfg;
|
|
4
4
|
name: string;
|
|
5
5
|
dotrain: string;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
7
|
+
export type InvalidOrderDetail = {
|
|
8
8
|
name: string;
|
|
9
9
|
error: string;
|
|
10
10
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,26 +1,71 @@
|
|
|
1
|
-
import type { ExtendedApprovalCalldata } from '../stores/transactionStore';
|
|
2
1
|
import type { Hex } from 'viem';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import type { RaindexVault } from '@rainlanguage/orderbook';
|
|
3
|
+
import type { ToastLink } from './toast';
|
|
4
|
+
import type { TransactionStoreState } from '../models/Transaction';
|
|
5
|
+
/**
|
|
6
|
+
* Context provided to the indexing function, allowing it to update
|
|
7
|
+
* transaction state and trigger callbacks without TransactionStore
|
|
8
|
+
* knowing the specifics of what's being indexed.
|
|
9
|
+
*/
|
|
10
|
+
export type IndexingContext = {
|
|
11
|
+
/** Update the transaction state (status, errorDetails, links) */
|
|
12
|
+
updateState: (partialState: Partial<TransactionStoreState>) => void;
|
|
13
|
+
/** Callback to invoke on successful indexing */
|
|
14
|
+
onSuccess: () => void;
|
|
15
|
+
/** Callback to invoke on indexing failure */
|
|
16
|
+
onError: () => void;
|
|
17
|
+
/** Current toast links (useful for prepending new links) */
|
|
18
|
+
links: ToastLink[];
|
|
11
19
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Generic indexing function type. TransactionStore calls this function
|
|
22
|
+
* after the transaction receipt is confirmed, without knowing what
|
|
23
|
+
* type of indexing is being performed (SDK-based, subgraph, etc.).
|
|
24
|
+
*/
|
|
25
|
+
export type AwaitIndexingFn = (ctx: IndexingContext) => Promise<void>;
|
|
26
|
+
export type VaultActionArgs = {
|
|
27
|
+
vault: RaindexVault;
|
|
28
|
+
onDeposit?: () => void;
|
|
29
|
+
account: Hex;
|
|
19
30
|
};
|
|
20
|
-
export
|
|
21
|
-
|
|
22
|
-
|
|
31
|
+
export declare enum TransactionName {
|
|
32
|
+
REMOVAL = "Order Removal",
|
|
33
|
+
WITHDRAWAL = "Vault Withdrawal",
|
|
34
|
+
WITHDRAWAL_MULTIPLE = "Vaults Withdrawal",
|
|
35
|
+
APPROVAL = "Token Approval",
|
|
36
|
+
DEPOSIT = "Vault Deposit",
|
|
37
|
+
TAKE_ORDER = "Take Order"
|
|
38
|
+
}
|
|
39
|
+
export declare enum TransactionStatusMessage {
|
|
40
|
+
IDLE = "Idle",
|
|
41
|
+
STARTING = "Starting transaction...",
|
|
42
|
+
CHECKING_ALLOWANCE = "Checking your allowance...",
|
|
43
|
+
PENDING_WALLET = "Waiting for wallet confirmation...",
|
|
44
|
+
PENDING_APPROVAL = "Approving token spend...",
|
|
45
|
+
PENDING_RECEIPT = "Waiting for transaction receipt...",
|
|
46
|
+
PENDING_DEPLOYMENT = "Deploying your order...",
|
|
47
|
+
PENDING_WITHDRAWAL = "Withdrawing tokens...",
|
|
48
|
+
PENDING_DEPOSIT = "Depositing tokens...",
|
|
49
|
+
PENDING_SUBGRAPH = "Awaiting transaction indexing...",
|
|
50
|
+
SUCCESS = "Transaction confirmed",
|
|
51
|
+
ERROR = "Something went wrong"
|
|
52
|
+
}
|
|
53
|
+
export declare enum TransactionStoreErrorMessage {
|
|
54
|
+
SWITCH_CHAIN_FAILED = "Failed to switch chain.",
|
|
55
|
+
SUBGRAPH_TIMEOUT_ERROR = "The subgraph took too long to respond. Your transaction may still be processing.",
|
|
56
|
+
SUBGRAPH_FAILED = "Failed to index transaction.",
|
|
57
|
+
RECEIPT_FAILED = "Failed to get transaction receipt."
|
|
58
|
+
}
|
|
59
|
+
export type InternalTransactionArgs = {
|
|
23
60
|
chainId: number;
|
|
24
|
-
|
|
25
|
-
|
|
61
|
+
txHash: Hex;
|
|
62
|
+
queryKey: string;
|
|
63
|
+
};
|
|
64
|
+
export type TransactionArgs = InternalTransactionArgs & {
|
|
65
|
+
name: string;
|
|
66
|
+
errorMessage: string;
|
|
67
|
+
successMessage: string;
|
|
68
|
+
queryKey: string;
|
|
69
|
+
toastLinks: ToastLink[];
|
|
70
|
+
awaitIndexingFn?: AwaitIndexingFn;
|
|
26
71
|
};
|
|
@@ -1 +1,31 @@
|
|
|
1
|
-
export
|
|
1
|
+
export var TransactionName;
|
|
2
|
+
(function (TransactionName) {
|
|
3
|
+
TransactionName["REMOVAL"] = "Order Removal";
|
|
4
|
+
TransactionName["WITHDRAWAL"] = "Vault Withdrawal";
|
|
5
|
+
TransactionName["WITHDRAWAL_MULTIPLE"] = "Vaults Withdrawal";
|
|
6
|
+
TransactionName["APPROVAL"] = "Token Approval";
|
|
7
|
+
TransactionName["DEPOSIT"] = "Vault Deposit";
|
|
8
|
+
TransactionName["TAKE_ORDER"] = "Take Order";
|
|
9
|
+
})(TransactionName || (TransactionName = {}));
|
|
10
|
+
export var TransactionStatusMessage;
|
|
11
|
+
(function (TransactionStatusMessage) {
|
|
12
|
+
TransactionStatusMessage["IDLE"] = "Idle";
|
|
13
|
+
TransactionStatusMessage["STARTING"] = "Starting transaction...";
|
|
14
|
+
TransactionStatusMessage["CHECKING_ALLOWANCE"] = "Checking your allowance...";
|
|
15
|
+
TransactionStatusMessage["PENDING_WALLET"] = "Waiting for wallet confirmation...";
|
|
16
|
+
TransactionStatusMessage["PENDING_APPROVAL"] = "Approving token spend...";
|
|
17
|
+
TransactionStatusMessage["PENDING_RECEIPT"] = "Waiting for transaction receipt...";
|
|
18
|
+
TransactionStatusMessage["PENDING_DEPLOYMENT"] = "Deploying your order...";
|
|
19
|
+
TransactionStatusMessage["PENDING_WITHDRAWAL"] = "Withdrawing tokens...";
|
|
20
|
+
TransactionStatusMessage["PENDING_DEPOSIT"] = "Depositing tokens...";
|
|
21
|
+
TransactionStatusMessage["PENDING_SUBGRAPH"] = "Awaiting transaction indexing...";
|
|
22
|
+
TransactionStatusMessage["SUCCESS"] = "Transaction confirmed";
|
|
23
|
+
TransactionStatusMessage["ERROR"] = "Something went wrong";
|
|
24
|
+
})(TransactionStatusMessage || (TransactionStatusMessage = {}));
|
|
25
|
+
export var TransactionStoreErrorMessage;
|
|
26
|
+
(function (TransactionStoreErrorMessage) {
|
|
27
|
+
TransactionStoreErrorMessage["SWITCH_CHAIN_FAILED"] = "Failed to switch chain.";
|
|
28
|
+
TransactionStoreErrorMessage["SUBGRAPH_TIMEOUT_ERROR"] = "The subgraph took too long to respond. Your transaction may still be processing.";
|
|
29
|
+
TransactionStoreErrorMessage["SUBGRAPH_FAILED"] = "Failed to index transaction.";
|
|
30
|
+
TransactionStoreErrorMessage["RECEIPT_FAILED"] = "Failed to get transaction receipt.";
|
|
31
|
+
})(TransactionStoreErrorMessage || (TransactionStoreErrorMessage = {}));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export function getAccountsAsOptions(accounts) {
|
|
2
|
+
if (!accounts)
|
|
3
|
+
return {};
|
|
4
|
+
return Object.fromEntries(Array.from(accounts.entries()).map(([key, value]) => [key, value.address]));
|
|
5
|
+
}
|
|
6
|
+
if (import.meta.vitest) {
|
|
7
|
+
const { expect, it, describe } = import.meta.vitest;
|
|
8
|
+
describe('getAccountsAsOptions', () => {
|
|
9
|
+
it('should return the correct accounts as options', () => {
|
|
10
|
+
const accounts = new Map([
|
|
11
|
+
['account1', { address: '0x1234567890abcdef', key: 'account1' }],
|
|
12
|
+
['account2', { address: '0xabcdef1234567890', key: 'account2' }]
|
|
13
|
+
]);
|
|
14
|
+
const result = getAccountsAsOptions(accounts);
|
|
15
|
+
expect(result).toEqual({
|
|
16
|
+
account1: '0x1234567890abcdef',
|
|
17
|
+
account2: '0xabcdef1234567890'
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { Address, RaindexOrder, RaindexOrderAsIO, RaindexVault } from '@rainlanguage/orderbook';
|
|
2
|
+
type OrderOrVault = RaindexOrder | RaindexOrderAsIO | RaindexVault;
|
|
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 chainId - The chain id
|
|
8
|
+
* @param orderbookAddress - The orderbook address
|
|
9
|
+
* @returns The constructed link path
|
|
10
|
+
*/
|
|
11
|
+
export declare function constructHashLink(orderOrVault: OrderOrVault, type: 'orders' | 'vaults', chainId: number, orderbookAddress: Address): string;
|
|
12
|
+
/**
|
|
13
|
+
* Determines if an order or vault is active
|
|
14
|
+
* @param orderOrVault - The order or vault object
|
|
15
|
+
* @returns True if the order is active, false otherwise
|
|
16
|
+
*/
|
|
17
|
+
export declare function isOrderOrVaultActive(orderOrVault: OrderOrVault): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Extracts the hash value from an order or vault
|
|
20
|
+
* @param orderOrVault - The order or vault object
|
|
21
|
+
* @returns The hash value
|
|
22
|
+
*/
|
|
23
|
+
export declare function extractHash(orderOrVault: OrderOrVault): string;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,115 @@
|
|
|
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 chainId - The chain id
|
|
11
|
+
* @param orderbookAddress - The orderbook address
|
|
12
|
+
* @returns The constructed link path
|
|
13
|
+
*/
|
|
14
|
+
export function constructHashLink(orderOrVault, type, chainId, orderbookAddress) {
|
|
15
|
+
if (!orderOrVault) {
|
|
16
|
+
return `/${type}`;
|
|
17
|
+
}
|
|
18
|
+
const slug = isOrder(orderOrVault) ? orderOrVault.orderHash : orderOrVault.id;
|
|
19
|
+
return `/${type}/${chainId}-${orderbookAddress}-${slug}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Determines if an order or vault is active
|
|
23
|
+
* @param orderOrVault - The order or vault object
|
|
24
|
+
* @returns True if the order is active, false otherwise
|
|
25
|
+
*/
|
|
26
|
+
export function isOrderOrVaultActive(orderOrVault) {
|
|
27
|
+
const _isOrder = isOrder(orderOrVault);
|
|
28
|
+
return _isOrder ? orderOrVault.active : false;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Extracts the hash value from an order or vault
|
|
32
|
+
* @param orderOrVault - The order or vault object
|
|
33
|
+
* @returns The hash value
|
|
34
|
+
*/
|
|
35
|
+
export function extractHash(orderOrVault) {
|
|
36
|
+
const _isOrder = isOrder(orderOrVault);
|
|
37
|
+
return _isOrder
|
|
38
|
+
? orderOrVault.orderHash
|
|
39
|
+
: orderOrVault?.id || '';
|
|
40
|
+
}
|
|
41
|
+
if (import.meta.vitest) {
|
|
42
|
+
const { expect, it, describe } = import.meta.vitest;
|
|
43
|
+
describe('constructHashLink', () => {
|
|
44
|
+
test.prop([
|
|
45
|
+
fc.record({
|
|
46
|
+
orderHash: fc.string(),
|
|
47
|
+
active: fc.boolean()
|
|
48
|
+
}),
|
|
49
|
+
fc.oneof(fc.constant('orders'), fc.constant('vaults')),
|
|
50
|
+
fc.integer(),
|
|
51
|
+
fc.string()
|
|
52
|
+
])('constructs correct link for orders', (order, type, chainId, orderbookAddress) => {
|
|
53
|
+
const result = constructHashLink(order, type, chainId, orderbookAddress);
|
|
54
|
+
expect(result).toBe(`/${type}/${chainId}-${orderbookAddress}-${order.orderHash}`);
|
|
55
|
+
});
|
|
56
|
+
test.prop([
|
|
57
|
+
fc.record({
|
|
58
|
+
id: fc.string(),
|
|
59
|
+
owner: fc.string()
|
|
60
|
+
}),
|
|
61
|
+
fc.oneof(fc.constant('orders'), fc.constant('vaults')),
|
|
62
|
+
fc.integer(),
|
|
63
|
+
fc.string()
|
|
64
|
+
])('constructs correct link for vaults', (vault, type, chainId, orderbookAddress) => {
|
|
65
|
+
const result = constructHashLink(vault, type, chainId, orderbookAddress);
|
|
66
|
+
expect(result).toBe(`/${type}/${chainId}-${orderbookAddress}-${vault.id}`);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('isOrderOrVaultActive', () => {
|
|
70
|
+
test.prop([
|
|
71
|
+
fc.record({
|
|
72
|
+
orderHash: fc.string(),
|
|
73
|
+
active: fc.boolean()
|
|
74
|
+
})
|
|
75
|
+
])('returns correct active status for orders', (order) => {
|
|
76
|
+
const result = isOrderOrVaultActive(order);
|
|
77
|
+
expect(result).toBe(order.active);
|
|
78
|
+
});
|
|
79
|
+
test.prop([
|
|
80
|
+
fc.record({
|
|
81
|
+
id: fc.string(),
|
|
82
|
+
owner: fc.string()
|
|
83
|
+
})
|
|
84
|
+
])('returns false for vaults', (vault) => {
|
|
85
|
+
const result = isOrderOrVaultActive(vault);
|
|
86
|
+
expect(result).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
describe('extractHash', () => {
|
|
90
|
+
test.prop([
|
|
91
|
+
fc.record({
|
|
92
|
+
orderHash: fc.string(),
|
|
93
|
+
active: fc.boolean()
|
|
94
|
+
})
|
|
95
|
+
])('extracts hash from orders', (order) => {
|
|
96
|
+
const result = extractHash(order);
|
|
97
|
+
expect(result).toBe(order.orderHash);
|
|
98
|
+
});
|
|
99
|
+
test.prop([
|
|
100
|
+
fc.record({
|
|
101
|
+
id: fc.string(),
|
|
102
|
+
owner: fc.string()
|
|
103
|
+
})
|
|
104
|
+
])('extracts hash from vaults', (vault) => {
|
|
105
|
+
const result = extractHash(vault);
|
|
106
|
+
expect(result).toBe(vault.id);
|
|
107
|
+
});
|
|
108
|
+
it('handles undefined vault id', () => {
|
|
109
|
+
// Create a partial vault object with undefined id
|
|
110
|
+
const vault = { id: undefined };
|
|
111
|
+
const result = extractHash(vault);
|
|
112
|
+
expect(result).toBe('');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getNetworkName(chainId: number): string | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as chains from 'viem/chains';
|
|
2
|
+
export function getNetworkName(chainId) {
|
|
3
|
+
const chain = Object.values(chains).find((chain) => chain.id === chainId);
|
|
4
|
+
return chain?.name;
|
|
5
|
+
}
|
|
6
|
+
if (import.meta.vitest) {
|
|
7
|
+
describe('getNetworkName', () => {
|
|
8
|
+
it('should return the network name for a given chain id', () => {
|
|
9
|
+
expect(getNetworkName(1)).toBe('Ethereum');
|
|
10
|
+
expect(getNetworkName(137)).toBe('Polygon');
|
|
11
|
+
});
|
|
12
|
+
});
|
|
13
|
+
}
|
package/dist/utils/number.d.ts
CHANGED
|
@@ -5,10 +5,3 @@
|
|
|
5
5
|
* @param decimalPoint - (optional) The number of digits to keep after "." in final result, defaults to valueDecimals
|
|
6
6
|
*/
|
|
7
7
|
export declare function bigintStringToPercentage(value: string, valueDecimals: number, finalDecimalsDigits?: number): string;
|
|
8
|
-
/**
|
|
9
|
-
* Converts a bigint value to a floating point number with the specified number of decimals
|
|
10
|
-
* @param value - The bigint value to convert
|
|
11
|
-
* @param decimals - The number of decimal places to use in the conversion
|
|
12
|
-
* @returns The converted floating point number
|
|
13
|
-
*/
|
|
14
|
-
export declare function bigintToFloat(value: bigint, decimals: number): number;
|
package/dist/utils/number.js
CHANGED
|
@@ -14,30 +14,3 @@ export function bigintStringToPercentage(value, valueDecimals, finalDecimalsDigi
|
|
|
14
14
|
}
|
|
15
15
|
return valueString;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Converts a bigint value to a floating point number with the specified number of decimals
|
|
19
|
-
* @param value - The bigint value to convert
|
|
20
|
-
* @param decimals - The number of decimal places to use in the conversion
|
|
21
|
-
* @returns The converted floating point number
|
|
22
|
-
*/
|
|
23
|
-
export function bigintToFloat(value, decimals) {
|
|
24
|
-
return parseFloat(formatUnits(value, decimals));
|
|
25
|
-
}
|
|
26
|
-
if (import.meta.vitest) {
|
|
27
|
-
const { it, expect } = import.meta.vitest;
|
|
28
|
-
it('should get percentage string from bigint string', () => {
|
|
29
|
-
const value = '123456000000000000';
|
|
30
|
-
const decimals = 18;
|
|
31
|
-
const finalDecimalsDigits = 4;
|
|
32
|
-
const result = bigintStringToPercentage(value, decimals, finalDecimalsDigits);
|
|
33
|
-
const expected = '12.3456';
|
|
34
|
-
expect(result).toEqual(expected);
|
|
35
|
-
});
|
|
36
|
-
it('should convert bigint to float', () => {
|
|
37
|
-
const value = 123456000000000000n;
|
|
38
|
-
const decimals = 18;
|
|
39
|
-
const result = bigintToFloat(value, decimals);
|
|
40
|
-
const expected = 0.123456;
|
|
41
|
-
expect(result).toEqual(expected);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { RaindexVaultBalanceChangeType, VaultBalanceChangeFilter } from '@rainlanguage/orderbook';
|
|
2
|
+
export declare const VAULT_BALANCE_CHANGE_LABELS: Record<RaindexVaultBalanceChangeType, string>;
|
|
3
|
+
export declare const VAULT_BALANCE_CHANGE_FILTER_LABELS: Record<VaultBalanceChangeFilter, string>;
|
|
4
|
+
export declare function labelForVaultBalanceChangeType(type: RaindexVaultBalanceChangeType): string;
|