@rainlanguage/ui-components 0.0.1-alpha.120 → 0.0.1-alpha.121
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/components/deployment/DeploymentSteps.svelte +2 -4
- package/dist/components/deployment/DeploymentSteps.svelte.d.ts +2 -3
- package/dist/index.d.ts +2 -5
- package/dist/index.js +0 -2
- package/dist/models/Transaction.d.ts +1 -0
- package/dist/models/Transaction.js +13 -0
- package/dist/providers/transactions/TransactionManager.d.ts +21 -0
- package/dist/providers/transactions/TransactionManager.js +52 -2
- package/dist/services/awaitTransactionIndexing.js +3 -3
- package/dist/types/modal.d.ts +8 -6
- package/dist/types/transaction.d.ts +3 -13
- package/package.json +2 -2
- package/dist/__mocks__/mockTransactionStore.d.ts +0 -4
- package/dist/__mocks__/mockTransactionStore.js +0 -52
- package/dist/components/deployment/handleDeployment.d.ts +0 -11
- package/dist/components/deployment/handleDeployment.js +0 -33
- package/dist/stores/transactionStore.d.ts +0 -49
- package/dist/stores/transactionStore.js +0 -180
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import TokenIOInput from "./TokenIOInput.svelte";
|
|
3
3
|
import ComposedRainlangModal from "./ComposedRainlangModal.svelte";
|
|
4
4
|
import {
|
|
5
|
+
DotrainOrderGui
|
|
5
6
|
} from "@rainlanguage/orderbook";
|
|
6
7
|
import WalletConnect from "../wallet/WalletConnect.svelte";
|
|
7
8
|
import {} from "svelte/store";
|
|
@@ -13,8 +14,6 @@ import DepositInput from "./DepositInput.svelte";
|
|
|
13
14
|
import SelectToken from "./SelectToken.svelte";
|
|
14
15
|
import DeploymentSectionHeader from "./DeploymentSectionHeader.svelte";
|
|
15
16
|
import { useGui } from "../../hooks/useGui";
|
|
16
|
-
import { handleDeployment } from "./handleDeployment";
|
|
17
|
-
import {} from "../../types/transaction";
|
|
18
17
|
import { fade } from "svelte/transition";
|
|
19
18
|
import ShareChoicesButton from "./ShareChoicesButton.svelte";
|
|
20
19
|
import { useRegistry } from "../../providers/registry/useRegistry";
|
|
@@ -177,8 +176,7 @@ async function handleDeployButtonClick() {
|
|
|
177
176
|
return;
|
|
178
177
|
}
|
|
179
178
|
DeploymentStepsError.clear();
|
|
180
|
-
|
|
181
|
-
return onDeploy(deploymentArgs);
|
|
179
|
+
return onDeploy(gui, subgraphUrl);
|
|
182
180
|
} catch (e) {
|
|
183
181
|
DeploymentStepsError.catch(e, DeploymentStepsErrorCode.ADD_ORDER_FAILED);
|
|
184
182
|
} finally {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
-
import { type ConfigSource, type NameAndDescriptionCfg } from '@rainlanguage/orderbook';
|
|
2
|
+
import { type ConfigSource, type NameAndDescriptionCfg, DotrainOrderGui } from '@rainlanguage/orderbook';
|
|
3
3
|
import { type Writable } from 'svelte/store';
|
|
4
4
|
import type { AppKit } from '@reown/appkit';
|
|
5
|
-
import { type DeploymentArgs } from '../../types/transaction';
|
|
6
5
|
import type { Account } from '../../types/account';
|
|
7
6
|
declare const __propDef: {
|
|
8
7
|
props: {
|
|
@@ -12,7 +11,7 @@ declare const __propDef: {
|
|
|
12
11
|
description: string;
|
|
13
12
|
};
|
|
14
13
|
/** Strategy details containing name and description configuration */ strategyDetail: NameAndDescriptionCfg;
|
|
15
|
-
/** Handlers for deployment modals */ onDeploy: (
|
|
14
|
+
/** Handlers for deployment modals */ onDeploy: (gui: DotrainOrderGui, subgraphUrl?: string) => void;
|
|
16
15
|
wagmiConnected: Writable<boolean>;
|
|
17
16
|
appKitModal: Writable<AppKit>;
|
|
18
17
|
settings: Writable<ConfigSource>;
|
package/dist/index.d.ts
CHANGED
|
@@ -68,9 +68,8 @@ export { default as TransactionList } from './components/transactions/Transactio
|
|
|
68
68
|
export { default as FixedBottomTransaction } from './components/transactions/FixedBottomTransaction.svelte';
|
|
69
69
|
export type { AppStoresInterface } from './types/appStores.ts';
|
|
70
70
|
export type { OrderbookConfigSource, OrderbookCfgRef } from '@rainlanguage/orderbook';
|
|
71
|
-
export { TransactionStatusMessage, TransactionStoreErrorMessage, type
|
|
72
|
-
export type {
|
|
73
|
-
export type { VaultActionModalProps, QuoteDebugModalHandler, DebugTradeModalHandler, DeployModalProps, DisclaimerModalProps, TransactionConfirmationProps } from './types/modal';
|
|
71
|
+
export { TransactionStatusMessage, TransactionStoreErrorMessage, type TransactionArgs, type DeploymentArgs, type VaultActionArgs } from './types/transaction';
|
|
72
|
+
export type { VaultActionModalProps, QuoteDebugModalHandler, DebugTradeModalHandler, DisclaimerModalProps, TransactionConfirmationProps, HandleTransactionConfirmationModal } from './types/modal';
|
|
74
73
|
export type { ValidStrategyDetail, InvalidStrategyDetail } from './types/strategy';
|
|
75
74
|
export type { ToastProps } from './types/toast';
|
|
76
75
|
export { createResolvableQuery, createResolvableInfiniteQuery } from './__mocks__/queries';
|
|
@@ -85,7 +84,6 @@ export { DEFAULT_PAGE_SIZE, DEFAULT_REFRESH_INTERVAL } from './queries/constants
|
|
|
85
84
|
export { QKEY_VAULTS, QKEY_VAULT, QKEY_VAULT_CHANGES, QKEY_ORDERS, QKEY_ORDER, QKEY_ORDER_TRADES_LIST, QKEY_ORDER_QUOTE, QKEY_VAULTS_VOL_LIST, QKEY_ORDER_APY } from './queries/keys';
|
|
86
85
|
export { darkChartTheme, lightChartTheme } from './utils/lightweightChartsThemes';
|
|
87
86
|
export { lightCodeMirrorTheme, darkCodeMirrorTheme } from './utils/codeMirrorThemes';
|
|
88
|
-
export { default as transactionStore } from './stores/transactionStore';
|
|
89
87
|
export { cachedWritableStore, cachedWritableIntOptional, cachedWritableStringOptional, cachedWritableString } from './storesGeneric/cachedWritableStore';
|
|
90
88
|
export { default as logoLight } from './assets/logo-light.svg';
|
|
91
89
|
export { default as logoDark } from './assets/logo-dark.svg';
|
|
@@ -105,4 +103,3 @@ export { TransactionManager } from './providers/transactions/TransactionManager'
|
|
|
105
103
|
export { mockPageStore } from './__mocks__/stores';
|
|
106
104
|
export { mockConfigSource } from './__mocks__/settings';
|
|
107
105
|
export { mockSettingsStore } from './__mocks__/settings';
|
|
108
|
-
export { mockTransactionStore } from './__mocks__/mockTransactionStore';
|
package/dist/index.js
CHANGED
|
@@ -83,7 +83,6 @@ export { QKEY_VAULTS, QKEY_VAULT, QKEY_VAULT_CHANGES, QKEY_ORDERS, QKEY_ORDER, Q
|
|
|
83
83
|
export { darkChartTheme, lightChartTheme } from './utils/lightweightChartsThemes';
|
|
84
84
|
export { lightCodeMirrorTheme, darkCodeMirrorTheme } from './utils/codeMirrorThemes';
|
|
85
85
|
// Stores
|
|
86
|
-
export { default as transactionStore } from './stores/transactionStore';
|
|
87
86
|
export { cachedWritableStore, cachedWritableIntOptional, cachedWritableStringOptional, cachedWritableString } from './storesGeneric/cachedWritableStore';
|
|
88
87
|
// Assets
|
|
89
88
|
export { default as logoLight } from './assets/logo-light.svg';
|
|
@@ -108,4 +107,3 @@ export { TransactionManager } from './providers/transactions/TransactionManager'
|
|
|
108
107
|
export { mockPageStore } from './__mocks__/stores';
|
|
109
108
|
export { mockConfigSource } from './__mocks__/settings';
|
|
110
109
|
export { mockSettingsStore } from './__mocks__/settings';
|
|
111
|
-
export { mockTransactionStore } from './__mocks__/mockTransactionStore';
|
|
@@ -13,6 +13,7 @@ export class TransactionStore {
|
|
|
13
13
|
name;
|
|
14
14
|
config;
|
|
15
15
|
txHash;
|
|
16
|
+
networkKey;
|
|
16
17
|
links;
|
|
17
18
|
onSuccess;
|
|
18
19
|
onError;
|
|
@@ -29,6 +30,7 @@ export class TransactionStore {
|
|
|
29
30
|
this.config = args.config;
|
|
30
31
|
this.txHash = args.txHash;
|
|
31
32
|
this.name = args.name;
|
|
33
|
+
this.networkKey = args.networkKey;
|
|
32
34
|
this.links = args.toastLinks;
|
|
33
35
|
this.state = writable({
|
|
34
36
|
name: this.name,
|
|
@@ -110,6 +112,17 @@ export class TransactionStore {
|
|
|
110
112
|
this.updateState({
|
|
111
113
|
status: TransactionStatusMessage.SUCCESS
|
|
112
114
|
});
|
|
115
|
+
const newOrderHash = result.value.orderHash;
|
|
116
|
+
// If we have a new order hash, add the "View order" link
|
|
117
|
+
if (newOrderHash) {
|
|
118
|
+
const newLink = {
|
|
119
|
+
link: `/orders/${this.networkKey}-${newOrderHash}`,
|
|
120
|
+
label: 'View order'
|
|
121
|
+
};
|
|
122
|
+
this.updateState({
|
|
123
|
+
links: [newLink, ...this.links]
|
|
124
|
+
});
|
|
125
|
+
}
|
|
113
126
|
return this.onSuccess();
|
|
114
127
|
}
|
|
115
128
|
this.updateState({
|
|
@@ -132,6 +132,27 @@ export declare class TransactionManager {
|
|
|
132
132
|
entity: SgVault;
|
|
133
133
|
subgraphUrl: string;
|
|
134
134
|
}): Promise<Transaction>;
|
|
135
|
+
/**
|
|
136
|
+
* Creates and initializes a new transaction for deploying a strategy.
|
|
137
|
+
* @param args - Configuration for the deployment transaction.
|
|
138
|
+
* @param args.txHash - Hash of the transaction to track.
|
|
139
|
+
* @param args.chainId - Chain ID where the transaction is being executed.
|
|
140
|
+
* @param args.networkKey - Network identifier string.
|
|
141
|
+
* @param args.queryKey - The ID of the vault into which funds are deposited (used for query invalidation and UI links).
|
|
142
|
+
* @param args.subgraphUrl - URL of the subgraph to query for transaction status.
|
|
143
|
+
* @returns A new Transaction instance configured for deposit.
|
|
144
|
+
* @example
|
|
145
|
+
* const tx = await manager.createAddOrderTransaction({
|
|
146
|
+
* txHash: '0xdeploytxhash',
|
|
147
|
+
* chainId: 1,
|
|
148
|
+
* networkKey: 'mainnet',
|
|
149
|
+
* queryKey: '0x789...', // Vault ID
|
|
150
|
+
* subgraphUrl: 'https://api.thegraph.com/subgraphs/name/...',
|
|
151
|
+
* });
|
|
152
|
+
*/
|
|
153
|
+
createAddOrderTransaction(args: InternalTransactionArgs & {
|
|
154
|
+
subgraphUrl: string;
|
|
155
|
+
}): Promise<Transaction>;
|
|
135
156
|
/**
|
|
136
157
|
* Creates, initializes, and executes a new transaction instance.
|
|
137
158
|
* @param args - Configuration for the transaction.
|
|
@@ -2,7 +2,7 @@ import { writable } from 'svelte/store';
|
|
|
2
2
|
import { TransactionStore } from '../../models/Transaction';
|
|
3
3
|
import { getExplorerLink } from '../../services/getExplorerLink';
|
|
4
4
|
import { TransactionName } from '../../types/transaction';
|
|
5
|
-
import { getTransaction, getTransactionRemoveOrders } from '@rainlanguage/orderbook';
|
|
5
|
+
import { getTransaction, getTransactionRemoveOrders, getTransactionAddOrders } from '@rainlanguage/orderbook';
|
|
6
6
|
import { formatUnits } from 'viem';
|
|
7
7
|
/**
|
|
8
8
|
* Manages blockchain transactions with toast notifications and query invalidation.
|
|
@@ -246,6 +246,54 @@ export class TransactionManager {
|
|
|
246
246
|
}
|
|
247
247
|
});
|
|
248
248
|
}
|
|
249
|
+
/**
|
|
250
|
+
* Creates and initializes a new transaction for deploying a strategy.
|
|
251
|
+
* @param args - Configuration for the deployment transaction.
|
|
252
|
+
* @param args.txHash - Hash of the transaction to track.
|
|
253
|
+
* @param args.chainId - Chain ID where the transaction is being executed.
|
|
254
|
+
* @param args.networkKey - Network identifier string.
|
|
255
|
+
* @param args.queryKey - The ID of the vault into which funds are deposited (used for query invalidation and UI links).
|
|
256
|
+
* @param args.subgraphUrl - URL of the subgraph to query for transaction status.
|
|
257
|
+
* @returns A new Transaction instance configured for deposit.
|
|
258
|
+
* @example
|
|
259
|
+
* const tx = await manager.createAddOrderTransaction({
|
|
260
|
+
* txHash: '0xdeploytxhash',
|
|
261
|
+
* chainId: 1,
|
|
262
|
+
* networkKey: 'mainnet',
|
|
263
|
+
* queryKey: '0x789...', // Vault ID
|
|
264
|
+
* subgraphUrl: 'https://api.thegraph.com/subgraphs/name/...',
|
|
265
|
+
* });
|
|
266
|
+
*/
|
|
267
|
+
async createAddOrderTransaction(args) {
|
|
268
|
+
const { queryKey, txHash, chainId, subgraphUrl } = args;
|
|
269
|
+
const name = 'Deploying order';
|
|
270
|
+
const errorMessage = 'Deployment failed.';
|
|
271
|
+
const successMessage = 'Order deployed successfully.';
|
|
272
|
+
const explorerLink = await getExplorerLink(txHash, chainId, 'tx');
|
|
273
|
+
const toastLinks = [
|
|
274
|
+
{
|
|
275
|
+
link: explorerLink,
|
|
276
|
+
label: 'View on explorer'
|
|
277
|
+
}
|
|
278
|
+
];
|
|
279
|
+
return this.createTransaction({
|
|
280
|
+
...args,
|
|
281
|
+
name,
|
|
282
|
+
errorMessage,
|
|
283
|
+
successMessage,
|
|
284
|
+
queryKey,
|
|
285
|
+
toastLinks,
|
|
286
|
+
awaitSubgraphConfig: {
|
|
287
|
+
subgraphUrl,
|
|
288
|
+
txHash,
|
|
289
|
+
successMessage,
|
|
290
|
+
fetchEntityFn: getTransactionAddOrders,
|
|
291
|
+
isSuccess: (data) => {
|
|
292
|
+
return Array.isArray(data) ? data.length > 0 : false;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
249
297
|
/**
|
|
250
298
|
* Creates, initializes, and executes a new transaction instance.
|
|
251
299
|
* @param args - Configuration for the transaction.
|
|
@@ -264,7 +312,9 @@ export class TransactionManager {
|
|
|
264
312
|
config: this.wagmiConfig
|
|
265
313
|
};
|
|
266
314
|
const onSuccess = () => {
|
|
267
|
-
|
|
315
|
+
if (args.queryKey) {
|
|
316
|
+
this.queryClient.invalidateQueries({ queryKey: [args.queryKey] });
|
|
317
|
+
}
|
|
268
318
|
};
|
|
269
319
|
const onError = () => {
|
|
270
320
|
this.addToast({
|
|
@@ -25,17 +25,17 @@ export const awaitSubgraphIndexing = async (options) => {
|
|
|
25
25
|
try {
|
|
26
26
|
const data = await fetchEntityFn(subgraphUrl, txHash);
|
|
27
27
|
if (data.value && isSuccess(data.value)) {
|
|
28
|
-
let
|
|
28
|
+
let newOrderHash;
|
|
29
29
|
// Extract orderHash from order data if it exists in the expected format
|
|
30
30
|
// This only applies to addOrder transactions
|
|
31
31
|
if (Array.isArray(data.value) && data.value.length > 0 && data.value[0]?.order?.orderHash) {
|
|
32
|
-
|
|
32
|
+
newOrderHash = data.value[0].order.orderHash;
|
|
33
33
|
}
|
|
34
34
|
return {
|
|
35
35
|
value: {
|
|
36
36
|
txHash,
|
|
37
37
|
successMessage,
|
|
38
|
-
orderHash,
|
|
38
|
+
orderHash: newOrderHash,
|
|
39
39
|
network,
|
|
40
40
|
data: data.value
|
|
41
41
|
}
|
package/dist/types/modal.d.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { SgOrder, SgVault } from '@rainlanguage/orderbook';
|
|
2
|
-
import type {
|
|
2
|
+
import type { VaultActionArgs } from './transaction';
|
|
3
3
|
import type { Hex } from 'viem';
|
|
4
4
|
export type VaultActionModalProps = {
|
|
5
5
|
open: boolean;
|
|
6
6
|
args: VaultActionArgs;
|
|
7
7
|
onSubmit: (amount: bigint) => void;
|
|
8
8
|
};
|
|
9
|
-
export type DeployModalProps = {
|
|
10
|
-
open: boolean;
|
|
11
|
-
args: DeploymentArgs;
|
|
12
|
-
};
|
|
13
9
|
export type DisclaimerModalProps = {
|
|
14
10
|
open: boolean;
|
|
15
11
|
onAccept: () => void;
|
|
@@ -22,9 +18,15 @@ export type TransactionConfirmationProps = {
|
|
|
22
18
|
chainId: number;
|
|
23
19
|
toAddress: Hex;
|
|
24
20
|
onConfirm: (hash: Hex) => void;
|
|
25
|
-
entity
|
|
21
|
+
entity?: SgOrder | SgVault;
|
|
26
22
|
calldata: string;
|
|
27
23
|
};
|
|
28
24
|
};
|
|
29
25
|
export type QuoteDebugModalHandler = (order: SgOrder, rpcUrl: string, orderbook: string, inputIOIndex: number, outputIOIndex: number, pair: string, blockNumber?: number) => void;
|
|
30
26
|
export type DebugTradeModalHandler = (hash: string, rpcUrl: string) => void;
|
|
27
|
+
export type HandleTransactionConfirmationModal = (props: TransactionConfirmationProps, options?: {
|
|
28
|
+
timeout?: number;
|
|
29
|
+
}) => Promise<{
|
|
30
|
+
success: boolean;
|
|
31
|
+
hash?: string;
|
|
32
|
+
}>;
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
import type { Hex } from 'viem';
|
|
2
|
-
import type { SgVault,
|
|
2
|
+
import type { SgVault, VaultCalldataResult, DeploymentTransactionArgs } from '@rainlanguage/orderbook';
|
|
3
3
|
import type { Config } from '@wagmi/core';
|
|
4
4
|
import type { ToastLink } from './toast';
|
|
5
5
|
import type { AwaitSubgraphConfig } from '../services/awaitTransactionIndexing';
|
|
6
|
-
export type
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
export type DeploymentArgs = {
|
|
10
|
-
approvals: ExtendedApprovalCalldata[];
|
|
11
|
-
deploymentCalldata: DepositAndAddOrderCalldataResult;
|
|
12
|
-
orderbookAddress: Hex;
|
|
13
|
-
chainId: number;
|
|
14
|
-
subgraphUrl?: string;
|
|
6
|
+
export type DeploymentArgs = DeploymentTransactionArgs & {
|
|
7
|
+
subgraphUrl: string;
|
|
15
8
|
network: string;
|
|
16
9
|
};
|
|
17
10
|
export type VaultActionArgs = {
|
|
@@ -71,6 +64,3 @@ export type TransactionArgs = InternalTransactionArgs & {
|
|
|
71
64
|
toastLinks: ToastLink[];
|
|
72
65
|
awaitSubgraphConfig?: AwaitSubgraphConfig;
|
|
73
66
|
};
|
|
74
|
-
export type DeploymentTransactionArgs = Omit<DeploymentArgs, 'account'> & {
|
|
75
|
-
config: Config;
|
|
76
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rainlanguage/ui-components",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.121",
|
|
4
4
|
"description": "A component library for building Svelte applications to be used with Raindex.",
|
|
5
5
|
"license": "LicenseRef-DCL-1.0",
|
|
6
6
|
"author": "Rain Open Source Software Ltd",
|
|
@@ -53,7 +53,7 @@
|
|
|
53
53
|
"@fontsource/dm-sans": "5.1.0",
|
|
54
54
|
"@imask/svelte": "7.6.1",
|
|
55
55
|
"@observablehq/plot": "0.6.16",
|
|
56
|
-
"@rainlanguage/orderbook": "0.0.1-alpha.
|
|
56
|
+
"@rainlanguage/orderbook": "0.0.1-alpha.121",
|
|
57
57
|
"@reown/appkit": "1.6.4",
|
|
58
58
|
"@reown/appkit-adapter-wagmi": "1.6.4",
|
|
59
59
|
"@sentry/sveltekit": "7.120.0",
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
import { initialState, TransactionErrorMessage } from '../stores/transactionStore';
|
|
3
|
-
import { TransactionStatusMessage } from '../types/transaction';
|
|
4
|
-
const mockTransactionWritable = writable(initialState);
|
|
5
|
-
export const mockTransactionStore = {
|
|
6
|
-
subscribe: mockTransactionWritable.subscribe,
|
|
7
|
-
reset: () => mockTransactionWritable.set(initialState),
|
|
8
|
-
handleDeploymentTransaction: async () => {
|
|
9
|
-
mockTransactionWritable.update((state) => ({
|
|
10
|
-
...state,
|
|
11
|
-
status: TransactionStatusMessage.SUCCESS,
|
|
12
|
-
message: 'Strategy deployed successfully!',
|
|
13
|
-
hash: '0x123'
|
|
14
|
-
}));
|
|
15
|
-
return Promise.resolve();
|
|
16
|
-
},
|
|
17
|
-
checkingWalletAllowance: (message = '') => mockTransactionWritable.update((state) => ({
|
|
18
|
-
...state,
|
|
19
|
-
status: TransactionStatusMessage.CHECKING_ALLOWANCE,
|
|
20
|
-
message
|
|
21
|
-
})),
|
|
22
|
-
awaitWalletConfirmation: (message = '') => mockTransactionWritable.update((state) => ({
|
|
23
|
-
...state,
|
|
24
|
-
status: TransactionStatusMessage.PENDING_WALLET,
|
|
25
|
-
message
|
|
26
|
-
})),
|
|
27
|
-
awaitApprovalTx: (hash) => mockTransactionWritable.update((state) => ({
|
|
28
|
-
...state,
|
|
29
|
-
hash,
|
|
30
|
-
status: TransactionStatusMessage.PENDING_APPROVAL,
|
|
31
|
-
message: 'Approving token spend...'
|
|
32
|
-
})),
|
|
33
|
-
transactionSuccess: (hash, message = '', newOrderHash = '', network = '') => mockTransactionWritable.update((state) => ({
|
|
34
|
-
...state,
|
|
35
|
-
status: TransactionStatusMessage.SUCCESS,
|
|
36
|
-
hash,
|
|
37
|
-
message,
|
|
38
|
-
newOrderHash,
|
|
39
|
-
network
|
|
40
|
-
})),
|
|
41
|
-
transactionError: (error, hash = '') => mockTransactionWritable.update((state) => ({
|
|
42
|
-
...state,
|
|
43
|
-
status: TransactionStatusMessage.ERROR,
|
|
44
|
-
error,
|
|
45
|
-
hash
|
|
46
|
-
})),
|
|
47
|
-
// Extra function for testing purposes
|
|
48
|
-
mockSetSubscribeValue: (value) => mockTransactionWritable.update((state) => ({
|
|
49
|
-
...state,
|
|
50
|
-
...value
|
|
51
|
-
}))
|
|
52
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { DotrainOrderGui } from '@rainlanguage/orderbook';
|
|
2
|
-
import type { DeploymentArgs } from '../../types/transaction';
|
|
3
|
-
export declare enum AddOrderErrors {
|
|
4
|
-
ADD_ORDER_FAILED = "Failed to add order",
|
|
5
|
-
MISSING_GUI = "Order GUI is required",
|
|
6
|
-
MISSING_CONFIG = "Wagmi config is required",
|
|
7
|
-
NO_ACCOUNT_CONNECTED = "No wallet address found",
|
|
8
|
-
ERROR_GETTING_ARGS = "Error getting deployment transaction args",
|
|
9
|
-
ERROR_GETTING_NETWORK_KEY = "Error getting network key"
|
|
10
|
-
}
|
|
11
|
-
export declare function handleDeployment(gui: DotrainOrderGui, account: string | null, subgraphUrl?: string): Promise<DeploymentArgs>;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export var AddOrderErrors;
|
|
2
|
-
(function (AddOrderErrors) {
|
|
3
|
-
AddOrderErrors["ADD_ORDER_FAILED"] = "Failed to add order";
|
|
4
|
-
AddOrderErrors["MISSING_GUI"] = "Order GUI is required";
|
|
5
|
-
AddOrderErrors["MISSING_CONFIG"] = "Wagmi config is required";
|
|
6
|
-
AddOrderErrors["NO_ACCOUNT_CONNECTED"] = "No wallet address found";
|
|
7
|
-
AddOrderErrors["ERROR_GETTING_ARGS"] = "Error getting deployment transaction args";
|
|
8
|
-
AddOrderErrors["ERROR_GETTING_NETWORK_KEY"] = "Error getting network key";
|
|
9
|
-
})(AddOrderErrors || (AddOrderErrors = {}));
|
|
10
|
-
export async function handleDeployment(gui, account, subgraphUrl) {
|
|
11
|
-
const networkKeyResult = gui.getNetworkKey();
|
|
12
|
-
if (networkKeyResult.error) {
|
|
13
|
-
throw new Error(AddOrderErrors.ERROR_GETTING_NETWORK_KEY);
|
|
14
|
-
}
|
|
15
|
-
const network = networkKeyResult.value;
|
|
16
|
-
if (!account) {
|
|
17
|
-
throw new Error(AddOrderErrors.NO_ACCOUNT_CONNECTED);
|
|
18
|
-
}
|
|
19
|
-
const result = await gui.getDeploymentTransactionArgs(account);
|
|
20
|
-
if (result.error) {
|
|
21
|
-
throw new Error(result.error.msg);
|
|
22
|
-
}
|
|
23
|
-
const { approvals, deploymentCalldata, orderbookAddress, chainId } = result.value;
|
|
24
|
-
return {
|
|
25
|
-
approvals,
|
|
26
|
-
deploymentCalldata,
|
|
27
|
-
// Cast to Hex, since js_api returns a string
|
|
28
|
-
orderbookAddress: orderbookAddress,
|
|
29
|
-
chainId,
|
|
30
|
-
network,
|
|
31
|
-
subgraphUrl
|
|
32
|
-
};
|
|
33
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { TransactionStatusMessage } from '../types/transaction';
|
|
2
|
-
import type { DeploymentTransactionArgs } from '../types/transaction';
|
|
3
|
-
export declare const ADDRESS_ZERO = "0x0000000000000000000000000000000000000000";
|
|
4
|
-
export declare const ONE: bigint;
|
|
5
|
-
export type TransactionState = {
|
|
6
|
-
status: TransactionStatusMessage;
|
|
7
|
-
error: string;
|
|
8
|
-
hash: string;
|
|
9
|
-
data: null;
|
|
10
|
-
functionName: string;
|
|
11
|
-
message: string;
|
|
12
|
-
newOrderHash: string;
|
|
13
|
-
network: string;
|
|
14
|
-
explorerLink: string;
|
|
15
|
-
};
|
|
16
|
-
export declare enum TransactionErrorMessage {
|
|
17
|
-
BAD_CALLLDATA = "Bad calldata.",
|
|
18
|
-
DEPLOY_FAILED = "Lock transaction failed.",
|
|
19
|
-
TIMEOUT = "The subgraph took too long to respond.",
|
|
20
|
-
APPROVAL_FAILED = "Approval transaction failed.",
|
|
21
|
-
USER_REJECTED_APPROVAL = "User rejected approval transaction.",
|
|
22
|
-
USER_REJECTED_TRANSACTION = "User rejected the transaction.",
|
|
23
|
-
DEPLOYMENT_FAILED = "Deployment transaction failed.",
|
|
24
|
-
SWITCH_CHAIN_FAILED = "Failed to switch chain."
|
|
25
|
-
}
|
|
26
|
-
export type TransactionStore = {
|
|
27
|
-
subscribe: (run: (value: TransactionState) => void) => () => void;
|
|
28
|
-
reset: () => void;
|
|
29
|
-
handleDeploymentTransaction: (args: DeploymentTransactionArgs) => Promise<void>;
|
|
30
|
-
checkingWalletAllowance: (message?: string) => void;
|
|
31
|
-
awaitWalletConfirmation: (message?: string) => void;
|
|
32
|
-
awaitApprovalTx: (hash: string) => void;
|
|
33
|
-
transactionSuccess: (hash: string, message?: string) => void;
|
|
34
|
-
transactionError: (message: TransactionErrorMessage, hash?: string) => void;
|
|
35
|
-
};
|
|
36
|
-
export declare const initialState: TransactionState;
|
|
37
|
-
declare const _default: {
|
|
38
|
-
subscribe: (this: void, run: import("svelte/store").Subscriber<TransactionState>, invalidate?: import("svelte/store").Invalidator<TransactionState> | undefined) => import("svelte/store").Unsubscriber;
|
|
39
|
-
reset: () => void;
|
|
40
|
-
handleDeploymentTransaction: ({ config, approvals, deploymentCalldata, orderbookAddress, chainId, subgraphUrl, network }: DeploymentTransactionArgs) => Promise<void>;
|
|
41
|
-
checkingWalletAllowance: (message?: string) => void;
|
|
42
|
-
awaitWalletConfirmation: (message?: string) => void;
|
|
43
|
-
awaitApprovalTx: (hash: string, symbol: string | undefined) => void;
|
|
44
|
-
transactionSuccess: (hash: string, message?: string, newOrderHash?: string, network?: string) => void;
|
|
45
|
-
transactionError: (error: TransactionErrorMessage, hash?: string) => void;
|
|
46
|
-
awaitTransactionIndexing: (subgraphUrl: string, txHash: string, successMessage: string) => Promise<void>;
|
|
47
|
-
awaitNewOrderIndexing: (subgraphUrl: string, txHash: string, network?: string) => Promise<void>;
|
|
48
|
-
};
|
|
49
|
-
export default _default;
|
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
import { sendTransaction, switchChain, waitForTransactionReceipt } from '@wagmi/core';
|
|
3
|
-
import { getExplorerLink } from '../services/getExplorerLink';
|
|
4
|
-
import { TransactionStatusMessage } from '../types/transaction';
|
|
5
|
-
import { awaitSubgraphIndexing } from '../services/awaitTransactionIndexing';
|
|
6
|
-
import { getTransaction, getTransactionAddOrders } from '@rainlanguage/orderbook';
|
|
7
|
-
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
|
|
8
|
-
export const ONE = BigInt('1000000000000000000');
|
|
9
|
-
export var TransactionErrorMessage;
|
|
10
|
-
(function (TransactionErrorMessage) {
|
|
11
|
-
TransactionErrorMessage["BAD_CALLLDATA"] = "Bad calldata.";
|
|
12
|
-
TransactionErrorMessage["DEPLOY_FAILED"] = "Lock transaction failed.";
|
|
13
|
-
TransactionErrorMessage["TIMEOUT"] = "The subgraph took too long to respond.";
|
|
14
|
-
TransactionErrorMessage["APPROVAL_FAILED"] = "Approval transaction failed.";
|
|
15
|
-
TransactionErrorMessage["USER_REJECTED_APPROVAL"] = "User rejected approval transaction.";
|
|
16
|
-
TransactionErrorMessage["USER_REJECTED_TRANSACTION"] = "User rejected the transaction.";
|
|
17
|
-
TransactionErrorMessage["DEPLOYMENT_FAILED"] = "Deployment transaction failed.";
|
|
18
|
-
TransactionErrorMessage["SWITCH_CHAIN_FAILED"] = "Failed to switch chain.";
|
|
19
|
-
})(TransactionErrorMessage || (TransactionErrorMessage = {}));
|
|
20
|
-
export const initialState = {
|
|
21
|
-
status: TransactionStatusMessage.IDLE,
|
|
22
|
-
error: '',
|
|
23
|
-
hash: '',
|
|
24
|
-
data: null,
|
|
25
|
-
functionName: '',
|
|
26
|
-
message: '',
|
|
27
|
-
newOrderHash: '',
|
|
28
|
-
network: '',
|
|
29
|
-
explorerLink: ''
|
|
30
|
-
};
|
|
31
|
-
const transactionStore = () => {
|
|
32
|
-
const { subscribe, set, update } = writable(initialState);
|
|
33
|
-
const reset = () => set(initialState);
|
|
34
|
-
const awaitTransactionIndexing = async (subgraphUrl, txHash, successMessage) => {
|
|
35
|
-
update((state) => ({
|
|
36
|
-
...state,
|
|
37
|
-
status: TransactionStatusMessage.PENDING_SUBGRAPH,
|
|
38
|
-
message: 'Waiting for transaction to be indexed...'
|
|
39
|
-
}));
|
|
40
|
-
const result = await awaitSubgraphIndexing({
|
|
41
|
-
subgraphUrl,
|
|
42
|
-
txHash,
|
|
43
|
-
successMessage,
|
|
44
|
-
fetchEntityFn: getTransaction,
|
|
45
|
-
isSuccess: (data) => !!data
|
|
46
|
-
});
|
|
47
|
-
if (result.error) {
|
|
48
|
-
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
49
|
-
}
|
|
50
|
-
if (result.value) {
|
|
51
|
-
return transactionSuccess(result.value.txHash, successMessage);
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const awaitNewOrderIndexing = async (subgraphUrl, txHash, network) => {
|
|
55
|
-
update((state) => ({
|
|
56
|
-
...state,
|
|
57
|
-
status: TransactionStatusMessage.PENDING_SUBGRAPH,
|
|
58
|
-
message: 'Waiting for new order to be indexed...'
|
|
59
|
-
}));
|
|
60
|
-
const result = await awaitSubgraphIndexing({
|
|
61
|
-
subgraphUrl,
|
|
62
|
-
txHash,
|
|
63
|
-
successMessage: 'New order indexed successfully',
|
|
64
|
-
network,
|
|
65
|
-
fetchEntityFn: getTransactionAddOrders,
|
|
66
|
-
isSuccess: (data) => data?.length > 0
|
|
67
|
-
});
|
|
68
|
-
if (result.error) {
|
|
69
|
-
return transactionError(TransactionErrorMessage.TIMEOUT);
|
|
70
|
-
}
|
|
71
|
-
if (result.value) {
|
|
72
|
-
return transactionSuccess(result.value.txHash, result.value.successMessage, result.value.orderHash, result.value.network);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const checkingWalletAllowance = (message) => update((state) => ({
|
|
76
|
-
...state,
|
|
77
|
-
status: TransactionStatusMessage.CHECKING_ALLOWANCE,
|
|
78
|
-
message: message || ''
|
|
79
|
-
}));
|
|
80
|
-
const awaitWalletConfirmation = (message) => update((state) => ({
|
|
81
|
-
...state,
|
|
82
|
-
status: TransactionStatusMessage.PENDING_WALLET,
|
|
83
|
-
message: message || ''
|
|
84
|
-
}));
|
|
85
|
-
const awaitApprovalTx = (hash, symbol) => update((state) => ({
|
|
86
|
-
...state,
|
|
87
|
-
hash: hash,
|
|
88
|
-
status: TransactionStatusMessage.PENDING_APPROVAL,
|
|
89
|
-
message: `Approving ${symbol || 'token'} spend...`
|
|
90
|
-
}));
|
|
91
|
-
const awaitTx = (hash, status, explorerLink, message) => update((state) => ({
|
|
92
|
-
...state,
|
|
93
|
-
hash: hash,
|
|
94
|
-
status: status,
|
|
95
|
-
message: message || 'Waiting for transaction...',
|
|
96
|
-
explorerLink: explorerLink || ''
|
|
97
|
-
}));
|
|
98
|
-
const transactionSuccess = (hash, message, newOrderHash, network) => {
|
|
99
|
-
update((state) => ({
|
|
100
|
-
...state,
|
|
101
|
-
status: TransactionStatusMessage.SUCCESS,
|
|
102
|
-
hash: hash,
|
|
103
|
-
message: message || '',
|
|
104
|
-
newOrderHash: newOrderHash || '',
|
|
105
|
-
network: network || ''
|
|
106
|
-
}));
|
|
107
|
-
};
|
|
108
|
-
const transactionError = (error, hash) => update((state) => ({
|
|
109
|
-
...state,
|
|
110
|
-
status: TransactionStatusMessage.ERROR,
|
|
111
|
-
error,
|
|
112
|
-
message: error,
|
|
113
|
-
hash: hash ?? ''
|
|
114
|
-
}));
|
|
115
|
-
const handleDeploymentTransaction = async ({ config, approvals, deploymentCalldata, orderbookAddress, chainId, subgraphUrl, network }) => {
|
|
116
|
-
reset();
|
|
117
|
-
try {
|
|
118
|
-
await switchChain(config, { chainId });
|
|
119
|
-
}
|
|
120
|
-
catch {
|
|
121
|
-
return transactionError(TransactionErrorMessage.SWITCH_CHAIN_FAILED);
|
|
122
|
-
}
|
|
123
|
-
for (const approval of approvals) {
|
|
124
|
-
let approvalHash;
|
|
125
|
-
try {
|
|
126
|
-
awaitWalletConfirmation(`Please approve ${approval.symbol || approval.token} spend in your wallet...`);
|
|
127
|
-
approvalHash = await sendTransaction(config, {
|
|
128
|
-
to: approval.token,
|
|
129
|
-
data: approval.calldata
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
catch {
|
|
133
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_APPROVAL);
|
|
134
|
-
}
|
|
135
|
-
try {
|
|
136
|
-
awaitApprovalTx(approvalHash, approval.symbol);
|
|
137
|
-
await waitForTransactionReceipt(config, { hash: approvalHash });
|
|
138
|
-
}
|
|
139
|
-
catch {
|
|
140
|
-
return transactionError(TransactionErrorMessage.APPROVAL_FAILED);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
let hash;
|
|
144
|
-
try {
|
|
145
|
-
awaitWalletConfirmation('Please confirm deployment in your wallet...');
|
|
146
|
-
hash = await sendTransaction(config, {
|
|
147
|
-
to: orderbookAddress,
|
|
148
|
-
data: deploymentCalldata
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
catch {
|
|
152
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
153
|
-
}
|
|
154
|
-
try {
|
|
155
|
-
const transactionExplorerLink = await getExplorerLink(hash, chainId, 'tx');
|
|
156
|
-
awaitTx(hash, TransactionStatusMessage.PENDING_DEPLOYMENT, transactionExplorerLink);
|
|
157
|
-
await waitForTransactionReceipt(config, { hash });
|
|
158
|
-
if (subgraphUrl) {
|
|
159
|
-
return awaitNewOrderIndexing(subgraphUrl, hash, network);
|
|
160
|
-
}
|
|
161
|
-
return transactionSuccess(hash, 'Deployment successful. Check the Orders page for your new order.', '', network);
|
|
162
|
-
}
|
|
163
|
-
catch {
|
|
164
|
-
return transactionError(TransactionErrorMessage.DEPLOYMENT_FAILED);
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
return {
|
|
168
|
-
subscribe,
|
|
169
|
-
reset,
|
|
170
|
-
handleDeploymentTransaction,
|
|
171
|
-
checkingWalletAllowance,
|
|
172
|
-
awaitWalletConfirmation,
|
|
173
|
-
awaitApprovalTx,
|
|
174
|
-
transactionSuccess,
|
|
175
|
-
transactionError,
|
|
176
|
-
awaitTransactionIndexing,
|
|
177
|
-
awaitNewOrderIndexing
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
export default transactionStore();
|