@rainlanguage/ui-components 0.0.1-alpha.21 → 0.0.1-alpha.211
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
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
import { writable } from 'svelte/store';
|
|
2
|
-
import { sendTransaction, switchChain, waitForTransactionReceipt } from '@wagmi/core';
|
|
3
|
-
import { getTransaction, getTransactionAddOrders, getTransactionRemoveOrders } from '@rainlanguage/orderbook/js_api';
|
|
4
|
-
import { getExplorerLink } from '../services/getExplorerLink';
|
|
5
|
-
export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
|
|
6
|
-
export const ONE = BigInt('1000000000000000000');
|
|
7
|
-
export var TransactionStatus;
|
|
8
|
-
(function (TransactionStatus) {
|
|
9
|
-
TransactionStatus["IDLE"] = "Idle";
|
|
10
|
-
TransactionStatus["CHECKING_ALLOWANCE"] = "Checking your allowance...";
|
|
11
|
-
TransactionStatus["PENDING_WALLET"] = "Waiting for wallet confirmation...";
|
|
12
|
-
TransactionStatus["PENDING_APPROVAL"] = "Approving token spend...";
|
|
13
|
-
TransactionStatus["PENDING_DEPLOYMENT"] = "Deploying your order...";
|
|
14
|
-
TransactionStatus["PENDING_WITHDRAWAL"] = "Withdrawing tokens...";
|
|
15
|
-
TransactionStatus["PENDING_DEPOSIT"] = "Depositing tokens...";
|
|
16
|
-
TransactionStatus["PENDING_REMOVE_ORDER"] = "Removing order...";
|
|
17
|
-
TransactionStatus["PENDING_SUBGRAPH"] = "Awaiting subgraph...";
|
|
18
|
-
TransactionStatus["SUCCESS"] = "Success! Transaction confirmed";
|
|
19
|
-
TransactionStatus["ERROR"] = "Something went wrong";
|
|
20
|
-
})(TransactionStatus || (TransactionStatus = {}));
|
|
21
|
-
export var TransactionErrorMessage;
|
|
22
|
-
(function (TransactionErrorMessage) {
|
|
23
|
-
TransactionErrorMessage["BAD_CALLLDATA"] = "Bad calldata.";
|
|
24
|
-
TransactionErrorMessage["DEPLOY_FAILED"] = "Lock transaction failed.";
|
|
25
|
-
TransactionErrorMessage["TIMEOUT"] = "Transaction timed out.";
|
|
26
|
-
TransactionErrorMessage["APPROVAL_FAILED"] = "Approval transaction failed.";
|
|
27
|
-
TransactionErrorMessage["USER_REJECTED_APPROVAL"] = "User rejected approval transaction.";
|
|
28
|
-
TransactionErrorMessage["USER_REJECTED_TRANSACTION"] = "User rejected the transaction.";
|
|
29
|
-
TransactionErrorMessage["DEPLOYMENT_FAILED"] = "Deployment transaction failed.";
|
|
30
|
-
TransactionErrorMessage["SWITCH_CHAIN_FAILED"] = "Failed to switch chain.";
|
|
31
|
-
TransactionErrorMessage["DEPOSIT_FAILED"] = "Failed to deposit tokens.";
|
|
32
|
-
TransactionErrorMessage["WITHDRAWAL_FAILED"] = "Failed to withdraw tokens.";
|
|
33
|
-
TransactionErrorMessage["REMOVE_ORDER_FAILED"] = "Failed to remove order.";
|
|
34
|
-
})(TransactionErrorMessage || (TransactionErrorMessage = {}));
|
|
35
|
-
const initialState = {
|
|
36
|
-
status: TransactionStatus.IDLE,
|
|
37
|
-
error: '',
|
|
38
|
-
hash: '',
|
|
39
|
-
data: null,
|
|
40
|
-
functionName: '',
|
|
41
|
-
message: '',
|
|
42
|
-
newOrderHash: '',
|
|
43
|
-
network: '',
|
|
44
|
-
explorerLink: ''
|
|
45
|
-
};
|
|
46
|
-
const transactionStore = () => {
|
|
47
|
-
const { subscribe, set, update } = writable(initialState);
|
|
48
|
-
const reset = () => set(initialState);
|
|
49
|
-
const awaitTransactionIndexing = async (subgraphUrl, txHash, successMessage) => {
|
|
50
|
-
update((state) => ({
|
|
51
|
-
...state,
|
|
52
|
-
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
53
|
-
message: 'Checking for transaction indexing...'
|
|
54
|
-
}));
|
|
55
|
-
let attempts = 0;
|
|
56
|
-
let newTx;
|
|
57
|
-
const interval = setInterval(async () => {
|
|
58
|
-
attempts++;
|
|
59
|
-
newTx = await getTransaction(subgraphUrl, txHash);
|
|
60
|
-
if (newTx) {
|
|
61
|
-
clearInterval(interval);
|
|
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);
|
|
73
|
-
};
|
|
74
|
-
const awaitNewOrderIndexing = async (subgraphUrl, txHash, network) => {
|
|
75
|
-
update((state) => ({
|
|
76
|
-
...state,
|
|
77
|
-
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
78
|
-
message: 'Waiting for new order to be indexed...'
|
|
79
|
-
}));
|
|
80
|
-
let attempts = 0;
|
|
81
|
-
const interval = setInterval(async () => {
|
|
82
|
-
attempts++;
|
|
83
|
-
const addOrders = await getTransactionAddOrders(subgraphUrl, txHash);
|
|
84
|
-
if (attempts >= 10) {
|
|
85
|
-
update((state) => ({
|
|
86
|
-
...state,
|
|
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);
|
|
97
|
-
};
|
|
98
|
-
const awaitRemoveOrderIndexing = async (subgraphUrl, txHash) => {
|
|
99
|
-
update((state) => ({
|
|
100
|
-
...state,
|
|
101
|
-
status: TransactionStatus.PENDING_SUBGRAPH,
|
|
102
|
-
message: 'Waiting for order removal to be indexed...'
|
|
103
|
-
}));
|
|
104
|
-
let attempts = 0;
|
|
105
|
-
const interval = setInterval(async () => {
|
|
106
|
-
attempts++;
|
|
107
|
-
const removeOrders = await getTransactionRemoveOrders(subgraphUrl, txHash);
|
|
108
|
-
if (attempts >= 10) {
|
|
109
|
-
update((state) => ({
|
|
110
|
-
...state,
|
|
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);
|
|
121
|
-
};
|
|
122
|
-
const checkingWalletAllowance = (message) => update((state) => ({
|
|
123
|
-
...state,
|
|
124
|
-
status: TransactionStatus.CHECKING_ALLOWANCE,
|
|
125
|
-
message: message || ''
|
|
126
|
-
}));
|
|
127
|
-
const awaitWalletConfirmation = (message) => update((state) => ({
|
|
128
|
-
...state,
|
|
129
|
-
status: TransactionStatus.PENDING_WALLET,
|
|
130
|
-
message: message || ''
|
|
131
|
-
}));
|
|
132
|
-
const awaitApprovalTx = (hash, symbol) => update((state) => ({
|
|
133
|
-
...state,
|
|
134
|
-
hash: hash,
|
|
135
|
-
status: TransactionStatus.PENDING_APPROVAL,
|
|
136
|
-
message: `Approving ${symbol || 'token'} spend...`
|
|
137
|
-
}));
|
|
138
|
-
const awaitTx = (hash, status, explorerLink, message) => update((state) => ({
|
|
139
|
-
...state,
|
|
140
|
-
hash: hash,
|
|
141
|
-
status: status,
|
|
142
|
-
message: message || 'Waiting for transaction...',
|
|
143
|
-
explorerLink: explorerLink || ''
|
|
144
|
-
}));
|
|
145
|
-
const transactionSuccess = (hash, message, newOrderHash, network) => {
|
|
146
|
-
update((state) => ({
|
|
147
|
-
...state,
|
|
148
|
-
status: TransactionStatus.SUCCESS,
|
|
149
|
-
hash: hash,
|
|
150
|
-
message: message || '',
|
|
151
|
-
newOrderHash: newOrderHash || '',
|
|
152
|
-
network: network || ''
|
|
153
|
-
}));
|
|
154
|
-
};
|
|
155
|
-
const transactionError = (message, hash) => update((state) => ({
|
|
156
|
-
...state,
|
|
157
|
-
status: TransactionStatus.ERROR,
|
|
158
|
-
error: message,
|
|
159
|
-
hash: hash || ''
|
|
160
|
-
}));
|
|
161
|
-
const handleDeploymentTransaction = async ({ config, approvals, deploymentCalldata, orderbookAddress, chainId, subgraphUrl, network }) => {
|
|
162
|
-
try {
|
|
163
|
-
await switchChain(config, { chainId });
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
return transactionError(TransactionErrorMessage.SWITCH_CHAIN_FAILED);
|
|
167
|
-
}
|
|
168
|
-
for (const approval of approvals) {
|
|
169
|
-
let approvalHash;
|
|
170
|
-
try {
|
|
171
|
-
awaitWalletConfirmation(`Please approve ${approval.symbol || approval.token} spend in your wallet...`);
|
|
172
|
-
approvalHash = await sendTransaction(config, {
|
|
173
|
-
to: approval.token,
|
|
174
|
-
data: approval.calldata
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_APPROVAL);
|
|
179
|
-
}
|
|
180
|
-
try {
|
|
181
|
-
awaitApprovalTx(approvalHash, approval.symbol);
|
|
182
|
-
await waitForTransactionReceipt(config, { hash: approvalHash });
|
|
183
|
-
}
|
|
184
|
-
catch {
|
|
185
|
-
return transactionError(TransactionErrorMessage.APPROVAL_FAILED);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
let hash;
|
|
189
|
-
try {
|
|
190
|
-
awaitWalletConfirmation('Please confirm deployment in your wallet...');
|
|
191
|
-
hash = await sendTransaction(config, {
|
|
192
|
-
to: orderbookAddress,
|
|
193
|
-
data: deploymentCalldata
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
catch {
|
|
197
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
198
|
-
}
|
|
199
|
-
try {
|
|
200
|
-
const transactionExplorerLink = await getExplorerLink(hash, chainId, 'tx');
|
|
201
|
-
awaitTx(hash, TransactionStatus.PENDING_DEPLOYMENT, transactionExplorerLink);
|
|
202
|
-
await waitForTransactionReceipt(config, { hash });
|
|
203
|
-
return awaitNewOrderIndexing(subgraphUrl, hash, network);
|
|
204
|
-
}
|
|
205
|
-
catch {
|
|
206
|
-
return transactionError(TransactionErrorMessage.DEPLOYMENT_FAILED);
|
|
207
|
-
}
|
|
208
|
-
};
|
|
209
|
-
const handleDepositOrWithdrawTransaction = async ({ config, approvalCalldata, transactionCalldata, action, chainId, vault, subgraphUrl }) => {
|
|
210
|
-
try {
|
|
211
|
-
await switchChain(config, { chainId });
|
|
212
|
-
}
|
|
213
|
-
catch {
|
|
214
|
-
return transactionError(TransactionErrorMessage.SWITCH_CHAIN_FAILED);
|
|
215
|
-
}
|
|
216
|
-
if (approvalCalldata) {
|
|
217
|
-
let approvalHash;
|
|
218
|
-
try {
|
|
219
|
-
awaitWalletConfirmation(`Please approve ${vault.token.symbol} spend in your wallet...`);
|
|
220
|
-
approvalHash = await sendTransaction(config, {
|
|
221
|
-
to: vault.token.address,
|
|
222
|
-
data: approvalCalldata
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
catch {
|
|
226
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_APPROVAL);
|
|
227
|
-
}
|
|
228
|
-
try {
|
|
229
|
-
awaitApprovalTx(approvalHash, vault.token.symbol);
|
|
230
|
-
await waitForTransactionReceipt(config, { hash: approvalHash });
|
|
231
|
-
}
|
|
232
|
-
catch {
|
|
233
|
-
return transactionError(TransactionErrorMessage.APPROVAL_FAILED);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
let hash;
|
|
237
|
-
try {
|
|
238
|
-
awaitWalletConfirmation(`Please confirm ${action === 'deposit' ? 'deposit' : 'withdrawal'} in your wallet...`);
|
|
239
|
-
hash = await sendTransaction(config, {
|
|
240
|
-
to: vault.orderbook.id,
|
|
241
|
-
data: transactionCalldata
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
catch {
|
|
245
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
246
|
-
}
|
|
247
|
-
try {
|
|
248
|
-
awaitTx(hash, action === 'deposit'
|
|
249
|
-
? TransactionStatus.PENDING_DEPOSIT
|
|
250
|
-
: TransactionStatus.PENDING_WITHDRAWAL);
|
|
251
|
-
await waitForTransactionReceipt(config, { hash });
|
|
252
|
-
return awaitTransactionIndexing(subgraphUrl, hash, `The ${action === 'deposit' ? 'deposit' : 'withdrawal'} was successful.`);
|
|
253
|
-
}
|
|
254
|
-
catch {
|
|
255
|
-
return transactionError(action === 'deposit'
|
|
256
|
-
? TransactionErrorMessage.DEPOSIT_FAILED
|
|
257
|
-
: TransactionErrorMessage.WITHDRAWAL_FAILED);
|
|
258
|
-
}
|
|
259
|
-
};
|
|
260
|
-
const handleRemoveOrderTransaction = async ({ config, orderbookAddress, removeOrderCalldata, chainId, subgraphUrl }) => {
|
|
261
|
-
try {
|
|
262
|
-
await switchChain(config, { chainId });
|
|
263
|
-
}
|
|
264
|
-
catch {
|
|
265
|
-
return transactionError(TransactionErrorMessage.SWITCH_CHAIN_FAILED);
|
|
266
|
-
}
|
|
267
|
-
let hash;
|
|
268
|
-
try {
|
|
269
|
-
awaitWalletConfirmation('Please confirm order removal in your wallet...');
|
|
270
|
-
hash = await sendTransaction(config, {
|
|
271
|
-
to: orderbookAddress,
|
|
272
|
-
data: removeOrderCalldata
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
catch {
|
|
276
|
-
return transactionError(TransactionErrorMessage.USER_REJECTED_TRANSACTION);
|
|
277
|
-
}
|
|
278
|
-
try {
|
|
279
|
-
awaitTx(hash, TransactionStatus.PENDING_REMOVE_ORDER);
|
|
280
|
-
await waitForTransactionReceipt(config, { hash });
|
|
281
|
-
return awaitRemoveOrderIndexing(subgraphUrl, hash);
|
|
282
|
-
}
|
|
283
|
-
catch {
|
|
284
|
-
return transactionError(TransactionErrorMessage.REMOVE_ORDER_FAILED);
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
return {
|
|
288
|
-
subscribe,
|
|
289
|
-
reset,
|
|
290
|
-
handleDeploymentTransaction,
|
|
291
|
-
handleDepositOrWithdrawTransaction,
|
|
292
|
-
handleRemoveOrderTransaction,
|
|
293
|
-
checkingWalletAllowance,
|
|
294
|
-
awaitWalletConfirmation,
|
|
295
|
-
awaitApprovalTx,
|
|
296
|
-
transactionSuccess,
|
|
297
|
-
transactionError,
|
|
298
|
-
awaitTransactionIndexing,
|
|
299
|
-
awaitNewOrderIndexing,
|
|
300
|
-
awaitRemoveOrderIndexing
|
|
301
|
-
};
|
|
302
|
-
};
|
|
303
|
-
export default transactionStore();
|
package/dist/utils/time.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { UTCTimestamp } from 'lightweight-charts';
|
|
2
|
-
export declare function formatTimestampSecondsAsLocal(timestampSeconds: bigint): string;
|
|
3
|
-
export declare function timestampSecondsToUTCTimestamp(timestampSeconds: bigint): UTCTimestamp;
|
|
4
|
-
/**
|
|
5
|
-
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
6
|
-
* @param promise - The original promise
|
|
7
|
-
* @param time - The time in ms
|
|
8
|
-
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
9
|
-
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
10
|
-
* if the time runs out before the main promise settlement
|
|
11
|
-
*/
|
|
12
|
-
export declare function promiseTimeout<T>(promise: Promise<T>, time: number, exception: unknown): Promise<T>;
|
package/dist/utils/time.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import dayjs from 'dayjs';
|
|
2
|
-
import bigIntSupport from 'dayjs/plugin/bigIntSupport';
|
|
3
|
-
import localizedFormat from 'dayjs/plugin/localizedFormat';
|
|
4
|
-
dayjs.extend(bigIntSupport);
|
|
5
|
-
dayjs.extend(localizedFormat);
|
|
6
|
-
export function formatTimestampSecondsAsLocal(timestampSeconds) {
|
|
7
|
-
return dayjs(timestampSeconds * BigInt('1000')).format('L LT');
|
|
8
|
-
}
|
|
9
|
-
export function timestampSecondsToUTCTimestamp(timestampSeconds) {
|
|
10
|
-
return dayjs(timestampSeconds * BigInt('1000')).unix();
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Method to put a timeout on a promise, throws the exception if promise is not settled within the time
|
|
14
|
-
* @param promise - The original promise
|
|
15
|
-
* @param time - The time in ms
|
|
16
|
-
* @param exception - The exception to reject with if time runs out before original promise settlement
|
|
17
|
-
* @returns A new promise that gets settled with initial promise settlement or rejected with exception value
|
|
18
|
-
* if the time runs out before the main promise settlement
|
|
19
|
-
*/
|
|
20
|
-
export async function promiseTimeout(promise, time, exception) {
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
let timeout;
|
|
23
|
-
return Promise.race([
|
|
24
|
-
promise,
|
|
25
|
-
new Promise((_resolve, reject) => (timeout = setTimeout(reject, time, exception)))
|
|
26
|
-
]).finally(() => clearTimeout(timeout));
|
|
27
|
-
}
|
package/dist/utils/vault.d.ts
DELETED
package/dist/utils/vault.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { formatUnits } from 'viem';
|
|
2
|
-
export const vaultBalanceDisplay = (vault) => {
|
|
3
|
-
return formatUnits(BigInt(vault.balance), +(vault.token?.decimals || 0));
|
|
4
|
-
};
|
|
5
|
-
if (import.meta.vitest) {
|
|
6
|
-
const { it, expect } = import.meta.vitest;
|
|
7
|
-
it('formats the vault balance correctly', () => {
|
|
8
|
-
const vault = {
|
|
9
|
-
id: '1',
|
|
10
|
-
balance: '1000000000000000000',
|
|
11
|
-
token: {
|
|
12
|
-
id: '1',
|
|
13
|
-
decimals: '18',
|
|
14
|
-
address: '0x00'
|
|
15
|
-
},
|
|
16
|
-
vaultId: '1',
|
|
17
|
-
owner: '0x00',
|
|
18
|
-
ordersAsInput: [],
|
|
19
|
-
ordersAsOutput: [],
|
|
20
|
-
balanceChanges: [],
|
|
21
|
-
orderbook: {
|
|
22
|
-
id: '0x00'
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
expect(vaultBalanceDisplay(vault)).toEqual('1');
|
|
26
|
-
vault.token.decimals = '6';
|
|
27
|
-
expect(vaultBalanceDisplay(vault)).toEqual('1000000000000');
|
|
28
|
-
});
|
|
29
|
-
}
|
|
File without changes
|