@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,47 @@
|
|
|
1
|
+
import { getContext, setContext } from 'svelte';
|
|
2
|
+
import { readable } from 'svelte/store';
|
|
3
|
+
export const ACCOUNT_KEY = 'account_key';
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves the account store directly from Svelte's context
|
|
6
|
+
*/
|
|
7
|
+
export const getAccountContext = () => {
|
|
8
|
+
const account = getContext(ACCOUNT_KEY);
|
|
9
|
+
if (!account) {
|
|
10
|
+
throw new Error('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
|
|
11
|
+
}
|
|
12
|
+
return account;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Sets the account store in Svelte's context
|
|
16
|
+
*/
|
|
17
|
+
export const setAccountContext = (account) => {
|
|
18
|
+
setContext(ACCOUNT_KEY, account);
|
|
19
|
+
};
|
|
20
|
+
if (import.meta.vitest) {
|
|
21
|
+
const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
|
|
22
|
+
vi.mock('svelte', async (importOriginal) => ({
|
|
23
|
+
...(await importOriginal()),
|
|
24
|
+
getContext: vi.fn()
|
|
25
|
+
}));
|
|
26
|
+
describe('getAccountContext', () => {
|
|
27
|
+
const mockGetContext = vi.mocked(getContext);
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
mockGetContext.mockReset();
|
|
30
|
+
});
|
|
31
|
+
it('should return the account from context when it exists', () => {
|
|
32
|
+
const mockAccount = readable('0x456');
|
|
33
|
+
mockGetContext.mockImplementation((key) => {
|
|
34
|
+
if (key === ACCOUNT_KEY)
|
|
35
|
+
return mockAccount;
|
|
36
|
+
return undefined;
|
|
37
|
+
});
|
|
38
|
+
const result = getAccountContext();
|
|
39
|
+
expect(mockGetContext).toHaveBeenCalledWith(ACCOUNT_KEY);
|
|
40
|
+
expect(result).toEqual(mockAccount);
|
|
41
|
+
});
|
|
42
|
+
it('should throw an error when account is not in context', () => {
|
|
43
|
+
mockGetContext.mockReturnValue(undefined);
|
|
44
|
+
expect(() => getAccountContext()).toThrow('No account was found in Svelte context. Did you forget to wrap your component with WalletProvider?');
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook to access wallet account information from context
|
|
3
|
+
* Must be used within a component that is a child of WalletProvider
|
|
4
|
+
*/
|
|
5
|
+
export declare function useAccount(): {
|
|
6
|
+
account: import("../../types/account").Account;
|
|
7
|
+
matchesAccount: (otherAddress: string) => boolean;
|
|
8
|
+
};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { get } from 'svelte/store';
|
|
2
|
+
import { isAddress, isAddressEqual } from 'viem';
|
|
3
|
+
import { getAccountContext } from './context';
|
|
4
|
+
import { readable } from 'svelte/store';
|
|
5
|
+
/**
|
|
6
|
+
* Hook to access wallet account information from context
|
|
7
|
+
* Must be used within a component that is a child of WalletProvider
|
|
8
|
+
*/
|
|
9
|
+
export function useAccount() {
|
|
10
|
+
/**
|
|
11
|
+
* The account store containing the current wallet address (as a Hex string) or null if not connected.
|
|
12
|
+
* This is a readable Svelte store that can be subscribed to for reactive updates.
|
|
13
|
+
* @type {import('svelte/store').Readable<Hex | null>}
|
|
14
|
+
*/
|
|
15
|
+
const account = getAccountContext();
|
|
16
|
+
/**
|
|
17
|
+
* Checks if the provided address matches the currently connected account.
|
|
18
|
+
* Returns false if no account is connected or if the provided address is invalid.
|
|
19
|
+
*/
|
|
20
|
+
const matchesAccount = (otherAddress) => {
|
|
21
|
+
if (!otherAddress)
|
|
22
|
+
return false;
|
|
23
|
+
const currentAccount = get(account);
|
|
24
|
+
if (!currentAccount) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
if (isAddress(currentAccount) &&
|
|
28
|
+
isAddress(otherAddress) &&
|
|
29
|
+
isAddressEqual(currentAccount, otherAddress)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
return {
|
|
35
|
+
account,
|
|
36
|
+
matchesAccount
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
if (import.meta.vitest) {
|
|
40
|
+
const { describe, it, expect, vi, beforeEach } = import.meta.vitest;
|
|
41
|
+
vi.mock('viem', async () => {
|
|
42
|
+
const actual = await vi.importActual('viem');
|
|
43
|
+
return {
|
|
44
|
+
...actual,
|
|
45
|
+
isAddress: vi.fn(),
|
|
46
|
+
isAddressEqual: vi.fn()
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
vi.mock('./context', () => ({
|
|
50
|
+
getAccountContext: vi.fn()
|
|
51
|
+
}));
|
|
52
|
+
vi.mock('svelte/store', async () => {
|
|
53
|
+
const actual = await vi.importActual('svelte/store');
|
|
54
|
+
return {
|
|
55
|
+
...actual,
|
|
56
|
+
get: vi.fn()
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
describe('useAccount', () => {
|
|
60
|
+
const mockGetAccountContext = vi.mocked(getAccountContext);
|
|
61
|
+
const mockGet = vi.mocked(get);
|
|
62
|
+
const mockIsAddress = vi.mocked(isAddress);
|
|
63
|
+
const mockIsAddressEqual = vi.mocked(isAddressEqual);
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
vi.clearAllMocks();
|
|
66
|
+
});
|
|
67
|
+
it('should return account wrapped in an object', () => {
|
|
68
|
+
const mockAccountStore = readable('0x123');
|
|
69
|
+
mockGetAccountContext.mockReturnValue(mockAccountStore);
|
|
70
|
+
const result = useAccount();
|
|
71
|
+
expect(mockGetAccountContext).toHaveBeenCalled();
|
|
72
|
+
expect(result.account).toBe(mockAccountStore);
|
|
73
|
+
expect(result.matchesAccount).toBeInstanceOf(Function);
|
|
74
|
+
});
|
|
75
|
+
describe('matchesAccount', () => {
|
|
76
|
+
const mockAccountStore = readable('0x123');
|
|
77
|
+
const currentAccount = '0x123';
|
|
78
|
+
const testAddress1 = '0x123';
|
|
79
|
+
const testAddress2 = '0xdef';
|
|
80
|
+
const invalidAddress = 'invalid';
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
mockGetAccountContext.mockReturnValue(mockAccountStore);
|
|
83
|
+
});
|
|
84
|
+
it('should return true if addresses are valid and equal', () => {
|
|
85
|
+
// Setup mocks
|
|
86
|
+
mockGet.mockReturnValue(currentAccount);
|
|
87
|
+
mockIsAddress.mockReturnValue(true);
|
|
88
|
+
mockIsAddressEqual.mockReturnValue(true);
|
|
89
|
+
const { matchesAccount } = useAccount();
|
|
90
|
+
const result = matchesAccount(testAddress1);
|
|
91
|
+
expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
|
|
92
|
+
expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
|
|
93
|
+
expect(mockIsAddress).toHaveBeenCalledWith(testAddress1);
|
|
94
|
+
expect(mockIsAddressEqual).toHaveBeenCalledWith(currentAccount, testAddress1);
|
|
95
|
+
expect(result).toBe(true);
|
|
96
|
+
});
|
|
97
|
+
it('should return false if addresses are valid but not equal', () => {
|
|
98
|
+
// Setup mocks
|
|
99
|
+
mockGet.mockReturnValue(currentAccount);
|
|
100
|
+
mockIsAddress.mockReturnValue(true);
|
|
101
|
+
mockIsAddressEqual.mockReturnValue(false);
|
|
102
|
+
const { matchesAccount } = useAccount();
|
|
103
|
+
const result = matchesAccount(testAddress2);
|
|
104
|
+
expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
|
|
105
|
+
expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
|
|
106
|
+
expect(mockIsAddress).toHaveBeenCalledWith(testAddress2);
|
|
107
|
+
expect(mockIsAddressEqual).toHaveBeenCalledWith(currentAccount, testAddress2);
|
|
108
|
+
expect(result).toBe(false);
|
|
109
|
+
});
|
|
110
|
+
it('should return false if current account is not set', () => {
|
|
111
|
+
// Setup mocks
|
|
112
|
+
mockGet.mockReturnValue(null);
|
|
113
|
+
const { matchesAccount } = useAccount();
|
|
114
|
+
const result = matchesAccount(testAddress1);
|
|
115
|
+
expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
|
|
116
|
+
expect(mockIsAddress).not.toHaveBeenCalled();
|
|
117
|
+
expect(mockIsAddressEqual).not.toHaveBeenCalled();
|
|
118
|
+
expect(result).toBe(false);
|
|
119
|
+
});
|
|
120
|
+
it('should return false if provided address is invalid', () => {
|
|
121
|
+
// Setup mocks
|
|
122
|
+
mockGet.mockReturnValue(currentAccount);
|
|
123
|
+
// This is crucial: we need to ensure short-circuit evaluation works correctly
|
|
124
|
+
mockIsAddress.mockImplementation((address) => {
|
|
125
|
+
return address !== invalidAddress; // Only the invalid address returns false
|
|
126
|
+
});
|
|
127
|
+
// This should never be called due to short-circuit evaluation
|
|
128
|
+
mockIsAddressEqual.mockReturnValue(false);
|
|
129
|
+
const { matchesAccount } = useAccount();
|
|
130
|
+
const result = matchesAccount(invalidAddress);
|
|
131
|
+
expect(mockGet).toHaveBeenCalledWith(mockAccountStore);
|
|
132
|
+
expect(mockIsAddress).toHaveBeenCalledWith(currentAccount);
|
|
133
|
+
expect(mockIsAddress).toHaveBeenCalledWith(invalidAddress);
|
|
134
|
+
expect(mockIsAddressEqual).not.toHaveBeenCalled(); // This should now pass
|
|
135
|
+
expect(result).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
it('should return false if provided address is null', () => {
|
|
138
|
+
// Setup mocks
|
|
139
|
+
mockGet.mockReturnValue(currentAccount);
|
|
140
|
+
const { matchesAccount } = useAccount();
|
|
141
|
+
const result = matchesAccount(null);
|
|
142
|
+
expect(mockIsAddress).not.toHaveBeenCalled();
|
|
143
|
+
expect(mockIsAddressEqual).not.toHaveBeenCalled();
|
|
144
|
+
expect(result).toBe(false);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
}
|
package/dist/queries/keys.d.ts
CHANGED
|
@@ -7,3 +7,4 @@ export declare const QKEY_ORDER_TRADES_LIST = "orderTradesList";
|
|
|
7
7
|
export declare const QKEY_ORDER_QUOTE = "orderQuote";
|
|
8
8
|
export declare const QKEY_VAULTS_VOL_LIST = "orderVaultsVolumeList";
|
|
9
9
|
export declare const QKEY_ORDER_APY = "orderApy";
|
|
10
|
+
export declare const QKEY_TOKENS = "tokens";
|
package/dist/queries/keys.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/svelte-query';
|
|
2
2
|
export declare const queryClient: QueryClient;
|
|
3
|
-
export declare const
|
|
3
|
+
export declare const invalidateTanstackQueries: (queryClient: QueryClient, queryKey: string[]) => Promise<void>;
|
|
@@ -7,10 +7,15 @@ export const queryClient = new QueryClient({
|
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
});
|
|
10
|
-
export const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
export const invalidateTanstackQueries = async (queryClient, queryKey) => {
|
|
11
|
+
try {
|
|
12
|
+
await queryClient.invalidateQueries({
|
|
13
|
+
queryKey,
|
|
14
|
+
refetchType: 'all',
|
|
15
|
+
exact: false
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error('Failed to refresh data.');
|
|
20
|
+
}
|
|
16
21
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module awaitTransactionIndexing
|
|
3
|
+
* @description Utilities for waiting for transactions to be indexed by a subgraph
|
|
4
|
+
*/
|
|
5
|
+
import type { WasmEncodedResult, RaindexTransaction, RaindexOrder, Address, Hex } from '@rainlanguage/orderbook';
|
|
6
|
+
export type AwaitSubgraphConfig = {
|
|
7
|
+
chainId: number;
|
|
8
|
+
orderbook: Address;
|
|
9
|
+
txHash: Hex;
|
|
10
|
+
successMessage: string;
|
|
11
|
+
fetchEntityFn: (chainId: number, orderbook: Address, txHash: Hex) => Promise<WasmEncodedResult<RaindexTransaction | RaindexOrder[] | null | undefined>>;
|
|
12
|
+
isSuccess: (data: RaindexTransaction | RaindexOrder[]) => boolean;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Result of a subgraph indexing operation
|
|
16
|
+
* @template T The type of data returned by the subgraph
|
|
17
|
+
*/
|
|
18
|
+
export type IndexingResult<T> = {
|
|
19
|
+
/**
|
|
20
|
+
* The successful result of the indexing operation
|
|
21
|
+
*/
|
|
22
|
+
value?: {
|
|
23
|
+
/**
|
|
24
|
+
* The transaction hash
|
|
25
|
+
*/
|
|
26
|
+
txHash: Hex;
|
|
27
|
+
/**
|
|
28
|
+
* Message to display on successful indexing
|
|
29
|
+
*/
|
|
30
|
+
successMessage: string;
|
|
31
|
+
/**
|
|
32
|
+
* Optional order hash if available
|
|
33
|
+
*/
|
|
34
|
+
orderHash?: Hex;
|
|
35
|
+
/**
|
|
36
|
+
* Optional network key
|
|
37
|
+
*/
|
|
38
|
+
network?: string;
|
|
39
|
+
/**
|
|
40
|
+
* Optional data returned from the subgraph
|
|
41
|
+
*/
|
|
42
|
+
data?: T;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Error message if indexing failed
|
|
46
|
+
*/
|
|
47
|
+
error?: string;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Generic function to handle waiting for subgraph indexing
|
|
51
|
+
* Returns a promise that resolves with an object containing either value or error
|
|
52
|
+
*
|
|
53
|
+
* @template T The type of data returned by the subgraph
|
|
54
|
+
* @param options Configuration options for the indexing operation
|
|
55
|
+
* @param options.chainId Chain ID to query
|
|
56
|
+
* @param options.orderbook Orderbook address to query
|
|
57
|
+
* @param options.txHash Transaction hash to check for indexing
|
|
58
|
+
* @param options.successMessage Message to display on successful indexing
|
|
59
|
+
* @param options.maxAttempts Maximum number of attempts before timing out (default: 10)
|
|
60
|
+
* @param options.interval Interval between attempts in milliseconds (default: 1000)
|
|
61
|
+
* @param options.network Optional network identifier
|
|
62
|
+
* @param options.fetchEntityFn Function to fetch data from the subgraph
|
|
63
|
+
* @param options.isSuccess Function to determine if the fetched data indicates success
|
|
64
|
+
* @returns Promise resolving to an IndexingResult
|
|
65
|
+
*/
|
|
66
|
+
export declare const awaitSubgraphIndexing: <T>(options: {
|
|
67
|
+
/**
|
|
68
|
+
* Chain ID to query
|
|
69
|
+
*/
|
|
70
|
+
chainId: number;
|
|
71
|
+
/**
|
|
72
|
+
* Orderbook address to query
|
|
73
|
+
*/
|
|
74
|
+
orderbook: Address;
|
|
75
|
+
/**
|
|
76
|
+
* Transaction hash to check for indexing
|
|
77
|
+
*/
|
|
78
|
+
txHash: Hex;
|
|
79
|
+
/**
|
|
80
|
+
* Message to display on successful indexing
|
|
81
|
+
*/
|
|
82
|
+
successMessage: string;
|
|
83
|
+
/**
|
|
84
|
+
* Maximum number of attempts before timing out
|
|
85
|
+
*/
|
|
86
|
+
maxAttempts?: number;
|
|
87
|
+
/**
|
|
88
|
+
* Interval between attempts in milliseconds
|
|
89
|
+
*/
|
|
90
|
+
interval?: number;
|
|
91
|
+
/**
|
|
92
|
+
* Optional network identifier
|
|
93
|
+
*/
|
|
94
|
+
network?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Function to fetch data from the subgraph
|
|
97
|
+
* @param chainId Chain ID to query
|
|
98
|
+
* @param orderbook Orderbook address to query
|
|
99
|
+
* @param txHash Transaction hash to query
|
|
100
|
+
*/
|
|
101
|
+
fetchEntityFn: (chainId: number, orderbook: Address, txHash: Hex) => Promise<WasmEncodedResult<T | null | undefined>>;
|
|
102
|
+
/**
|
|
103
|
+
* Function to determine if the fetched data indicates success
|
|
104
|
+
* @param data The data returned from the subgraph
|
|
105
|
+
*/
|
|
106
|
+
isSuccess: (data: T) => boolean;
|
|
107
|
+
}) => Promise<IndexingResult<T>>;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module awaitTransactionIndexing
|
|
3
|
+
* @description Utilities for waiting for transactions to be indexed by a subgraph
|
|
4
|
+
*/
|
|
5
|
+
import { TransactionStoreErrorMessage } from '../types/transaction';
|
|
6
|
+
/**
|
|
7
|
+
* Generic function to handle waiting for subgraph indexing
|
|
8
|
+
* Returns a promise that resolves with an object containing either value or error
|
|
9
|
+
*
|
|
10
|
+
* @template T The type of data returned by the subgraph
|
|
11
|
+
* @param options Configuration options for the indexing operation
|
|
12
|
+
* @param options.chainId Chain ID to query
|
|
13
|
+
* @param options.orderbook Orderbook address to query
|
|
14
|
+
* @param options.txHash Transaction hash to check for indexing
|
|
15
|
+
* @param options.successMessage Message to display on successful indexing
|
|
16
|
+
* @param options.maxAttempts Maximum number of attempts before timing out (default: 10)
|
|
17
|
+
* @param options.interval Interval between attempts in milliseconds (default: 1000)
|
|
18
|
+
* @param options.network Optional network identifier
|
|
19
|
+
* @param options.fetchEntityFn Function to fetch data from the subgraph
|
|
20
|
+
* @param options.isSuccess Function to determine if the fetched data indicates success
|
|
21
|
+
* @returns Promise resolving to an IndexingResult
|
|
22
|
+
*/
|
|
23
|
+
export const awaitSubgraphIndexing = async (options) => {
|
|
24
|
+
const { chainId, orderbook, txHash, successMessage, maxAttempts = 10, interval = 1000, network, fetchEntityFn, isSuccess } = options;
|
|
25
|
+
const checkIndexing = async (attempt) => {
|
|
26
|
+
try {
|
|
27
|
+
const data = await fetchEntityFn(chainId, orderbook, txHash);
|
|
28
|
+
if (data.value && isSuccess(data.value)) {
|
|
29
|
+
let newOrderHash;
|
|
30
|
+
// Extract orderHash from order data if it exists in the expected format
|
|
31
|
+
// This only applies to addOrder transactions
|
|
32
|
+
if (Array.isArray(data.value) && data.value.length > 0 && data.value[0]?.orderHash) {
|
|
33
|
+
newOrderHash = data.value[0].orderHash;
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
value: {
|
|
37
|
+
txHash,
|
|
38
|
+
successMessage,
|
|
39
|
+
orderHash: newOrderHash,
|
|
40
|
+
network,
|
|
41
|
+
data: data.value
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Continue with the next attempt
|
|
48
|
+
}
|
|
49
|
+
if (attempt >= maxAttempts) {
|
|
50
|
+
return {
|
|
51
|
+
error: TransactionStoreErrorMessage.SUBGRAPH_TIMEOUT_ERROR
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
await new Promise((resolve) => setTimeout(resolve, interval));
|
|
55
|
+
return checkIndexing(attempt + 1);
|
|
56
|
+
};
|
|
57
|
+
return checkIndexing(1);
|
|
58
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const getExplorerLink: (hash: string, chainId: number, type: "tx" | "address") =>
|
|
1
|
+
export declare const getExplorerLink: (hash: string, chainId: number, type: "tx" | "address") => string;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import * as chains from 'viem/chains';
|
|
2
|
-
export const getExplorerLink =
|
|
2
|
+
export const getExplorerLink = (hash, chainId, type) => {
|
|
3
3
|
const chain = Object.values(chains).find((chain) => chain.id === chainId);
|
|
4
4
|
if (chain?.blockExplorers) {
|
|
5
5
|
return chain.blockExplorers.default.url + `/${type}/${hash}`;
|
|
6
6
|
}
|
|
7
|
-
|
|
8
|
-
return '';
|
|
9
|
-
}
|
|
7
|
+
return '';
|
|
10
8
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { DotrainOrderGui } from '@rainlanguage/orderbook
|
|
2
|
-
export declare function handleShareChoices(gui: DotrainOrderGui): Promise<void>;
|
|
1
|
+
import type { DotrainOrderGui } from '@rainlanguage/orderbook';
|
|
2
|
+
export declare function handleShareChoices(gui: DotrainOrderGui, registryUrl: string): Promise<void>;
|
|
@@ -1,10 +1,15 @@
|
|
|
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
|
|
7
|
-
const
|
|
7
|
+
const result = gui.serializeState();
|
|
8
|
+
if (result.error) {
|
|
9
|
+
throw new Error(result.error.msg);
|
|
10
|
+
}
|
|
11
|
+
const state = result.value;
|
|
8
12
|
url.searchParams.set('state', state || '');
|
|
13
|
+
url.searchParams.set('registry', registryUrl);
|
|
9
14
|
navigator.clipboard.writeText(url.toString());
|
|
10
15
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RaindexTrade } from '@rainlanguage/orderbook';
|
|
2
2
|
import type { UTCTimestamp } from 'lightweight-charts';
|
|
3
3
|
export type HistoricalOrderChartData = {
|
|
4
4
|
value: number;
|
|
5
5
|
time: UTCTimestamp;
|
|
6
6
|
color?: string;
|
|
7
7
|
}[];
|
|
8
|
-
export declare function prepareHistoricalOrderChartData(takeOrderEntities:
|
|
8
|
+
export declare function prepareHistoricalOrderChartData(takeOrderEntities: RaindexTrade[], colorTheme: string): {
|
|
9
9
|
value: number;
|
|
10
10
|
time: UTCTimestamp;
|
|
11
11
|
color?: string;
|