@rango-dev/widget-embedded 0.30.1-next.13 → 0.30.1-next.14

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rango-dev/widget-embedded",
3
- "version": "0.30.1-next.13",
3
+ "version": "0.30.1-next.14",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "source": "./src/index.ts",
@@ -4,6 +4,7 @@ import { useManager } from '@rango-dev/queue-manager-react';
4
4
  import React, { createContext, useContext } from 'react';
5
5
 
6
6
  import { useLanguage } from '../../hooks/useLanguage';
7
+ import { useUpdateQuoteInput } from '../../hooks/useUpdateQuoteInput/useUpdateQuoteInput';
7
8
  import { useAppStore } from '../../store/AppStore';
8
9
  import { useNotificationStore } from '../../store/notification';
9
10
  import { useQuoteStore } from '../../store/quote';
@@ -35,6 +36,7 @@ export function WidgetInfo(props: React.PropsWithChildren) {
35
36
  const resetLanguage = useLanguage().resetLanguage;
36
37
  const notifications = useNotificationStore().getNotifications();
37
38
  const clearNotifications = useNotificationStore().clearNotifications;
39
+ const updateQuoteInput = useUpdateQuoteInput();
38
40
 
39
41
  // eslint-disable-next-line react/jsx-no-constructed-context-values
40
42
  const value: WidgetInfoContextInterface = {
@@ -59,6 +61,9 @@ export function WidgetInfo(props: React.PropsWithChildren) {
59
61
  list: notifications,
60
62
  clearAll: clearNotifications,
61
63
  },
64
+ quote: {
65
+ updateQuoteInput,
66
+ },
62
67
  };
63
68
 
64
69
  return (
@@ -1,7 +1,7 @@
1
1
  import type { WidgetHistory } from './WidgetInfo.helpers';
2
2
  import type { FetchStatus, FindToken } from '../../store/slices/data';
3
3
  import type { ConnectedWallet } from '../../store/wallets';
4
- import type { Wallet } from '../../types';
4
+ import type { UpdateQuoteInput, Wallet } from '../../types';
5
5
  import type { Notification } from '../../types/notification';
6
6
  import type { BlockchainMeta, SwapperMeta, Token } from 'rango-sdk';
7
7
 
@@ -27,4 +27,7 @@ export interface WidgetInfoContextInterface {
27
27
  list: Notification[];
28
28
  clearAll: () => void;
29
29
  };
30
+ quote: {
31
+ updateQuoteInput: UpdateQuoteInput;
32
+ };
30
33
  }
@@ -0,0 +1 @@
1
+ export { useUpdateQuoteInput } from './useUpdateQuoteInput';
@@ -0,0 +1,50 @@
1
+ import type { UpdateQuoteInput } from '../../types';
2
+
3
+ import { useAppStore } from '../../store/AppStore';
4
+ import { useQuoteStore } from '../../store/quote';
5
+
6
+ // This hook provides a function to update quote inputs using fewer and simpler parameters.
7
+ export function useUpdateQuoteInput() {
8
+ const { findToken } = useAppStore();
9
+ const blockchains = useAppStore().blockchains();
10
+ const tokens = useAppStore().tokens();
11
+ const {
12
+ setFromBlockchain,
13
+ setFromToken,
14
+ setToBlockchain,
15
+ setToToken,
16
+ setInputAmount,
17
+ } = useQuoteStore();
18
+
19
+ const updateQuoteInput: UpdateQuoteInput = (params) => {
20
+ const { fromBlockchain, fromToken, toBlockchain, toToken, requestAmount } =
21
+ params;
22
+ const meta = { blockchains, tokens };
23
+
24
+ if (fromBlockchain !== undefined) {
25
+ const blockchainMeta =
26
+ blockchains.find((blockchain) => blockchain.name === fromBlockchain) ??
27
+ null;
28
+ setFromBlockchain(blockchainMeta);
29
+ }
30
+ if (fromToken !== undefined) {
31
+ const token = fromToken ? findToken(fromToken) ?? null : null;
32
+ setFromToken({ meta, token });
33
+ }
34
+ if (toBlockchain !== undefined) {
35
+ const blockchainMeta =
36
+ blockchains.find((blockchain) => blockchain.name === toBlockchain) ??
37
+ null;
38
+ setToBlockchain(blockchainMeta);
39
+ }
40
+ if (toToken !== undefined) {
41
+ const token = toToken ? findToken(toToken) ?? null : null;
42
+ setToToken({ meta, token });
43
+ }
44
+ if (requestAmount !== undefined) {
45
+ setInputAmount(requestAmount);
46
+ }
47
+ };
48
+
49
+ return updateQuoteInput;
50
+ }
@@ -3,6 +3,7 @@
3
3
  import type { PriceImpactWarningLevel } from '@rango-dev/ui';
4
4
  import type BigNumber from 'bignumber.js';
5
5
  import type {
6
+ Asset,
6
7
  BlockchainValidationStatus,
7
8
  RouteTag,
8
9
  RoutingResultType,
@@ -131,3 +132,11 @@ export type QuoteErrorResponse = {
131
132
  message: string;
132
133
  options: QuoteError;
133
134
  };
135
+
136
+ export type UpdateQuoteInput = (params: {
137
+ fromBlockchain?: string | null;
138
+ toBlockchain?: string | null;
139
+ fromToken?: Asset | null;
140
+ toToken?: Asset | null;
141
+ requestAmount?: string;
142
+ }) => void;