@rainlanguage/ui-components 0.0.1-alpha.24 → 0.0.1-alpha.241
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 +14 -6
- package/dist/__fixtures__/settings.yaml +123 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte +4 -0
- package/dist/__mocks__/CodeMirrorRainlang.svelte.d.ts +18 -0
- package/dist/__mocks__/MockCodeMirrorEditor.svelte +17 -0
- package/dist/__mocks__/MockCodeMirrorEditor.svelte.d.ts +21 -0
- package/dist/__mocks__/MockComponent.js +1 -1
- package/dist/__mocks__/MockComponent.svelte +10 -2
- package/dist/__mocks__/MockComponent.svelte.d.ts +4 -1
- package/dist/__mocks__/mockWeb3Config.d.ts +1 -1
- package/dist/__mocks__/mockWeb3Config.js +10 -7
- package/dist/__mocks__/queries.js +9 -9
- package/dist/__mocks__/stores.d.ts +55 -45
- package/dist/__mocks__/stores.js +85 -68
- package/dist/app.css +3 -3
- package/dist/components/ButtonDarkMode.svelte +7 -1
- package/dist/components/ButtonLoading.svelte +1 -1
- package/dist/components/ButtonScrub.svelte +22 -0
- package/dist/components/ButtonScrub.svelte.d.ts +25 -0
- package/dist/components/ButtonVaultLink.svelte +12 -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/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 +20 -12
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +3 -2
- package/dist/components/EditableSpan.svelte +3 -14
- package/dist/components/EditableSpan.svelte.d.ts +0 -1
- package/dist/components/Hash.svelte +6 -5
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewRaindexFilters.svelte +64 -0
- package/dist/components/ListViewRaindexFilters.svelte.d.ts +32 -0
- package/dist/components/LocalDbStatusBadge.svelte +27 -0
- package/dist/components/LocalDbStatusBadge.svelte.d.ts +19 -0
- package/dist/components/LocalDbStatusCard.svelte +43 -0
- package/dist/components/LocalDbStatusCard.svelte.d.ts +20 -0
- package/dist/components/LocalDbStatusModal.svelte +105 -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/Sensitive.svelte +16 -0
- package/dist/components/Sensitive.svelte.d.ts +28 -0
- package/dist/components/TanstackAppTable.svelte +270 -60
- package/dist/components/TanstackAppTable.svelte.d.ts +15 -9
- 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 +319 -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 +3 -2
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +196 -221
- 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 +10 -11
- package/dist/components/deployment/DepositInput.svelte.d.ts +2 -3
- package/dist/components/deployment/DisclaimerModal.svelte +6 -7
- package/dist/components/deployment/FieldDefinitionInput.svelte +10 -14
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +2 -3
- 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 +127 -50
- package/dist/components/deployment/SelectToken.svelte.d.ts +5 -4
- package/dist/components/deployment/TokenBalance.svelte +19 -0
- package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
- package/dist/components/deployment/TokenIOInput.svelte +27 -17
- 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 +220 -82
- package/dist/components/detail/OrderDetail.svelte.d.ts +21 -15
- package/dist/components/detail/TanstackOrderQuote.svelte +114 -46
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +14 -16
- package/dist/components/detail/VaultDetail.svelte +82 -79
- 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/DropdownRaindexesFilter.svelte +172 -0
- package/dist/components/dropdown/DropdownRaindexesFilter.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 +4 -2
- package/dist/components/icon/Refresh.svelte.d.ts +2 -0
- package/dist/components/input/InputOrderHash.svelte +1 -1
- package/dist/components/input/InputOrderHash.svelte.d.ts +3 -3
- package/dist/components/input/InputOwnerFilter.svelte +48 -0
- package/dist/components/input/InputOwnerFilter.svelte.d.ts +19 -0
- package/dist/components/input/InputRegistryUrl.svelte +36 -14
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +30 -20
- 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 +132 -124
- 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 +206 -115
- package/dist/components/tables/OrdersListTable.svelte.d.ts +18 -23
- package/dist/components/tables/VaultBalanceChangesTable.svelte +83 -43
- package/dist/components/tables/VaultBalanceChangesTable.svelte.d.ts +13 -11
- package/dist/components/tables/VaultsListTable.svelte +275 -150
- package/dist/components/tables/VaultsListTable.svelte.d.ts +24 -33
- package/dist/components/transactions/FixedBottomTransaction.svelte +64 -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 +11 -5
- package/dist/errors/DeploymentStepsError.js +13 -7
- package/dist/errors/index.d.ts +1 -1
- package/dist/errors/index.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/hooks/useRaindexOrderBuilder.d.ts +3 -0
- package/dist/hooks/useRaindexOrderBuilder.js +11 -0
- package/dist/index.d.ts +122 -91
- package/dist/index.js +118 -87
- package/dist/models/Transaction.d.ts +75 -0
- package/dist/models/Transaction.js +100 -0
- 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/RaindexOrderBuilderProvider.svelte +8 -0
- package/dist/providers/RaindexOrderBuilderProvider.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 +43 -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 +134 -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 +234 -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 +10 -9
- package/dist/queries/queryClient.d.ts +2 -2
- package/dist/queries/queryClient.js +16 -11
- package/dist/services/awaitTransactionIndexing.d.ts +107 -0
- package/dist/services/awaitTransactionIndexing.js +60 -0
- package/dist/services/getExplorerLink.d.ts +1 -1
- package/dist/services/getExplorerLink.js +3 -5
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +6 -5
- package/dist/services/historicalOrderCharts.d.ts +3 -3
- package/dist/services/historicalOrderCharts.js +364 -371
- package/dist/services/index.d.ts +5 -2
- package/dist/services/index.js +3 -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 +194 -0
- package/dist/services/registry.d.ts +5 -5
- package/dist/services/registry.js +17 -217
- package/dist/services/time.d.ts +12 -0
- package/dist/services/time.js +88 -6
- package/dist/services/validateAmount.d.ts +30 -0
- package/dist/services/validateAmount.js +53 -0
- package/dist/storesGeneric/cachedWritableStore.d.ts +57 -0
- package/dist/storesGeneric/cachedWritableStore.js +93 -0
- package/dist/storesGeneric/scrub.d.ts +14 -0
- package/dist/storesGeneric/scrub.js +22 -0
- package/dist/test/matchers.d.ts +2 -2
- package/dist/test/matchers.js +2 -2
- package/dist/types/account.d.ts +3 -0
- package/dist/types/appStores.d.ts +9 -16
- package/dist/types/modal.d.ts +26 -14
- package/dist/types/order.d.ts +10 -0
- 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 +67 -22
- package/dist/types/transaction.js +31 -1
- package/dist/utils/breadcrumbs.js +2 -2
- package/dist/utils/codeMirrorThemes.js +80 -74
- 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 +117 -0
- package/dist/utils/getNetworkName.d.ts +1 -0
- package/dist/utils/getNetworkName.js +13 -0
- package/dist/utils/hex.js +1 -1
- package/dist/utils/lightweightChartsThemes.d.ts +1 -1
- package/dist/utils/lightweightChartsThemes.js +11 -11
- package/dist/utils/localDbStatus.d.ts +26 -0
- package/dist/utils/localDbStatus.js +22 -0
- package/dist/utils/number.d.ts +0 -7
- package/dist/utils/number.js +5 -30
- package/dist/utils/stripTrailingWhitespace.d.ts +16 -0
- package/dist/utils/stripTrailingWhitespace.js +22 -0
- 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 +89 -84
- 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/CheckboxMyItemsOnly.svelte +0 -23
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -21
- package/dist/components/ListViewOrderbookFilters.svelte +0 -58
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +0 -28
- 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/DropdownOrderListAccounts.svelte +0 -15
- package/dist/components/dropdown/DropdownOrderListAccounts.svelte.d.ts +0 -20
- package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
- package/dist/hooks/useGui.d.ts +0 -3
- package/dist/hooks/useGui.js +0 -11
- package/dist/providers/GuiProvider.svelte +0 -8
- package/dist/providers/GuiProvider.svelte.d.ts +0 -21
- package/dist/stores/transactionStore.d.ts +0 -98
- package/dist/stores/transactionStore.js +0 -303
- package/dist/types/strategy.d.ts +0 -10
- 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
package/dist/services/time.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import bigIntSupport from "dayjs/plugin/bigIntSupport";
|
|
3
|
+
import localizedFormat from "dayjs/plugin/localizedFormat";
|
|
4
|
+
import utc from "dayjs/plugin/utc";
|
|
5
|
+
dayjs.extend(bigIntSupport);
|
|
6
|
+
dayjs.extend(localizedFormat);
|
|
7
|
+
dayjs.extend(utc);
|
|
1
8
|
export const TIME_DELTA_24_HOURS = 60 * 60 * 24;
|
|
2
9
|
export const TIME_DELTA_48_HOURS = TIME_DELTA_24_HOURS * 2;
|
|
3
10
|
export const TIME_DELTA_7_DAYS = TIME_DELTA_24_HOURS * 7;
|
|
@@ -6,12 +13,87 @@ export const TIME_DELTA_1_YEAR = TIME_DELTA_24_HOURS * 365;
|
|
|
6
13
|
export function dateTimestamp(date) {
|
|
7
14
|
return Math.floor(date.getTime() / 1000);
|
|
8
15
|
}
|
|
16
|
+
export function formatTimestampSecondsAsLocal(timestampSeconds) {
|
|
17
|
+
return dayjs(timestampSeconds * BigInt("1000"))
|
|
18
|
+
.utc()
|
|
19
|
+
.format("L LT");
|
|
20
|
+
}
|
|
21
|
+
export function timestampSecondsToUTCTimestamp(timestampSeconds) {
|
|
22
|
+
return dayjs(timestampSeconds * BigInt("1000")).unix();
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
26
|
+
* @param promise - The original promise
|
|
27
|
+
* @param time - The time in ms
|
|
28
|
+
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
29
|
+
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
30
|
+
* if the time runs out before the main promise settlement
|
|
31
|
+
*/
|
|
32
|
+
export async function promiseTimeout(promise, time, exception) {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
34
|
+
let timeout;
|
|
35
|
+
return Promise.race([
|
|
36
|
+
promise,
|
|
37
|
+
new Promise((_resolve, reject) => (timeout = setTimeout(reject, time, exception))),
|
|
38
|
+
]).finally(() => clearTimeout(timeout));
|
|
39
|
+
}
|
|
9
40
|
if (import.meta.vitest) {
|
|
10
|
-
const { it, expect } = import.meta.vitest;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
41
|
+
const { describe, it, expect, vi } = import.meta.vitest;
|
|
42
|
+
describe("Date and timestamp utilities", () => {
|
|
43
|
+
describe("formatTimestampSecondsAsLocal", () => {
|
|
44
|
+
it("converts timestamp to local format", () => {
|
|
45
|
+
const result = formatTimestampSecondsAsLocal(BigInt("1672531200")); // Jan 1, 2023 12:00 AM
|
|
46
|
+
expect(result).toBe("01/01/2023 12:00 AM");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("timestampSecondsToUTCTimestamp", () => {
|
|
50
|
+
it("converts bigint timestamp to UTCTimestamp", () => {
|
|
51
|
+
const result = timestampSecondsToUTCTimestamp(BigInt("1672531200"));
|
|
52
|
+
expect(result).toBe(1672531200);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe("promiseTimeout", () => {
|
|
57
|
+
it("resolves when promise resolves before timeout", async () => {
|
|
58
|
+
const testValue = "test";
|
|
59
|
+
const promise = Promise.resolve(testValue);
|
|
60
|
+
const result = await promiseTimeout(promise, 100, new Error("Timeout"));
|
|
61
|
+
expect(result).toBe(testValue);
|
|
62
|
+
});
|
|
63
|
+
it("rejects when promise times out", async () => {
|
|
64
|
+
const promise = new Promise((resolve) => setTimeout(resolve, 200));
|
|
65
|
+
const exception = new Error("Timeout");
|
|
66
|
+
await expect(promiseTimeout(promise, 100, exception)).rejects.toThrow(exception);
|
|
67
|
+
});
|
|
68
|
+
it("rejects when original promise rejects", async () => {
|
|
69
|
+
const error = new Error("Original rejection");
|
|
70
|
+
const promise = Promise.reject(error);
|
|
71
|
+
await expect(promiseTimeout(promise, 100, new Error("Timeout"))).rejects.toThrow(error);
|
|
72
|
+
});
|
|
73
|
+
it("clears timeout after promise resolution", async () => {
|
|
74
|
+
vi.spyOn(global, "clearTimeout");
|
|
75
|
+
const promise = Promise.resolve("test");
|
|
76
|
+
await promiseTimeout(promise, 100, new Error("Timeout"));
|
|
77
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
it("clears timeout after promise rejection", async () => {
|
|
80
|
+
vi.spyOn(global, "clearTimeout");
|
|
81
|
+
const promise = Promise.reject(new Error("Original rejection"));
|
|
82
|
+
try {
|
|
83
|
+
await promiseTimeout(promise, 100, new Error("Timeout"));
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore the error
|
|
87
|
+
}
|
|
88
|
+
expect(clearTimeout).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe("dateTimestamp", () => {
|
|
92
|
+
it("should get date timestamp in seconds", () => {
|
|
93
|
+
const date = new Date(2022, 1, 16, 17, 32, 11, 168);
|
|
94
|
+
const result = dateTimestamp(date);
|
|
95
|
+
const expected = Math.floor(date.getTime() / 1000);
|
|
96
|
+
expect(result).toEqual(expected);
|
|
97
|
+
});
|
|
16
98
|
});
|
|
17
99
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The maximum number of fractional (post-decimal-point) digits that the
|
|
3
|
+
* underlying `Float` decimal parser accepts without precision loss. A value
|
|
4
|
+
* with more than this many decimal places is rejected client-side with a
|
|
5
|
+
* friendly message.
|
|
6
|
+
*/
|
|
7
|
+
export declare const MAX_DECIMALS = 67;
|
|
8
|
+
export interface AmountDecimalsValidation {
|
|
9
|
+
isValid: boolean;
|
|
10
|
+
errorMessage: string | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Counts the number of fractional digits in a plain decimal string.
|
|
14
|
+
*
|
|
15
|
+
* Returns `null` when the input is not a plain decimal number (empty, or
|
|
16
|
+
* containing anything other than an optional leading sign and digits around a
|
|
17
|
+
* single decimal point), so callers defer to the underlying parser for those
|
|
18
|
+
* cases.
|
|
19
|
+
*
|
|
20
|
+
* @param value The raw string entered by the user.
|
|
21
|
+
*/
|
|
22
|
+
export declare function countDecimalPlaces(value: string): number | null;
|
|
23
|
+
/**
|
|
24
|
+
* Validates that a raw amount string does not exceed the maximum supported
|
|
25
|
+
* number of decimal places.
|
|
26
|
+
*
|
|
27
|
+
* @param value The raw string entered by the user.
|
|
28
|
+
* @returns Validation result with a friendly error message when invalid.
|
|
29
|
+
*/
|
|
30
|
+
export declare function validateAmount(value: string): AmountDecimalsValidation;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The maximum number of fractional (post-decimal-point) digits that the
|
|
3
|
+
* underlying `Float` decimal parser accepts without precision loss. A value
|
|
4
|
+
* with more than this many decimal places is rejected client-side with a
|
|
5
|
+
* friendly message.
|
|
6
|
+
*/
|
|
7
|
+
export const MAX_DECIMALS = 67;
|
|
8
|
+
/**
|
|
9
|
+
* Counts the number of fractional digits in a plain decimal string.
|
|
10
|
+
*
|
|
11
|
+
* Returns `null` when the input is not a plain decimal number (empty, or
|
|
12
|
+
* containing anything other than an optional leading sign and digits around a
|
|
13
|
+
* single decimal point), so callers defer to the underlying parser for those
|
|
14
|
+
* cases.
|
|
15
|
+
*
|
|
16
|
+
* @param value The raw string entered by the user.
|
|
17
|
+
*/
|
|
18
|
+
export function countDecimalPlaces(value) {
|
|
19
|
+
const trimmed = value.trim();
|
|
20
|
+
if (trimmed === "")
|
|
21
|
+
return null;
|
|
22
|
+
// Optional sign, integer part, optional fractional part. Plain decimal only
|
|
23
|
+
// (no scientific notation, no thousands separators) to match the inputs the
|
|
24
|
+
// `Float` decimal parser accepts.
|
|
25
|
+
const match = /^[+-]?(\d*)(?:\.(\d*))?$/.exec(trimmed);
|
|
26
|
+
if (!match)
|
|
27
|
+
return null;
|
|
28
|
+
const [, integerPart, fractionalPart] = match;
|
|
29
|
+
// Reject strings with no digits at all (e.g. ".", "+", "-").
|
|
30
|
+
if ((integerPart ?? "") === "" && (fractionalPart ?? "") === "")
|
|
31
|
+
return null;
|
|
32
|
+
return (fractionalPart ?? "").length;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Validates that a raw amount string does not exceed the maximum supported
|
|
36
|
+
* number of decimal places.
|
|
37
|
+
*
|
|
38
|
+
* @param value The raw string entered by the user.
|
|
39
|
+
* @returns Validation result with a friendly error message when invalid.
|
|
40
|
+
*/
|
|
41
|
+
export function validateAmount(value) {
|
|
42
|
+
const decimals = countDecimalPlaces(value);
|
|
43
|
+
if (decimals !== null && decimals > MAX_DECIMALS) {
|
|
44
|
+
return {
|
|
45
|
+
isValid: false,
|
|
46
|
+
errorMessage: `Too many decimal places. A maximum of ${MAX_DECIMALS} decimal places is allowed.`,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return {
|
|
50
|
+
isValid: true,
|
|
51
|
+
errorMessage: null,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -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?: number | 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?: string | 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);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Global "scrub" toggle used for safe screenshotting of the GUI.
|
|
3
|
+
*
|
|
4
|
+
* When `true`, every {@link Sensitive} region (which wraps all rendered
|
|
5
|
+
* addresses and transaction hashes via the `Hash` component) is masked with an
|
|
6
|
+
* opaque grey box so that sharing a screenshot does not leak addresses/hashes.
|
|
7
|
+
*
|
|
8
|
+
* This is purely presentational: it never changes any on-chain data or the
|
|
9
|
+
* underlying values held in memory, only how they are displayed.
|
|
10
|
+
*
|
|
11
|
+
* The value is persisted to localStorage under the `scrub` key so the masked
|
|
12
|
+
* state survives reloads while a user is preparing screenshots.
|
|
13
|
+
*/
|
|
14
|
+
export declare const scrub: import("svelte/store").Writable<boolean>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { cachedWritableStore } from "./cachedWritableStore";
|
|
2
|
+
/**
|
|
3
|
+
* Global "scrub" toggle used for safe screenshotting of the GUI.
|
|
4
|
+
*
|
|
5
|
+
* When `true`, every {@link Sensitive} region (which wraps all rendered
|
|
6
|
+
* addresses and transaction hashes via the `Hash` component) is masked with an
|
|
7
|
+
* opaque grey box so that sharing a screenshot does not leak addresses/hashes.
|
|
8
|
+
*
|
|
9
|
+
* This is purely presentational: it never changes any on-chain data or the
|
|
10
|
+
* underlying values held in memory, only how they are displayed.
|
|
11
|
+
*
|
|
12
|
+
* The value is persisted to localStorage under the `scrub` key so the masked
|
|
13
|
+
* state survives reloads while a user is preparing screenshots.
|
|
14
|
+
*/
|
|
15
|
+
export const scrub = cachedWritableStore("scrub", false, (value) => JSON.stringify(value), (serialized) => {
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(serialized) === true;
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
});
|
package/dist/test/matchers.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as matchers from
|
|
1
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
2
2
|
export declare const expect: import("vitest").ExpectStatic;
|
|
3
|
-
declare module
|
|
3
|
+
declare module "vitest" {
|
|
4
4
|
interface JestAssertion<T = any> extends matchers.TestingLibraryMatchers<ReturnType<typeof expect.stringContaining>, T> {
|
|
5
5
|
}
|
|
6
6
|
}
|
package/dist/test/matchers.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expect as vitestExpect } from
|
|
2
|
-
import * as matchers from
|
|
1
|
+
import { expect as vitestExpect } from "vitest";
|
|
2
|
+
import * as matchers from "@testing-library/jest-dom/matchers";
|
|
3
3
|
vitestExpect.extend(matchers);
|
|
4
4
|
export const expect = vitestExpect;
|
|
@@ -1,19 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Writable } from "svelte/store";
|
|
2
|
+
import type { Address, Hex } from "@rainlanguage/raindex";
|
|
3
3
|
export interface AppStoresInterface {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
activeAccountsItems: Writable<Record<string, string>>;
|
|
8
|
-
activeOrderStatus: Writable<boolean | undefined>;
|
|
9
|
-
orderHash: Writable<string>;
|
|
4
|
+
selectedChainIds: Writable<number[]>;
|
|
5
|
+
showInactiveOrders: Writable<boolean>;
|
|
6
|
+
orderHash: Writable<Hex>;
|
|
10
7
|
hideZeroBalanceVaults: Writable<boolean>;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
activeAccounts: Readable<{
|
|
16
|
-
[k: string]: string;
|
|
17
|
-
}>;
|
|
18
|
-
showMyItemsOnly: Writable<boolean>;
|
|
8
|
+
hideInactiveOrdersVaults: Writable<boolean>;
|
|
9
|
+
activeTokens: Writable<Address[]>;
|
|
10
|
+
activeRaindexAddresses: Writable<Address[]>;
|
|
11
|
+
ownerFilter: Writable<Address>;
|
|
19
12
|
}
|
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/raindex";
|
|
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
|
+
}>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,26 +1,71 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import type { Hex } from "viem";
|
|
2
|
+
import type { RaindexVault } from "@rainlanguage/raindex";
|
|
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 = {}));
|