@skip-go/widget 2.3.8 → 2.4.0

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/README.md CHANGED
@@ -134,6 +134,33 @@ interface SwapWidgetProps {
134
134
  highlightColor: string; // color used when hovering over buttons, and in select chain/asset dropdown
135
135
  };
136
136
  persistSwapWidgetState?: boolean; // whether or not swap widget state should persist after refresh. Defaults to true
137
+
138
+ // Pass in callback functions to handle events in the widget.
139
+ onWalletConnected?: ({
140
+ walletName: string,
141
+ chainId: string,
142
+ address?: string,
143
+ }) => void;
144
+
145
+ onWalletDisconnected?: ({
146
+ chainType?: string
147
+ }) => void;
148
+
149
+ onTransactionBroadcasted?: ({
150
+ txHash: string,
151
+ chainId: string,
152
+ explorerLink: string,
153
+ }) => void;
154
+
155
+ onTransactionComplete?: ({
156
+ txHash: string,
157
+ chainId: string,
158
+ explorerLink: string,
159
+ }) => void;
160
+
161
+ onTransactionFailed?: ({
162
+ error: string;
163
+ }) => void;
137
164
  }
138
165
  ````
139
166
 
@@ -166,8 +193,8 @@ are passed to the web-component via attributes in kebab-case as strings or strin
166
193
  <SwapWidget
167
194
  className="test-class"
168
195
  onlyTestnet={true}
