@rainlanguage/ui-components 0.0.1-alpha.8 → 0.0.1-alpha.80
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__/orderDetail.d.ts +1 -1
- package/dist/__mocks__/MockComponent.svelte +4 -0
- package/dist/__mocks__/MockComponent.svelte.d.ts +3 -1
- package/dist/__mocks__/mockTransactionStore.d.ts +3 -21
- package/dist/__mocks__/mockTransactionStore.js +26 -13
- package/dist/__mocks__/settings.d.ts +6 -2
- package/dist/__mocks__/settings.js +6 -1
- package/dist/__mocks__/stores.d.ts +86 -19
- package/dist/__mocks__/stores.js +26 -17
- package/dist/components/ButtonVaultLink.svelte +3 -3
- package/dist/components/ButtonVaultLink.svelte.d.ts +1 -1
- package/dist/components/CheckboxMyItemsOnly.svelte +3 -2
- package/dist/components/CheckboxMyItemsOnly.svelte.d.ts +0 -1
- package/dist/components/CodeMirrorDotrain.svelte +4 -0
- package/dist/components/CodeMirrorDotrain.svelte.d.ts +1 -0
- package/dist/components/CodeMirrorRainlang.svelte +2 -2
- package/dist/components/CodeMirrorRainlang.svelte.d.ts +1 -1
- package/dist/components/Hash.svelte +3 -3
- package/dist/components/License.svelte +5 -4
- package/dist/components/ListViewOrderbookFilters.svelte +14 -13
- package/dist/components/ListViewOrderbookFilters.svelte.d.ts +2 -5
- package/dist/components/OrderOrVaultHash.svelte +10 -7
- package/dist/components/OrderOrVaultHash.svelte.d.ts +1 -1
- package/dist/components/PageHeader.svelte +20 -22
- package/dist/components/PageHeader.svelte.d.ts +1 -0
- package/dist/components/TanstackAppTable.svelte +2 -3
- package/dist/components/TanstackAppTable.svelte.d.ts +1 -1
- package/dist/components/Tooltip.svelte +8 -0
- package/dist/components/Tooltip.svelte.d.ts +21 -0
- package/dist/components/charts/OrderTradesChart.svelte +1 -1
- package/dist/components/charts/TanstackLightweightChartLine.svelte +5 -9
- package/dist/components/charts/VaultBalanceChart.svelte +1 -1
- package/dist/components/charts/VaultBalanceChart.svelte.d.ts +1 -1
- 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/ComposedRainlangModal.svelte +7 -5
- package/dist/components/deployment/ComposedRainlangModal.svelte.d.ts +1 -4
- package/dist/components/deployment/DeploymentSectionHeader.svelte +7 -4
- package/dist/components/deployment/DeploymentSteps.svelte +180 -155
- package/dist/components/deployment/DeploymentSteps.svelte.d.ts +7 -13
- package/dist/components/deployment/DeploymentsSection.svelte +18 -14
- package/dist/components/deployment/DepositInput.svelte +31 -14
- package/dist/components/deployment/DepositInput.svelte.d.ts +1 -2
- package/dist/components/deployment/FieldDefinitionInput.svelte +20 -14
- package/dist/components/deployment/FieldDefinitionInput.svelte.d.ts +1 -2
- package/dist/components/deployment/SelectToken.svelte +12 -3
- package/dist/components/deployment/SelectToken.svelte.d.ts +1 -2
- package/dist/components/deployment/StrategyPage.svelte +6 -2
- package/dist/components/deployment/TokenIOInput.svelte +15 -5
- package/dist/components/deployment/TokenIOInput.svelte.d.ts +1 -2
- package/dist/components/deployment/handleDeployment.d.ts +11 -0
- package/dist/components/deployment/handleDeployment.js +33 -0
- package/dist/components/detail/OrderDetail.svelte +46 -41
- package/dist/components/detail/OrderDetail.svelte.d.ts +11 -8
- package/dist/components/detail/TanstackOrderQuote.svelte +6 -6
- package/dist/components/detail/TanstackOrderQuote.svelte.d.ts +1 -1
- package/dist/components/detail/VaultDetail.svelte +29 -40
- package/dist/components/detail/VaultDetail.svelte.d.ts +10 -10
- package/dist/components/dropdown/DropdownActiveSubgraphs.svelte.d.ts +1 -1
- 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/InputRegistryUrl.svelte +2 -2
- package/dist/components/input/InputToken.svelte +2 -2
- package/dist/components/input/InputTokenAmount.svelte +1 -1
- package/dist/components/tables/OrderAPY.svelte +1 -1
- package/dist/components/tables/OrderTradesListTable.svelte +1 -1
- package/dist/components/tables/OrderVaultsVolTable.svelte +1 -1
- package/dist/components/tables/OrdersListTable.svelte +16 -18
- package/dist/components/tables/OrdersListTable.svelte.d.ts +0 -6
- package/dist/components/tables/VaultBalanceChangesTable.svelte +3 -3
- package/dist/components/tables/VaultsListTable.svelte +43 -52
- package/dist/components/tables/VaultsListTable.svelte.d.ts +3 -6
- 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 +5 -2
- package/dist/errors/DeploymentStepsError.js +4 -1
- package/dist/hooks/useGui.d.ts +3 -0
- package/dist/hooks/useGui.js +11 -0
- package/dist/index.d.ts +12 -6
- package/dist/index.js +14 -5
- package/dist/providers/GuiProvider.svelte +8 -0
- package/dist/providers/GuiProvider.svelte.d.ts +21 -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/queryClient.d.ts +1 -1
- package/dist/queries/queryClient.js +3 -3
- package/dist/services/awaitTransactionIndexing.d.ts +163 -0
- package/dist/services/awaitTransactionIndexing.js +120 -0
- package/dist/services/handleShareChoices.d.ts +2 -2
- package/dist/services/handleShareChoices.js +7 -2
- package/dist/services/historicalOrderCharts.d.ts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +1 -1
- package/dist/services/registry.d.ts +6 -0
- package/dist/services/registry.js +156 -0
- package/dist/stores/transactionStore.d.ts +7 -10
- package/dist/stores/transactionStore.js +35 -61
- 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/account.js +1 -0
- package/dist/types/appStores.d.ts +2 -2
- package/dist/types/modal.d.ts +1 -1
- package/dist/types/strategy.d.ts +1 -1
- package/dist/types/transaction.d.ts +3 -3
- package/dist/utils/constructHashLink.d.ts +23 -0
- package/dist/utils/constructHashLink.js +110 -0
- package/dist/utils/vault.d.ts +1 -1
- package/package.json +34 -34
- package/dist/components/deployment/DepositsSection.svelte +0 -8
- package/dist/components/deployment/DepositsSection.svelte.d.ts +0 -20
- package/dist/components/deployment/FieldDefinitionsSection.svelte +0 -9
- package/dist/components/deployment/FieldDefinitionsSection.svelte.d.ts +0 -20
- package/dist/components/deployment/SelectTokensSection.svelte +0 -17
- package/dist/components/deployment/SelectTokensSection.svelte.d.ts +0 -21
- package/dist/components/deployment/TokenIOSection.svelte +0 -17
- package/dist/components/deployment/TokenIOSection.svelte.d.ts +0 -21
- package/dist/components/deployment/getDeploymentTransactionArgs.d.ts +0 -17
- package/dist/components/deployment/getDeploymentTransactionArgs.js +0 -24
- package/dist/components/detail/DepositOrWithdrawButtons.svelte +0 -44
- package/dist/components/detail/DepositOrWithdrawButtons.svelte.d.ts +0 -26
- package/dist/components/dropdown/DropdownOrderStatus.svelte +0 -31
- package/dist/components/dropdown/DropdownOrderStatus.svelte.d.ts +0 -19
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DotrainOrderGui } from '@rainlanguage/orderbook';
|
|
1
2
|
/**
|
|
2
3
|
* Fetches and parses a file registry from a given URL.
|
|
3
4
|
* The registry is expected to be a text file where each line contains a file name and URL separated by a space.
|
|
@@ -52,6 +53,40 @@ export const fetchRegistryDotrains = async (url) => {
|
|
|
52
53
|
}));
|
|
53
54
|
return dotrains;
|
|
54
55
|
};
|
|
56
|
+
export async function validateStrategies(registryDotrains) {
|
|
57
|
+
const strategiesPromises = registryDotrains.map(async (registryDotrain) => {
|
|
58
|
+
try {
|
|
59
|
+
const result = await DotrainOrderGui.getStrategyDetails(registryDotrain.dotrain);
|
|
60
|
+
if (result.error) {
|
|
61
|
+
throw new Error(result.error.msg);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
valid: true,
|
|
65
|
+
data: {
|
|
66
|
+
...registryDotrain,
|
|
67
|
+
details: result.value
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
return {
|
|
73
|
+
valid: false,
|
|
74
|
+
data: {
|
|
75
|
+
name: registryDotrain.name,
|
|
76
|
+
error: error instanceof Error ? error.message : String(error)
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const strategiesResults = await Promise.all(strategiesPromises);
|
|
82
|
+
const validStrategies = strategiesResults
|
|
83
|
+
.filter((result) => result.valid)
|
|
84
|
+
.map((result) => result.data);
|
|
85
|
+
const invalidStrategies = strategiesResults
|
|
86
|
+
.filter((result) => !result.valid)
|
|
87
|
+
.map((result) => result.data);
|
|
88
|
+
return { validStrategies, invalidStrategies };
|
|
89
|
+
}
|
|
55
90
|
if (import.meta.vitest) {
|
|
56
91
|
const { describe, it, expect, vi } = import.meta.vitest;
|
|
57
92
|
describe('getFileRegistry', () => {
|
|
@@ -130,4 +165,125 @@ file2.rain https://example.com/file2.rain`;
|
|
|
130
165
|
await expect(fetchRegistryDotrains('https://example.com/registry')).rejects.toThrow('Error fetching dotrain for file1.rain: Network error');
|
|
131
166
|
});
|
|
132
167
|
});
|
|
168
|
+
describe('validateStrategies', async () => {
|
|
169
|
+
// Mock the DotrainOrderGui dependency
|
|
170
|
+
vi.mock('@rainlanguage/orderbook', () => ({
|
|
171
|
+
DotrainOrderGui: {
|
|
172
|
+
getStrategyDetails: vi.fn()
|
|
173
|
+
}
|
|
174
|
+
}));
|
|
175
|
+
// Import DotrainOrderGui after mocking
|
|
176
|
+
const { DotrainOrderGui } = await import('@rainlanguage/orderbook');
|
|
177
|
+
beforeEach(() => {
|
|
178
|
+
vi.resetAllMocks();
|
|
179
|
+
});
|
|
180
|
+
it('should validate strategies and categorize them properly', async () => {
|
|
181
|
+
// Input data
|
|
182
|
+
const registryDotrains = [
|
|
183
|
+
{ name: 'valid.rain', dotrain: 'valid dotrain content' },
|
|
184
|
+
{ name: 'invalid.rain', dotrain: 'invalid dotrain content' },
|
|
185
|
+
{ name: 'another-valid.rain', dotrain: 'another valid content' }
|
|
186
|
+
];
|
|
187
|
+
// Set up mock responses for the DotrainOrderGui
|
|
188
|
+
DotrainOrderGui.getStrategyDetails
|
|
189
|
+
.mockResolvedValueOnce({
|
|
190
|
+
value: { name: 'Valid Strategy', description: 'A valid strategy' },
|
|
191
|
+
error: null
|
|
192
|
+
})
|
|
193
|
+
.mockResolvedValueOnce({
|
|
194
|
+
error: { msg: 'Invalid syntax' },
|
|
195
|
+
value: null
|
|
196
|
+
})
|
|
197
|
+
.mockResolvedValueOnce({
|
|
198
|
+
value: { name: 'Another Valid', description: 'Another valid strategy' },
|
|
199
|
+
error: null
|
|
200
|
+
});
|
|
201
|
+
// Call the function with our test data
|
|
202
|
+
const result = await validateStrategies(registryDotrains);
|
|
203
|
+
// Verify DotrainOrderGui was called correctly
|
|
204
|
+
expect(DotrainOrderGui.getStrategyDetails).toHaveBeenCalledTimes(3);
|
|
205
|
+
expect(DotrainOrderGui.getStrategyDetails).toHaveBeenCalledWith('valid dotrain content');
|
|
206
|
+
expect(DotrainOrderGui.getStrategyDetails).toHaveBeenCalledWith('invalid dotrain content');
|
|
207
|
+
expect(DotrainOrderGui.getStrategyDetails).toHaveBeenCalledWith('another valid content');
|
|
208
|
+
// Verify the valid strategies are processed correctly
|
|
209
|
+
expect(result.validStrategies).toHaveLength(2);
|
|
210
|
+
expect(result.validStrategies[0].name).toBe('valid.rain');
|
|
211
|
+
expect(result.validStrategies[0].dotrain).toBe('valid dotrain content');
|
|
212
|
+
expect(result.validStrategies[0].details).toEqual({
|
|
213
|
+
name: 'Valid Strategy',
|
|
214
|
+
description: 'A valid strategy'
|
|
215
|
+
});
|
|
216
|
+
// Verify the invalid strategies are processed correctly
|
|
217
|
+
expect(result.invalidStrategies).toHaveLength(1);
|
|
218
|
+
expect(result.invalidStrategies[0].name).toBe('invalid.rain');
|
|
219
|
+
expect(result.invalidStrategies[0].error).toBe('Invalid syntax');
|
|
220
|
+
});
|
|
221
|
+
it('should handle exceptions thrown during strategy validation', async () => {
|
|
222
|
+
// Input data
|
|
223
|
+
const registryDotrains = [{ name: 'error.rain', dotrain: 'will throw error' }];
|
|
224
|
+
// Mock the DotrainOrderGui to throw an exception
|
|
225
|
+
DotrainOrderGui.getStrategyDetails.mockRejectedValueOnce(new Error('Unexpected parsing error'));
|
|
226
|
+
// Call the function
|
|
227
|
+
const result = await validateStrategies(registryDotrains);
|
|
228
|
+
// Verify results
|
|
229
|
+
expect(result.validStrategies).toHaveLength(0);
|
|
230
|
+
expect(result.invalidStrategies).toHaveLength(1);
|
|
231
|
+
expect(result.invalidStrategies[0].name).toBe('error.rain');
|
|
232
|
+
expect(result.invalidStrategies[0].error).toBe('Unexpected parsing error');
|
|
233
|
+
});
|
|
234
|
+
it('should handle non-Error objects being thrown', async () => {
|
|
235
|
+
// Input data
|
|
236
|
+
const registryDotrains = [{ name: 'string-error.rain', dotrain: 'will throw string' }];
|
|
237
|
+
// Mock the DotrainOrderGui to throw a string instead of an Error
|
|
238
|
+
DotrainOrderGui.getStrategyDetails.mockRejectedValueOnce('String error message');
|
|
239
|
+
// Call the function
|
|
240
|
+
const result = await validateStrategies(registryDotrains);
|
|
241
|
+
// Verify results
|
|
242
|
+
expect(result.validStrategies).toHaveLength(0);
|
|
243
|
+
expect(result.invalidStrategies).toHaveLength(1);
|
|
244
|
+
expect(result.invalidStrategies[0].name).toBe('string-error.rain');
|
|
245
|
+
expect(result.invalidStrategies[0].error).toBe('String error message');
|
|
246
|
+
});
|
|
247
|
+
it('should process an empty array of strategies', async () => {
|
|
248
|
+
const result = await validateStrategies([]);
|
|
249
|
+
expect(result.validStrategies).toEqual([]);
|
|
250
|
+
expect(result.invalidStrategies).toEqual([]);
|
|
251
|
+
expect(DotrainOrderGui.getStrategyDetails).not.toHaveBeenCalled();
|
|
252
|
+
});
|
|
253
|
+
it('should handle mixed validation results correctly', async () => {
|
|
254
|
+
// Create a mix of scenarios
|
|
255
|
+
const registryDotrains = [
|
|
256
|
+
{ name: 'valid1.rain', dotrain: 'valid content 1' },
|
|
257
|
+
{ name: 'error.rain', dotrain: 'will throw error' },
|
|
258
|
+
{ name: 'valid2.rain', dotrain: 'valid content 2' },
|
|
259
|
+
{ name: 'invalid.rain', dotrain: 'invalid content' }
|
|
260
|
+
];
|
|
261
|
+
// Set up mock responses
|
|
262
|
+
DotrainOrderGui.getStrategyDetails
|
|
263
|
+
.mockResolvedValueOnce({
|
|
264
|
+
value: { strategyName: 'Strategy 1', description: 'Description 1' },
|
|
265
|
+
error: null
|
|
266
|
+
})
|
|
267
|
+
.mockRejectedValueOnce(new Error('Processing error'))
|
|
268
|
+
.mockResolvedValueOnce({
|
|
269
|
+
value: { strategyName: 'Strategy 2', description: 'Description 2' },
|
|
270
|
+
error: null
|
|
271
|
+
})
|
|
272
|
+
.mockResolvedValueOnce({
|
|
273
|
+
error: { msg: 'Validation failed' },
|
|
274
|
+
value: null
|
|
275
|
+
});
|
|
276
|
+
// Call the function
|
|
277
|
+
const result = await validateStrategies(registryDotrains);
|
|
278
|
+
// Verify results
|
|
279
|
+
expect(result.validStrategies).toHaveLength(2);
|
|
280
|
+
expect(result.validStrategies[0].name).toBe('valid1.rain');
|
|
281
|
+
expect(result.validStrategies[1].name).toBe('valid2.rain');
|
|
282
|
+
expect(result.invalidStrategies).toHaveLength(2);
|
|
283
|
+
expect(result.invalidStrategies[0].name).toBe('error.rain');
|
|
284
|
+
expect(result.invalidStrategies[0].error).toBe('Processing error');
|
|
285
|
+
expect(result.invalidStrategies[1].name).toBe('invalid.rain');
|
|
286
|
+
expect(result.invalidStrategies[1].error).toBe('Validation failed');
|
|
287
|
+
});
|
|
288
|
+
});
|
|
133
289
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Hex } from 'viem';
|
|
2
2
|
import type { Config } from '@wagmi/core';
|
|
3
|
-
import type { ApprovalCalldata,
|
|
3
|
+
import type { ApprovalCalldata, DepositCalldataResult, RemoveOrderCalldata, SgVault, WithdrawCalldataResult } from '@rainlanguage/orderbook';
|
|
4
|
+
import type { DeploymentArgs } from '../types/transaction';
|
|
4
5
|
export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
|
5
6
|
export declare const ONE: bigint;
|
|
6
7
|
export declare enum TransactionStatus {
|
|
@@ -19,7 +20,7 @@ export declare enum TransactionStatus {
|
|
|
19
20
|
export declare enum TransactionErrorMessage {
|
|
20
21
|
BAD_CALLLDATA = "Bad calldata.",
|
|
21
22
|
DEPLOY_FAILED = "Lock transaction failed.",
|
|
22
|
-
TIMEOUT = "
|
|
23
|
+
TIMEOUT = "The subgraph took too long to respond.",
|
|
23
24
|
APPROVAL_FAILED = "Approval transaction failed.",
|
|
24
25
|
USER_REJECTED_APPROVAL = "User rejected approval transaction.",
|
|
25
26
|
USER_REJECTED_TRANSACTION = "User rejected the transaction.",
|
|
@@ -32,14 +33,9 @@ export declare enum TransactionErrorMessage {
|
|
|
32
33
|
export type ExtendedApprovalCalldata = ApprovalCalldata & {
|
|
33
34
|
symbol?: string;
|
|
34
35
|
};
|
|
35
|
-
export type
|
|
36
|
+
export type DeploymentArgsWithoutAccount = Omit<DeploymentArgs, 'account'>;
|
|
37
|
+
export type DeploymentTransactionArgs = DeploymentArgsWithoutAccount & {
|
|
36
38
|
config: Config;
|
|
37
|
-
approvals: ExtendedApprovalCalldata[];
|
|
38
|
-
deploymentCalldata: DepositAndAddOrderCalldataResult;
|
|
39
|
-
orderbookAddress: Hex;
|
|
40
|
-
chainId: number;
|
|
41
|
-
subgraphUrl: string;
|
|
42
|
-
network: string;
|
|
43
39
|
};
|
|
44
40
|
export type DepositOrWithdrawTransactionArgs = {
|
|
45
41
|
config: Config;
|
|
@@ -80,6 +76,7 @@ export type TransactionStore = {
|
|
|
80
76
|
transactionSuccess: (hash: string, message?: string) => void;
|
|
81
77
|
transactionError: (message: TransactionErrorMessage, hash?: string) => void;
|
|
82
78
|
};
|
|
79
|
+
export declare const initialState: TransactionState;
|
|
83
80
|
declare const _default: {
|
|
84
81
|
subscribe: (this: void, run: import("svelte/store").Subscriber<TransactionState>, invalidate?: import("svelte/store").Invalidator<TransactionState> | undefined) => import("svelte/store").Unsubscriber;
|
|
85
82
|
reset: () => void;
|
|
@@ -90,7 +87,7 @@ declare const _default: {
|
|
|
90
87
|
awaitWalletConfirmation: (message?: string) => void;
|
|
91
88
|
awaitApprovalTx: (hash: string, symbol: string | undefined) => void;
|
|
92
89
|
transactionSuccess: (hash: string, message?: string, newOrderHash?: string, network?: string) => void;
|
|
93
|
-
transactionError: (
|
|
90
|
+
transactionError: (error: TransactionErrorMessage, hash?: string) => void;
|
|
94
91
|
awaitTransactionIndexing: (subgraphUrl: string, txHash: string, successMessage: string) => Promise<void>;
|
|
95
92
|
awaitNewOrderIndexing: (subgraphUrl: string, txHash: string, network?: string) => Promise<void>;
|
|
96
93
|
awaitRemoveOrderIndexing: (subgraphUrl: string, txHash: string) => Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { writable } from 'svelte/store';
|
|
2
2
|
import { sendTransaction, switchChain, waitForTransactionReceipt } from '@wagmi/core';
|
|
3
|
-
import { getTransaction, getTransactionAddOrders, getTransactionRemoveOrders } from '@rainlanguage/orderbook/js_api';
|
|
4
3
|
import { getExplorerLink } from '../services/getExplorerLink';
|
|
4
|
+
import { awaitSubgraphIndexing, getNewOrderConfig, getRemoveOrderConfig, getTransactionConfig } from '../services/awaitTransactionIndexing';
|
|
5
5
|
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
|
|
6
6
|
export const ONE = BigInt('1000000000000000000');
|
|
7
7
|
export var TransactionStatus;
|
|
@@ -22,7 +22,7 @@ export var TransactionErrorMessage;
|
|
|
22
22
|
(function (TransactionErrorMessage) {
|
|
23
23
|
TransactionErrorMessage["BAD_CALLLDATA"] = "Bad calldata.";
|
|
24
24
|
TransactionErrorMessage["DEPLOY_FAILED"] = "Lock transaction failed.";
|
|
25
|
-
TransactionErrorMessage["TIMEOUT"] = "
|
|
25
|
+
TransactionErrorMessage["TIMEOUT"] = "The subgraph took too long to respond.";
|
|
26
26
|
TransactionErrorMessage["APPROVAL_FAILED"] = "Approval transaction failed.";
|
|
27
27
|
TransactionErrorMessage["USER_REJECTED_APPROVAL"] = "User rejected approval transaction.";
|
|
28
28
|
TransactionErrorMessage["USER_REJECTED_TRANSACTION"] = "User rejected the transaction.";
|
|
@@ -32,7 +32,7 @@ export var TransactionErrorMessage;
|
|
|
32
32
|
TransactionErrorMessage["WITHDRAWAL_FAILED"] = "Failed to withdraw tokens.";
|
|
33
33
|
TransactionErrorMessage["REMOVE_ORDER_FAILED"] = "Failed to remove order.";
|
|
34
34
|
})(TransactionErrorMessage || (TransactionErrorMessage = {}));
|
|
35
|
-
const initialState = {
|
|
35
|
+
export const initialState = {
|
|
36
36
|
status: TransactionStatus.IDLE,
|
|
37
37
|
error: '',
|
|
38
38
|
hash: '',
|
|
@@ -50,26 +50,15 @@ const transactionStore = () => {
|
|
|
50
50
|
update((state) => ({
|
|
51
51
|
...state,
|
|
52
52
|
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
53
|
-
message: '
|
|
53
|
+
message: 'Waiting for transaction to be indexed...'
|
|
54
54
|
}));
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
transactionSuccess(txHash, successMessage);
|
|
63
|
-
}
|
|
64
|
-
else if (attempts >= 10) {
|
|
65
|
-
update((state) => ({
|
|
66
|
-
...state,
|
|
67
|
-
message: 'The subgraph took too long to respond. Please check again later.'
|
|
68
|
-
}));
|
|
69
|
-
clearInterval(interval);
|
|
70
|
-
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
71
|
-
}
|
|
72
|
-
}, 1000);
|
|
55
|
+
const result = await awaitSubgraphIndexing(getTransactionConfig(subgraphUrl, txHash, successMessage));
|
|
56
|
+
if (result.error) {
|
|
57
|
+
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
58
|
+
}
|
|
59
|
+
if (result.value) {
|
|
60
|
+
return transactionSuccess(result.value.txHash, result.value.successMessage);
|
|
61
|
+
}
|
|
73
62
|
};
|
|
74
63
|
const awaitNewOrderIndexing = async (subgraphUrl, txHash, network) => {
|
|
75
64
|
update((state) => ({
|
|
@@ -77,23 +66,13 @@ const transactionStore = () => {
|
|
|
77
66
|
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
78
67
|
message: 'Waiting for new order to be indexed...'
|
|
79
68
|
}));
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
message: 'The subgraph took too long to respond. Please check again later.'
|
|
88
|
-
}));
|
|
89
|
-
clearInterval(interval);
|
|
90
|
-
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
91
|
-
}
|
|
92
|
-
else if (addOrders?.length > 0) {
|
|
93
|
-
clearInterval(interval);
|
|
94
|
-
return transactionSuccess(txHash, '', addOrders[0].order.orderHash, network);
|
|
95
|
-
}
|
|
96
|
-
}, 1000);
|
|
69
|
+
const result = await awaitSubgraphIndexing(getNewOrderConfig(subgraphUrl, txHash, '', network));
|
|
70
|
+
if (result.error) {
|
|
71
|
+
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
72
|
+
}
|
|
73
|
+
if (result.value) {
|
|
74
|
+
return transactionSuccess(result.value.txHash, result.value.successMessage, result.value.orderHash, result.value.network);
|
|
75
|
+
}
|
|
97
76
|
};
|
|
98
77
|
const awaitRemoveOrderIndexing = async (subgraphUrl, txHash) => {
|
|
99
78
|
update((state) => ({
|
|
@@ -101,23 +80,13 @@ const transactionStore = () => {
|
|
|
101
80
|
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
102
81
|
message: 'Waiting for order removal to be indexed...'
|
|
103
82
|
}));
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
message: 'The subgraph took too long to respond. Please check again later.'
|
|
112
|
-
}));
|
|
113
|
-
clearInterval(interval);
|
|
114
|
-
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
115
|
-
}
|
|
116
|
-
else if (removeOrders?.length > 0) {
|
|
117
|
-
clearInterval(interval);
|
|
118
|
-
return transactionSuccess(txHash);
|
|
119
|
-
}
|
|
120
|
-
}, 1000);
|
|
83
|
+
const result = await awaitSubgraphIndexing(getRemoveOrderConfig(subgraphUrl, txHash, 'Order removed successfully'));
|
|
84
|
+
if (result.error) {
|
|
85
|
+
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
86
|
+
}
|
|
87
|
+
if (result.value) {
|
|
88
|
+
return transactionSuccess(result.value.txHash, result.value.successMessage);
|
|
89
|
+
}
|
|
121
90
|
};
|
|
122
91
|
const checkingWalletAllowance = (message) => update((state) => ({
|
|
123
92
|
...state,
|
|
@@ -152,10 +121,10 @@ const transactionStore = () => {
|
|
|
152
121
|
network: network || ''
|
|
153
122
|
}));
|
|
154
123
|
};
|
|
155
|
-
const transactionError = (
|
|
124
|
+
const transactionError = (error, hash) => update((state) => ({
|
|
156
125
|
...state,
|
|
157
126
|
status: TransactionStatus.ERROR,
|
|
158
|
-
error:
|
|
127
|
+
error: error,
|
|
159
128
|
hash: hash || ''
|
|
160
129
|
}));
|
|
161
130
|
const handleDeploymentTransaction = async ({ config, approvals, deploymentCalldata, orderbookAddress, chainId, subgraphUrl, network }) => {
|
|
@@ -200,7 +169,10 @@ const transactionStore = () => {
|
|
|
200
169
|
const transactionExplorerLink = await getExplorerLink(hash, chainId, 'tx');
|
|
201
170
|
awaitTx(hash, TransactionStatus.PENDING_DEPLOYMENT, transactionExplorerLink);
|
|
202
171
|
await waitForTransactionReceipt(config, { hash });
|
|
203
|
-
|
|
172
|
+
if (subgraphUrl) {
|
|
173
|
+
return awaitNewOrderIndexing(subgraphUrl, hash, network);
|
|
174
|
+
}
|
|
175
|
+
return transactionSuccess(hash, 'Deployment successful. Check the Orders page for your new order.', '', network);
|
|
204
176
|
}
|
|
205
177
|
catch {
|
|
206
178
|
return transactionError(TransactionErrorMessage.DEPLOYMENT_FAILED);
|
|
@@ -245,9 +217,10 @@ const transactionStore = () => {
|
|
|
245
217
|
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
246
218
|
}
|
|
247
219
|
try {
|
|
220
|
+
const transactionExplorerLink = await getExplorerLink(hash, chainId, 'tx');
|
|
248
221
|
awaitTx(hash, action === 'deposit'
|
|
249
222
|
? TransactionStatus.PENDING_DEPOSIT
|
|
250
|
-
: TransactionStatus.PENDING_WITHDRAWAL);
|
|
223
|
+
: TransactionStatus.PENDING_WITHDRAWAL, transactionExplorerLink);
|
|
251
224
|
await waitForTransactionReceipt(config, { hash });
|
|
252
225
|
return awaitTransactionIndexing(subgraphUrl, hash, `The ${action === 'deposit' ? 'deposit' : 'withdrawal'} was successful.`);
|
|
253
226
|
}
|
|
@@ -276,7 +249,8 @@ const transactionStore = () => {
|
|
|
276
249
|
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
277
250
|
}
|
|
278
251
|
try {
|
|
279
|
-
|
|
252
|
+
const transactionExplorerLink = await getExplorerLink(hash, chainId, 'tx');
|
|
253
|
+
awaitTx(hash, TransactionStatus.PENDING_REMOVE_ORDER, transactionExplorerLink);
|
|
280
254
|
await waitForTransactionReceipt(config, { hash });
|
|
281
255
|
return awaitRemoveOrderIndexing(subgraphUrl, hash);
|
|
282
256
|
}
|
|
@@ -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);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Readable, Writable } from 'svelte/store';
|
|
2
|
-
import type { ConfigSource, OrderbookConfigSource } from '@rainlanguage/orderbook
|
|
2
|
+
import type { ConfigSource, OrderbookConfigSource } from '@rainlanguage/orderbook';
|
|
3
3
|
export interface AppStoresInterface {
|
|
4
4
|
settings: Writable<ConfigSource | undefined>;
|
|
5
5
|
activeSubgraphs: Writable<Record<string, string>>;
|
|
6
6
|
accounts: Readable<Record<string, string>>;
|
|
7
7
|
activeAccountsItems: Writable<Record<string, string>>;
|
|
8
|
-
activeOrderStatus: Writable<boolean
|
|
8
|
+
activeOrderStatus: Writable<boolean>;
|
|
9
9
|
orderHash: Writable<string>;
|
|
10
10
|
hideZeroBalanceVaults: Writable<boolean>;
|
|
11
11
|
activeNetworkRef: Writable<string | undefined>;
|
package/dist/types/modal.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { SgOrder } from '@rainlanguage/orderbook
|
|
1
|
+
import type { SgOrder } from '@rainlanguage/orderbook';
|
|
2
2
|
import type { DepositOrWithdrawArgs, OrderRemoveArgs, DeploymentArgs } from './transaction';
|
|
3
3
|
export type DepositOrWithdrawModalProps = {
|
|
4
4
|
open: boolean;
|
package/dist/types/strategy.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import type { ExtendedApprovalCalldata } from '../stores/transactionStore';
|
|
2
|
-
import type { DepositAndAddOrderCalldataResult } from '@rainlanguage/orderbook/js_api';
|
|
3
2
|
import type { Hex } from 'viem';
|
|
4
|
-
import type { SgOrder, SgVault } from '@rainlanguage/orderbook
|
|
3
|
+
import type { DepositAndAddOrderCalldataResult, SgOrder, SgVault } from '@rainlanguage/orderbook';
|
|
5
4
|
export type DeploymentArgs = {
|
|
6
5
|
approvals: ExtendedApprovalCalldata[];
|
|
7
6
|
deploymentCalldata: DepositAndAddOrderCalldataResult;
|
|
8
7
|
orderbookAddress: Hex;
|
|
9
8
|
chainId: number;
|
|
10
|
-
subgraphUrl
|
|
9
|
+
subgraphUrl?: string;
|
|
11
10
|
network: string;
|
|
12
11
|
};
|
|
13
12
|
export type DepositOrWithdrawArgs = {
|
|
@@ -17,6 +16,7 @@ export type DepositOrWithdrawArgs = {
|
|
|
17
16
|
chainId: number;
|
|
18
17
|
rpcUrl: string;
|
|
19
18
|
subgraphUrl: string;
|
|
19
|
+
account: Hex;
|
|
20
20
|
};
|
|
21
21
|
export type OrderRemoveArgs = {
|
|
22
22
|
order: SgOrder;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { SgOrder, SgOrderAsIO, SgVault } from '@rainlanguage/orderbook';
|
|
2
|
+
type OrderOrVault = SgOrder | SgOrderAsIO | SgVault;
|
|
3
|
+
/**
|
|
4
|
+
* Constructs a link path for an order or vault based on its type and network
|
|
5
|
+
* @param orderOrVault - The order or vault object
|
|
6
|
+
* @param type - The type of resource ('orders' or 'vaults')
|
|
7
|
+
* @param network - The network name
|
|
8
|
+
* @returns The constructed link path
|
|
9
|
+
*/
|
|
10
|
+
export declare function constructHashLink(orderOrVault: OrderOrVault, type: 'orders' | 'vaults', network: string): string;
|
|
11
|
+
/**
|
|
12
|
+
* Determines if an order or vault is active
|
|
13
|
+
* @param orderOrVault - The order or vault object
|
|
14
|
+
* @returns True if the order is active, false otherwise
|
|
15
|
+
*/
|
|
16
|
+
export declare function isOrderOrVaultActive(orderOrVault: OrderOrVault): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Extracts the hash value from an order or vault
|
|
19
|
+
* @param orderOrVault - The order or vault object
|
|
20
|
+
* @returns The hash value
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractHash(orderOrVault: OrderOrVault): string;
|
|
23
|
+
export {};
|