@rainlanguage/ui-components 0.0.1-alpha.151 → 0.0.1-alpha.152
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 +70 -6
- package/dist/components/deployment/SelectToken.svelte +7 -3
- package/dist/components/deployment/SelectToken.svelte.d.ts +3 -1
- package/dist/components/deployment/TokenBalance.svelte +19 -0
- package/dist/components/deployment/TokenBalance.svelte.d.ts +19 -0
- package/dist/components/deployment/TokenIOInput.svelte +11 -5
- package/dist/components/deployment/TokenIOInput.svelte.d.ts +2 -0
- package/dist/components/deployment/VaultIdInformation.svelte +17 -0
- package/dist/components/deployment/VaultIdInformation.svelte.d.ts +21 -0
- package/dist/types/tokenBalance.d.ts +6 -0
- package/dist/types/tokenBalance.js +1 -0
- package/package.json +2 -2
|
@@ -3,13 +3,14 @@ import TokenIOInput from "./TokenIOInput.svelte";
|
|
|
3
3
|
import ComposedRainlangModal from "./ComposedRainlangModal.svelte";
|
|
4
4
|
import {
|
|
5
5
|
DotrainOrderGui,
|
|
6
|
-
RaindexClient
|
|
6
|
+
RaindexClient,
|
|
7
|
+
AccountBalance
|
|
7
8
|
} from "@rainlanguage/orderbook";
|
|
8
9
|
import WalletConnect from "../wallet/WalletConnect.svelte";
|
|
9
10
|
import {} from "svelte/store";
|
|
10
11
|
import { handleShareChoices } from "../../services/handleShareChoices";
|
|
11
12
|
import { DeploymentStepsError, DeploymentStepsErrorCode } from "../../errors";
|
|
12
|
-
import { onMount } from "svelte";
|
|
13
|
+
import { onDestroy, onMount } from "svelte";
|
|
13
14
|
import FieldDefinitionInput from "./FieldDefinitionInput.svelte";
|
|
14
15
|
import DepositInput from "./DepositInput.svelte";
|
|
15
16
|
import SelectToken from "./SelectToken.svelte";
|
|
@@ -37,6 +38,7 @@ let selectTokens = void 0;
|
|
|
37
38
|
let checkingDeployment = false;
|
|
38
39
|
let availableTokens = [];
|
|
39
40
|
let loadingTokens = false;
|
|
41
|
+
let tokenBalances = /* @__PURE__ */ new Map();
|
|
40
42
|
const gui = useGui();
|
|
41
43
|
const registry = useRegistry();
|
|
42
44
|
const raindexClient = useRaindexClient();
|
|
@@ -53,6 +55,22 @@ onMount(async () => {
|
|
|
53
55
|
$: if (selectTokens?.length === 0 || allTokensSelected) {
|
|
54
56
|
updateFields();
|
|
55
57
|
}
|
|
58
|
+
let unsubscribeAccount = account.subscribe((account2) => {
|
|
59
|
+
if (!account2) {
|
|
60
|
+
const balances = tokenBalances;
|
|
61
|
+
balances.clear();
|
|
62
|
+
tokenBalances = balances;
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (selectTokens) {
|
|
66
|
+
selectTokens.forEach(async (selectToken) => {
|
|
67
|
+
await getTokenInfoAndFetchBalance(selectToken.key);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
onDestroy(() => {
|
|
72
|
+
unsubscribeAccount();
|
|
73
|
+
});
|
|
56
74
|
async function loadAvailableTokens() {
|
|
57
75
|
if (loadingTokens) return;
|
|
58
76
|
loadingTokens = true;
|
|
@@ -95,8 +113,48 @@ function updateFields() {
|
|
|
95
113
|
async function _handleShareChoices() {
|
|
96
114
|
await handleShareChoices(gui, registry.getCurrentRegistry());
|
|
97
115
|
}
|
|
98
|
-
async function
|
|
116
|
+
async function fetchTokenBalance(tokenInfo) {
|
|
117
|
+
if (!$account) return;
|
|
118
|
+
const balances = tokenBalances;
|
|
119
|
+
balances.set(tokenInfo.key, {
|
|
120
|
+
value: { balance: BigInt(0), formattedBalance: "0" },
|
|
121
|
+
loading: true,
|
|
122
|
+
error: ""
|
|
123
|
+
});
|
|
124
|
+
const { value: accountBalance, error } = await gui.getAccountBalance(
|
|
125
|
+
tokenInfo.address,
|
|
126
|
+
$account
|
|
127
|
+
);
|
|
128
|
+
if (error) {
|
|
129
|
+
balances.set(tokenInfo.key, {
|
|
130
|
+
value: { balance: BigInt(0), formattedBalance: "0" },
|
|
131
|
+
loading: false,
|
|
132
|
+
error: error.readableMsg
|
|
133
|
+
});
|
|
134
|
+
tokenBalances = balances;
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
balances.set(tokenInfo.key, {
|
|
138
|
+
value: accountBalance,
|
|
139
|
+
loading: false,
|
|
140
|
+
error: ""
|
|
141
|
+
});
|
|
142
|
+
tokenBalances = balances;
|
|
143
|
+
}
|
|
144
|
+
async function getTokenInfoAndFetchBalance(key) {
|
|
145
|
+
const tokenInfoResult = await gui.getTokenInfo(key);
|
|
146
|
+
if (tokenInfoResult.error) {
|
|
147
|
+
throw new Error(tokenInfoResult.error.msg);
|
|
148
|
+
}
|
|
149
|
+
const tokenInfo = tokenInfoResult.value;
|
|
150
|
+
if (!tokenInfo || !tokenInfo.address) {
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
await fetchTokenBalance(tokenInfo);
|
|
154
|
+
}
|
|
155
|
+
async function onSelectTokenSelect(key) {
|
|
99
156
|
await areAllTokensSelected();
|
|
157
|
+
await getTokenInfoAndFetchBalance(key);
|
|
100
158
|
if (allTokensSelected) {
|
|
101
159
|
let result = await gui.getAllTokenInfos();
|
|
102
160
|
if (result.error) {
|
|
@@ -181,7 +239,13 @@ async function handleDeployButtonClick() {
|
|
|
181
239
|
description="Select the tokens that you want to use in your order."
|
|
182
240
|
/>
|
|
183
241
|
{#each selectTokens as token}
|
|
184
|
-
<SelectToken
|
|
242
|
+
<SelectToken
|
|
243
|
+
{token}
|
|
244
|
+
{onSelectTokenSelect}
|
|
245
|
+
{availableTokens}
|
|
246
|
+
loading={loadingTokens}
|
|
247
|
+
{tokenBalances}
|
|
248
|
+
/>
|
|
185
249
|
{/each}
|
|
186
250
|
</div>
|
|
187
251
|
{/if}
|
|
@@ -205,11 +269,11 @@ async function handleDeployButtonClick() {
|
|
|
205
269
|
{/each}
|
|
206
270
|
|
|
207
271
|
{#each allTokenOutputs as output}
|
|
208
|
-
<TokenIOInput label="Output" vault={output} />
|
|
272
|
+
<TokenIOInput label="Output" vault={output} {tokenBalances} />
|
|
209
273
|
{/each}
|
|
210
274
|
|
|
211
275
|
{#each allTokenInputs as input}
|
|
212
|
-
<TokenIOInput label="Input" vault={input} />
|
|
276
|
+
<TokenIOInput label="Input" vault={input} {tokenBalances} />
|
|
213
277
|
{/each}
|
|
214
278
|
{/if}
|
|
215
279
|
|
|
@@ -5,10 +5,12 @@ import { onMount } from "svelte";
|
|
|
5
5
|
import { useGui } from "../../hooks/useGui";
|
|
6
6
|
import ButtonSelectOption from "./ButtonSelectOption.svelte";
|
|
7
7
|
import TokenSelectionModal from "./TokenSelectionModal.svelte";
|
|
8
|
+
import TokenBalanceComponent from "./TokenBalance.svelte";
|
|
8
9
|
export let token;
|
|
9
10
|
export let onSelectTokenSelect;
|
|
10
11
|
export let availableTokens = [];
|
|
11
12
|
export let loading = false;
|
|
13
|
+
export let tokenBalances = /* @__PURE__ */ new Map();
|
|
12
14
|
let inputValue = null;
|
|
13
15
|
let tokenInfo = null;
|
|
14
16
|
let error = "";
|
|
@@ -24,8 +26,9 @@ onMount(async () => {
|
|
|
24
26
|
throw new Error(result.error.msg);
|
|
25
27
|
}
|
|
26
28
|
tokenInfo = result.value;
|
|
27
|
-
if (result.value
|
|
29
|
+
if (result.value.address) {
|
|
28
30
|
inputValue = result.value.address;
|
|
31
|
+
onSelectTokenSelect(token.key);
|
|
29
32
|
}
|
|
30
33
|
} catch {
|
|
31
34
|
}
|
|
@@ -93,12 +96,12 @@ async function saveTokenSelection(address) {
|
|
|
93
96
|
error = errorMessage;
|
|
94
97
|
} finally {
|
|
95
98
|
checking = false;
|
|
96
|
-
onSelectTokenSelect();
|
|
99
|
+
onSelectTokenSelect(token.key);
|
|
97
100
|
}
|
|
98
101
|
}
|
|
99
102
|
function clearTokenSelection() {
|
|
100
103
|
gui.unsetSelectToken(token.key);
|
|
101
|
-
onSelectTokenSelect();
|
|
104
|
+
onSelectTokenSelect(token.key);
|
|
102
105
|
}
|
|
103
106
|
async function getInfoForSelectedToken() {
|
|
104
107
|
error = "";
|
|
@@ -207,6 +210,7 @@ async function handleInput(event) {
|
|
|
207
210
|
>
|
|
208
211
|
<CheckCircleSolid class="h-5 w-5" color="green" />
|
|
209
212
|
<span>{tokenInfo.name}</span>
|
|
213
|
+
<TokenBalanceComponent tokenBalance={tokenBalances.get(token.key)} />
|
|
210
214
|
</div>
|
|
211
215
|
{:else if error}
|
|
212
216
|
<div class="flex h-5 flex-row items-center gap-2" data-testid="error">
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import type { GuiSelectTokensCfg, TokenInfo } from '@rainlanguage/orderbook';
|
|
3
|
+
import type { TokenBalance } from '../../types/tokenBalance';
|
|
3
4
|
declare const __propDef: {
|
|
4
5
|
props: {
|
|
5
6
|
token: GuiSelectTokensCfg;
|
|
6
|
-
onSelectTokenSelect: () => void;
|
|
7
|
+
onSelectTokenSelect: (key: string) => void;
|
|
7
8
|
availableTokens?: TokenInfo[];
|
|
8
9
|
loading?: boolean;
|
|
10
|
+
tokenBalances?: Map<string, TokenBalance>;
|
|
9
11
|
};
|
|
10
12
|
events: {
|
|
11
13
|
[evt: string]: CustomEvent<any>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script>import { Spinner } from "flowbite-svelte";
|
|
2
|
+
export let tokenBalance;
|
|
3
|
+
</script>
|
|
4
|
+
|
|
5
|
+
{#if tokenBalance}
|
|
6
|
+
{#if tokenBalance.loading}
|
|
7
|
+
<div class="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400">
|
|
8
|
+
<Spinner class="h-4 w-4" />
|
|
9
|
+
</div>
|
|
10
|
+
{:else if !tokenBalance.error}
|
|
11
|
+
<div class="text-sm text-gray-600 dark:text-gray-400">
|
|
12
|
+
Balance: {tokenBalance.value.formattedBalance}
|
|
13
|
+
</div>
|
|
14
|
+
{:else if tokenBalance.error}
|
|
15
|
+
<div class="text-sm text-red-600 dark:text-red-400">
|
|
16
|
+
{tokenBalance.error}
|
|
17
|
+
</div>
|
|
18
|
+
{/if}
|
|
19
|
+
{/if}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { TokenBalance } from '../../types/tokenBalance';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
tokenBalance: TokenBalance | undefined;
|
|
6
|
+
};
|
|
7
|
+
events: {
|
|
8
|
+
[evt: string]: CustomEvent<any>;
|
|
9
|
+
};
|
|
10
|
+
slots: {};
|
|
11
|
+
exports?: {} | undefined;
|
|
12
|
+
bindings?: string | undefined;
|
|
13
|
+
};
|
|
14
|
+
export type TokenBalanceProps = typeof __propDef.props;
|
|
15
|
+
export type TokenBalanceEvents = typeof __propDef.events;
|
|
16
|
+
export type TokenBalanceSlots = typeof __propDef.slots;
|
|
17
|
+
export default class TokenBalance extends SvelteComponent<TokenBalanceProps, TokenBalanceEvents, TokenBalanceSlots> {
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script>import { Input } from "flowbite-svelte";
|
|
2
2
|
import {} from "@rainlanguage/orderbook";
|
|
3
|
-
import DeploymentSectionHeader from "./DeploymentSectionHeader.svelte";
|
|
4
3
|
import { onMount } from "svelte";
|
|
5
4
|
import { useGui } from "../../hooks/useGui";
|
|
5
|
+
import VaultIdInformation from "./VaultIdInformation.svelte";
|
|
6
6
|
const gui = useGui();
|
|
7
7
|
export let label;
|
|
8
8
|
export let vault;
|
|
9
|
+
export let tokenBalances = /* @__PURE__ */ new Map();
|
|
9
10
|
let tokenInfo = null;
|
|
10
11
|
let inputValue = "";
|
|
11
12
|
let error = "";
|
|
@@ -56,10 +57,15 @@ $: if (vault.token?.key) {
|
|
|
56
57
|
</script>
|
|
57
58
|
|
|
58
59
|
<div class="flex w-full flex-col gap-6">
|
|
59
|
-
<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
60
|
+
<div class="flex w-full flex-col gap-2">
|
|
61
|
+
<div class="flex items-center gap-2">
|
|
62
|
+
<VaultIdInformation
|
|
63
|
+
title={`${label} ${tokenInfo?.symbol ? `(${tokenInfo.symbol})` : ''}`}
|
|
64
|
+
description={`${tokenInfo?.symbol || 'Token'} vault ID`}
|
|
65
|
+
tokenBalance={tokenBalances.get(vault.token?.key || '')}
|
|
66
|
+
/>
|
|
67
|
+
</div>
|
|
68
|
+
</div>
|
|
63
69
|
<div class="flex flex-col gap-2">
|
|
64
70
|
<Input
|
|
65
71
|
data-testid="vault-id-input"
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import { type OrderIOCfg } from '@rainlanguage/orderbook';
|
|
3
|
+
import type { TokenBalance } from '../../types/tokenBalance';
|
|
3
4
|
declare const __propDef: {
|
|
4
5
|
props: {
|
|
5
6
|
label: "Input" | "Output";
|
|
6
7
|
vault: OrderIOCfg;
|
|
8
|
+
tokenBalances?: Map<string, TokenBalance>;
|
|
7
9
|
};
|
|
8
10
|
events: {
|
|
9
11
|
[evt: string]: CustomEvent<any>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script>import TokenBalanceComponent from "./TokenBalance.svelte";
|
|
2
|
+
export let title;
|
|
3
|
+
export let description;
|
|
4
|
+
export let tokenBalance;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
<div class="flex max-w-xl flex-grow flex-col gap-y-4 text-left">
|
|
8
|
+
<h1 class="break-words text-xl font-semibold text-gray-900 lg:text-2xl dark:text-white">
|
|
9
|
+
{title}
|
|
10
|
+
</h1>
|
|
11
|
+
<div class="flex items-center gap-2 text-sm text-gray-600 dark:text-gray-400">
|
|
12
|
+
<div class="text-gray-600 dark:text-gray-400">
|
|
13
|
+
{description}
|
|
14
|
+
</div>
|
|
15
|
+
<TokenBalanceComponent {tokenBalance} />
|
|
16
|
+
</div>
|
|
17
|
+
</div>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { TokenBalance } from '../../types/tokenBalance';
|
|
3
|
+
declare const __propDef: {
|
|
4
|
+
props: {
|
|
5
|
+
title: string;
|
|
6
|
+
description: string;
|
|
7
|
+
tokenBalance: TokenBalance | undefined;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {};
|
|
13
|
+
exports?: {} | undefined;
|
|
14
|
+
bindings?: string | undefined;
|
|
15
|
+
};
|
|
16
|
+
export type VaultIdInformationProps = typeof __propDef.props;
|
|
17
|
+
export type VaultIdInformationEvents = typeof __propDef.events;
|
|
18
|
+
export type VaultIdInformationSlots = typeof __propDef.slots;
|
|
19
|
+
export default class VaultIdInformation extends SvelteComponent<VaultIdInformationProps, VaultIdInformationEvents, VaultIdInformationSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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.152",
|
|
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.152",
|
|
57
57
|
"@reown/appkit": "1.6.4",
|
|
58
58
|
"@reown/appkit-adapter-wagmi": "1.6.4",
|
|
59
59
|
"@sentry/sveltekit": "7.120.0",
|