169
- colors={{
170
- primary: '#FF4FFF',
196
+ theme={{
197
+ brandColor: '#FF4FFF',
171
198
  }}
172
199
  defaultRoute={{
173
200
  srcChainID: 'osmosis-1',
@@ -185,7 +212,7 @@ becomes
185
212
  <swap-widget
186
213
  class-name="test-class"
187
214
  onlyTestnet="true"
188
- colors='{"primary":"#FF4FFF"}'
215
+ theme='{"brandColor":"#FF4FFF"}'
189
216
  default-route={JSON.stringify({
190
217
  srcChainID: 'osmosis-1',
191
218
  srcAssetDenom:
@@ -1,4 +1,4 @@
1
1
  import { AssetsRequest } from '@skip-go/client';
2
2
  export declare function useAssets(options?: AssetsRequest): import("@tanstack/react-query/build/legacy/types").UseQueryResult<{
3
- [k: string]: import("@skip-go/client/dist/shared-CvoSvr3u").a[];
3
+ [k: string]: import("@skip-go/client/dist/shared-CpfDn0H3").b[];
4
4
  }, Error>;
@@ -16,5 +16,5 @@ interface UseRouteArgs extends RouteConfig {
16
16
  destinationAssetChainID?: string;
17
17
  enabled?: boolean;
18
18
  }
19
- export declare function useRoute({ direction, amount, sourceAsset, sourceAssetChainID, destinationAsset, destinationAssetChainID, enabled, swapVenues, bridges, experimentalFeatures, allowMultiTx, allowUnsafe, smartSwapOptions, }: UseRouteArgs): import("@tanstack/react-query/build/legacy/types").UseQueryResult<import("@skip-go/client/dist/shared-CvoSvr3u").R | undefined, Error>;
19
+ export declare function useRoute({ direction, amount, sourceAsset, sourceAssetChainID, destinationAsset, destinationAssetChainID, enabled, swapVenues, bridges, experimentalFeatures, allowMultiTx, allowUnsafe, smartSwapOptions, }: UseRouteArgs): import("@tanstack/react-query/build/legacy/types").UseQueryResult<import("@skip-go/client/dist/shared-CpfDn0H3").R | undefined, Error>;
20
20
  export {};
@@ -31,7 +31,7 @@ export declare function useSwapWidget(persistSwapWidgetState?: boolean): {
31
31
  onSourceAssetChange: (asset: Asset) => void;
32
32
  onSourceChainChange: (chain: Chain, injectAsset?: Asset) => Promise<void>;
33
33
  priceImpactThresholdReached: boolean;
34
- route: import("@skip-go/client/dist/shared-CvoSvr3u").R | undefined;
34
+ route: import("@skip-go/client/dist/shared-CpfDn0H3").R | undefined;
35
35
  routeError: string;
36
36
  routeLoading: boolean;
37
37
  routeWarningMessage: string | undefined;
package/build/index.es.js CHANGED
@@ -210,12 +210,12 @@ const SolanaProvider = ({ children }) => {
210
210
  return (jsx(WalletProvider$1, { wallets: solanaWallets, localStorageKey: "ibc-fun-solana-wallet", autoConnect: true, children: children }, "skip-widget-solana-wallet"));
211
211
  };
212
212
 
213
- const defaultValues$4 = {
213
+ const defaultValues$5 = {
214
214
  evm: undefined,
215
215
  cosmos: undefined,
216
216
  svm: undefined,
217
217
  };
218
- const useStore$1 = create(subscribeWithSelector(persist(() => defaultValues$4, {
218
+ const useStore$1 = create(subscribeWithSelector(persist(() => defaultValues$5, {
219
219
  name: 'TrackWalletState',
220
220
  version: 2,
221
221
  storage: createJSONStorage(() => window.sessionStorage),
@@ -308,10 +308,11 @@ function isReadyToCheckLedger(walletClient) {
308
308
  }
309
309
 
310
310
  const SkipContext = createContext(undefined);
311
- function SkipProvider({ children, apiURL, endpointOptions, makeDestinationWallets, }) {
311
+ function SkipProvider({ children, apiURL, endpointOptions, makeDestinationWallets, chainIDsToAffiliates, }) {
312
312
  const { getWalletRepo } = useManager();
313
313
  const { wallets } = useWallet();
314
314
  const skipClient = new SkipRouter({
315
+ chainIDsToAffiliates,
315
316
  getCosmosSigner: async (chainID) => {
316
317
  var _a, _b;
317
318
  const chainName = chainIdToName(chainID);
@@ -429,11 +430,11 @@ function isChainIdEvmos(chainID) {
429
430
  return chainID === 'evmos_9001-2' || chainID.includes('evmos');
430
431
  }
431
432
 
432
- const defaultValues$3 = {
433
+ const defaultValues$4 = {
433
434
  customGasAmount: DEFAULT_GAS_AMOUNT,
434
435
  slippage: (3).toString(),
435
436
  };
436
- const useSettingsStore = create()(persist(() => defaultValues$3, {
437
+ const useSettingsStore = create()(persist(() => defaultValues$4, {
437
438
  name: 'SettingsState',
438
439
  version: 4,
439
440
  }));
@@ -720,8 +721,12 @@ const PenumbraWalletListItem = ({ children, walletName, ...props }) => {
720
721
  return jsx("div", { ...props, children: children });
721
722
  };
722
723
 
724
+ const defaultValues$3 = {};
725
+ const useCallbackStore = create()(() => defaultValues$3);
726
+
723
727
  const useMakeWallets = () => {
724
728
  const { data: chains } = useChains();
729
+ const { onWalletConnected, onWalletDisconnected } = useCallbackStore.getState();
725
730
  const getChain = (_chainID) => chains === null || chains === void 0 ? void 0 : chains.find((chain) => chain.chainID === _chainID);
726
731
  const { connector: currentConnector, address: evmAddress, isConnected: isEvmConnected, } = useAccount$1();
727
732
  const { disconnectAsync } = useDisconnect();
@@ -754,6 +759,11 @@ const useMakeWallets = () => {
754
759
  try {
755
760
  await gracefullyConnect(wallet);
756
761
  trackWallet.track('cosmos', wallet.walletName, chainType);
762
+ onWalletConnected === null || onWalletConnected === void 0 ? void 0 : onWalletConnected({
763
+ walletName: wallet.walletPrettyName,
764
+ chainId: chainID,
765
+ address: wallet.address,
766
+ });
757
767
  }
758
768
  catch (error) {
759
769
  console.error(error);
@@ -794,6 +804,7 @@ const useMakeWallets = () => {
794
804
  disconnect: async () => {
795
805
  await wallet.disconnect();
796
806
  trackWallet.untrack('cosmos');
807
+ onWalletDisconnected === null || onWalletDisconnected === void 0 ? void 0 : onWalletDisconnected({ chainType });
797
808
  },
798
809
  isWalletConnected: wallet.isWalletConnected,
799
810
  }));
@@ -816,6 +827,11 @@ const useMakeWallets = () => {
816
827
  try {
817
828
  await connectAsync({ connector, chainId: Number(chainID) });
818
829
  trackWallet.track('evm', connector.id, chainType);
830
+ onWalletConnected === null || onWalletConnected === void 0 ? void 0 : onWalletConnected({
831
+ walletName: connector.name,
832
+ chainId: chainID,
833
+ address: evmAddress,
834
+ });
819
835
  }
820
836
  catch (error) {
821
837
  console.error(error);
@@ -853,6 +869,7 @@ const useMakeWallets = () => {
853
869
  disconnect: async () => {
854
870
  await disconnectAsync();
855
871
  trackWallet.untrack('evm');
872
+ onWalletDisconnected === null || onWalletDisconnected === void 0 ? void 0 : onWalletDisconnected({ chainType });
856
873
  },
857
874
  isWalletConnected: connector.id === (currentConnector === null || currentConnector === void 0 ? void 0 : currentConnector.id),
858
875
  };
@@ -868,9 +885,15 @@ const useMakeWallets = () => {
868
885
  logo: wallet.adapter.icon,
869
886
  },
870
887
  connect: async () => {
888
+ var _a;
871
889
  try {
872
890
  await wallet.adapter.connect();
873
891
  trackWallet.track('svm', wallet.adapter.name, chainType);
892
+ onWalletConnected === null || onWalletConnected === void 0 ? void 0 : onWalletConnected({
893
+ walletName: wallet.adapter.name,
894
+ chainId: chainID,
895
+ address: (_a = wallet.adapter.publicKey) === null || _a === void 0 ? void 0 : _a.toBase58(),
896
+ });
874
897
  }
875
898
  catch (error) {
876
899
  console.error(error);
@@ -903,6 +926,7 @@ const useMakeWallets = () => {
903
926
  disconnect: async () => {
904
927
  await wallet.adapter.disconnect();
905
928
  trackWallet.untrack('svm');
929
+ onWalletDisconnected === null || onWalletDisconnected === void 0 ? void 0 : onWalletDisconnected({ chainType });
906
930
  },
907
931
  isWalletConnected: wallet.adapter.connected,
908
932
  isAvailable: wallet.readyState === 'Installed',
@@ -1095,8 +1119,8 @@ const apiURL = `${appUrl}/api/widget/skip`;
1095
1119
  const WalletProvider = ({ children }) => {
1096
1120
  return (jsx(SolanaProvider, { children: jsx(CosmosProvider, { children: jsx(EVMProvider, { children: jsx(WalletModalProvider, { children: children }) }) }) }));
1097
1121
  };
1098
- const SkipAPIProvider = ({ children, endpointOptions: endpointOptions$1 = endpointOptions, apiURL: apiURL$1 = apiURL, makeDestinationWallets, }) => {
1099
- return (jsx(SkipProvider, { apiURL: apiURL$1, endpointOptions: endpointOptions$1, makeDestinationWallets: makeDestinationWallets, children: jsx(AssetsProvider, { children: children }) }));
1122
+ const SkipAPIProvider = ({ children, endpointOptions: endpointOptions$1 = endpointOptions, apiURL: apiURL$1 = apiURL, makeDestinationWallets, chainIDsToAffiliates, }) => {
1123
+ return (jsx(SkipProvider, { apiURL: apiURL$1, endpointOptions: endpointOptions$1, makeDestinationWallets: makeDestinationWallets, chainIDsToAffiliates: chainIDsToAffiliates, children: jsx(AssetsProvider, { children: children }) }));
1100
1124
  };
1101
1125
  const SwapWidgetProvider = ({ children, ...skipApiProviderProps }) => {
1102
1126
  return (jsx(WalletProvider, { children: jsx(SkipAPIProvider, { ...skipApiProviderProps, children: children }) }));
@@ -4712,6 +4736,7 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4712
4736
  const { data: chains } = useChains();
4713
4737
  const getChain = (chainID) => chains === null || chains === void 0 ? void 0 : chains.find((chain) => chain.chainID === chainID);
4714
4738
  const { makeWallets } = useMakeWallets();
4739
+ const { onTransactionBroadcasted, onTransactionComplete, onTransactionFailed } = useCallbackStore.getState();
4715
4740
  const [isExpanded, setIsExpanded] = useState(() => route.chainIDs.length === 2 ? true : false);
4716
4741
  const [isOpen, control] = disclosure;
4717
4742
  const [indexSetAddressDialogOpen, setIndexIsSetAddressDialogOpen] = useState();
@@ -4844,6 +4869,11 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4844
4869
  explorerLink: txStatus.explorerLink,
4845
4870
  },
4846
4871
  ];
4872
+ onTransactionBroadcasted === null || onTransactionBroadcasted === void 0 ? void 0 : onTransactionBroadcasted({
4873
+ chainId: txStatus.chainID,
4874
+ txHash: txStatus.txHash,
4875
+ explorerLink: txStatus.explorerLink,
4876
+ });
4847
4877
  if (route.txsRequired === txs.length) {
4848
4878
  toast.success(jsx("p", { children: "You can safely navigate away from this page while your transaction is pending" }), {
4849
4879
  icon: (jsx(InformationCircleIcon, { className: "h-10 w-10 text-blue-500" })),
@@ -4859,6 +4889,11 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4859
4889
  if (isUserRejectedRequestError(err)) {
4860
4890
  throw new Error('User rejected request');
4861
4891
  }
4892
+ onTransactionFailed === null || onTransactionFailed === void 0 ? void 0 : onTransactionFailed({
4893
+ error: err instanceof Error
4894
+ ? `${err.name}: ${err.message}`
4895
+ : String(err)
4896
+ });
4862
4897
  throw err;
4863
4898
  }
4864
4899
  }
@@ -4870,6 +4905,11 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4870
4905
  },
4871
4906
  onError: (err) => {
4872
4907
  console.error(err);
4908
+ onTransactionFailed === null || onTransactionFailed === void 0 ? void 0 : onTransactionFailed({
4909
+ error: err instanceof Error
4910
+ ? `${err.name}: ${err.message}`
4911
+ : String(err)
4912
+ });
4873
4913
  toast(({ createdAt, id }) => (jsxs("div", { className: "flex flex-col", children: [jsx("h4", { className: "mb-2 font-bold", children: "Transaction Failed!" }), jsxs(StyledBorderDiv, { as: "pre", className: "mb-4 overflow-auto whitespace-pre-wrap break-all rounded border p-2 font-diatypeMono text-xs", children: [err instanceof Error
4874
4914
  ? `${err.name}: ${err.message}`
4875
4915
  : String(err), jsx("br", {}), jsx("br", {}), new Date(createdAt).toISOString()] }), jsx("button", { className: "self-end text-sm font-medium text-red-500 hover:underline", onClick: () => toast.dismiss(id), children: "Clear Notification \u00D7" })] })), {
@@ -4881,6 +4921,16 @@ const PreviewRoute = ({ route, disclosure, isAmountError, }) => {
4881
4921
  });
4882
4922
  },
4883
4923
  });
4924
+ useEffect(() => {
4925
+ var _a, _b, _c;
4926
+ if ((statusData === null || statusData === void 0 ? void 0 : statusData.isSuccess) && submitMutation.isSuccess) {
4927
+ onTransactionComplete === null || onTransactionComplete === void 0 ? void 0 : onTransactionComplete({
4928
+ txHash: (_a = broadcastedTxs === null || broadcastedTxs === void 0 ? void 0 : broadcastedTxs[0]) === null || _a === void 0 ? void 0 : _a.txHash,
4929
+ chainId: (_b = broadcastedTxs === null || broadcastedTxs === void 0 ? void 0 : broadcastedTxs[0]) === null || _b === void 0 ? void 0 : _b.chainID,
4930
+ explorerLink: (_c = broadcastedTxs === null || broadcastedTxs === void 0 ? void 0 : broadcastedTxs[0]) === null || _c === void 0 ? void 0 : _c.explorerLink,
4931
+ });
4932
+ }
4933
+ }, [statusData === null || statusData === void 0 ? void 0 : statusData.isSuccess, submitMutation.isSuccess]);
4884
4934
  const SubmitButton = () => {
4885
4935
  if (allAddressFilled) {
4886
4936
  return (jsx(StyledBrandDiv, { as: "button", className: cn('w-full rounded-md py-4 font-semibold text-white', 'outline-none transition-transform', 'enabled:hover:rotate-1 enabled:hover:scale-102', 'disabled:cursor-not-allowed disabled:opacity-75'), onClick: () => submitMutation.mutate(), disabled: submitMutation.isPending ||
@@ -5203,7 +5253,7 @@ const WithStyledShadowDom = ({ children }) => {
5203
5253
  return isClient ? (jsxs(Scope, { stylesheets: [css_248z, css_248z$2, css_248z$1], ref: onShadowDomLoaded, children: [jsx("div", { ref: onStyledComponentContainerLoaded }), jsx(StyleSheetManager, { target: styledComponentContainer, children: children })] })) : null;
5204
5254
  };
5205
5255
 
5206
- const SwapWidgetWithoutProviders = ({ settings, onlyTestnet, defaultRoute, routeConfig, theme, filter, ...swapWidgetUIProps }) => {
5256
+ const SwapWidgetWithoutProviders = ({ settings, onlyTestnet, defaultRoute, routeConfig, theme, filter, onWalletConnected, onWalletDisconnected, onTransactionBroadcasted, onTransactionComplete, onTransactionFailed, ...swapWidgetUIProps }) => {
5207
5257
  useEffect(() => {
5208
5258
  configureSwapWidget({
5209
5259
  onlyTestnet,
@@ -5212,7 +5262,24 @@ const SwapWidgetWithoutProviders = ({ settings, onlyTestnet, defaultRoute, route
5212
5262
  routeConfig,
5213
5263
  filter,
5214
5264
  });
5215
- }, [onlyTestnet, settings, defaultRoute, routeConfig]);
5265
+ useCallbackStore.setState({
5266
+ onWalletConnected,
5267
+ onWalletDisconnected,
5268
+ onTransactionBroadcasted,
5269
+ onTransactionComplete,
5270
+ onTransactionFailed,
5271
+ });
5272
+ }, [
5273
+ onlyTestnet,
5274
+ settings,
5275
+ defaultRoute,
5276
+ routeConfig,
5277
+ onWalletConnected,
5278
+ onWalletDisconnected,
5279
+ onTransactionBroadcasted,
5280
+ onTransactionComplete,
5281
+ onTransactionFailed,
5282
+ ]);
5216
5283
  const mergedThemes = useMemo(() => {
5217
5284
  return {
5218
5285
  ...defaultTheme,
@@ -5221,7 +5288,7 @@ const SwapWidgetWithoutProviders = ({ settings, onlyTestnet, defaultRoute, route
5221
5288
  }, [defaultTheme, theme]);
5222
5289
  return (jsx(WithStyledShadowDom, { children: jsx(ThemeProvider, { theme: mergedThemes, children: jsx(SwapWidgetUI, { ...swapWidgetUIProps }) }) }));
5223
5290
  };
5224
- const SwapWidget = ({ settings, onlyTestnet, defaultRoute, routeConfig, theme, className, style, filter, toasterProps, persistSwapWidgetState, ...swapWidgetProviderProps }) => {
5291
+ const SwapWidget = ({ settings, onlyTestnet, defaultRoute, routeConfig, theme, className, style, filter, toasterProps, persistSwapWidgetState, onWalletConnected, onWalletDisconnected, onTransactionBroadcasted, onTransactionComplete, onTransactionFailed, ...swapWidgetProviderProps }) => {
5225
5292
  useEffect(() => {
5226
5293
  configureSwapWidget({
5227
5294
  onlyTestnet,
@@ -5230,7 +5297,24 @@ const SwapWidget = ({ settings, onlyTestnet, defaultRoute, routeConfig, theme, c
5230
5297
  routeConfig,
5231
5298
  filter,
5232
5299
  });
5233
- }, [onlyTestnet, settings, defaultRoute, routeConfig]);
5300
+ useCallbackStore.setState({
5301
+ onWalletConnected,
5302
+ onWalletDisconnected,
5303
+ onTransactionBroadcasted,
5304
+ onTransactionComplete,
5305
+ onTransactionFailed,
5306
+ });
5307
+ }, [
5308
+ onlyTestnet,
5309
+ settings,
5310
+ defaultRoute,
5311
+ routeConfig,
5312
+ onWalletConnected,
5313
+ onWalletDisconnected,
5314
+ onTransactionBroadcasted,
5315
+ onTransactionComplete,
5316
+ onTransactionFailed,
5317
+ ]);
5234
5318
  const mergedThemes = useMemo(() => {
5235
5319
  return {
5236
5320
  ...defaultTheme,