@imtbl/checkout-sdk 2.0.0-alpha.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/LICENSE.md +176 -0
- package/README.md +58 -0
- package/dist/browser/index.js +6566 -0
- package/dist/node/index.cjs +6566 -0
- package/dist/node/index.js +6566 -0
- package/dist/types/api/blockscout/blockscout.d.ts +53 -0
- package/dist/types/api/blockscout/blockscout.test.d.ts +1 -0
- package/dist/types/api/blockscout/blockscoutType.d.ts +33 -0
- package/dist/types/api/blockscout/index.d.ts +2 -0
- package/dist/types/api/http/httpClient.d.ts +14 -0
- package/dist/types/api/http/httpClient.test.d.ts +1 -0
- package/dist/types/api/http/index.d.ts +1 -0
- package/dist/types/availability/availability.d.ts +6 -0
- package/dist/types/availability/availability.test.d.ts +1 -0
- package/dist/types/availability/index.d.ts +1 -0
- package/dist/types/balances/balances.d.ts +9 -0
- package/dist/types/balances/balances.test.d.ts +1 -0
- package/dist/types/balances/index.d.ts +1 -0
- package/dist/types/blockExplorer/blockExplorer.d.ts +9 -0
- package/dist/types/blockExplorer/blockExplorer.test.d.ts +1 -0
- package/dist/types/blockExplorer/index.d.ts +1 -0
- package/dist/types/config/config.d.ts +26 -0
- package/dist/types/config/config.test.d.ts +1 -0
- package/dist/types/config/index.d.ts +1 -0
- package/dist/types/config/remoteConfigFetcher.d.ts +19 -0
- package/dist/types/config/remoteConfigFetcher.test.d.ts +1 -0
- package/dist/types/config/tokensFetcher.d.ts +23 -0
- package/dist/types/config/tokensFetcher.test.d.ts +1 -0
- package/dist/types/connect/connect.d.ts +4 -0
- package/dist/types/connect/connect.test.d.ts +1 -0
- package/dist/types/connect/index.d.ts +1 -0
- package/dist/types/env/constants.d.ts +150 -0
- package/dist/types/env/env.d.ts +3 -0
- package/dist/types/env/env.test.d.ts +1 -0
- package/dist/types/env/index.d.ts +2 -0
- package/dist/types/errors/checkoutError.d.ts +80 -0
- package/dist/types/errors/checkoutError.test.d.ts +1 -0
- package/dist/types/errors/index.d.ts +1 -0
- package/dist/types/fiatRamp/fiatRamp.d.ts +23 -0
- package/dist/types/fiatRamp/fiatRamp.test.d.ts +1 -0
- package/dist/types/fiatRamp/index.d.ts +1 -0
- package/dist/types/gasEstimate/bridgeGasEstimate.d.ts +4 -0
- package/dist/types/gasEstimate/bridgeGasEstimate.test.d.ts +1 -0
- package/dist/types/gasEstimate/bridgeGasEstimateType.d.ts +5 -0
- package/dist/types/gasEstimate/gasEstimator.d.ts +4 -0
- package/dist/types/gasEstimate/gasEstimator.test.d.ts +1 -0
- package/dist/types/gasEstimate/gasPriceInWei.d.ts +2 -0
- package/dist/types/gasEstimate/gasPriceInWei.test.d.ts +1 -0
- package/dist/types/gasEstimate/index.d.ts +3 -0
- package/dist/types/index.d.ts +18 -0
- package/dist/types/instance/contract.d.ts +2 -0
- package/dist/types/instance/index.d.ts +2 -0
- package/dist/types/instance/instance.d.ts +11 -0
- package/dist/types/instance/instance.test.d.ts +1 -0
- package/dist/types/logger/debugLogger.d.ts +3 -0
- package/dist/types/logger/debugLogger.test.d.ts +1 -0
- package/dist/types/network/index.d.ts +1 -0
- package/dist/types/network/network.d.ts +7 -0
- package/dist/types/network/network.test.d.ts +1 -0
- package/dist/types/provider/getUnderlyingProvider.d.ts +8 -0
- package/dist/types/provider/getUnderlyingProvider.test.d.ts +1 -0
- package/dist/types/provider/index.d.ts +4 -0
- package/dist/types/provider/injected/index.d.ts +3 -0
- package/dist/types/provider/injected/index.test.d.ts +1 -0
- package/dist/types/provider/injected/register.d.ts +20 -0
- package/dist/types/provider/injected/store.d.ts +42 -0
- package/dist/types/provider/injected/utils.d.ts +19 -0
- package/dist/types/provider/injected/window.d.ts +8 -0
- package/dist/types/provider/injectedProvidersManager.d.ts +19 -0
- package/dist/types/provider/provider.d.ts +3 -0
- package/dist/types/provider/provider.test.d.ts +1 -0
- package/dist/types/provider/providerDetail.d.ts +5 -0
- package/dist/types/provider/validateProvider.d.ts +5 -0
- package/dist/types/provider/validateProvider.test.d.ts +1 -0
- package/dist/types/readOnlyProviders/readOnlyProvider.d.ts +4 -0
- package/dist/types/readOnlyProviders/readOnlyProviders.test.d.ts +1 -0
- package/dist/types/riskAssessment/index.d.ts +1 -0
- package/dist/types/riskAssessment/riskAssessment.d.ts +14 -0
- package/dist/types/riskAssessment/riskAssessment.test.d.ts +1 -0
- package/dist/types/sdk.d.ts +216 -0
- package/dist/types/sdk.test.d.ts +1 -0
- package/dist/types/smartCheckout/actions/getUnsignedActions.d.ts +7 -0
- package/dist/types/smartCheckout/actions/getUnsignedActions.test.d.ts +1 -0
- package/dist/types/smartCheckout/actions/index.d.ts +2 -0
- package/dist/types/smartCheckout/actions/signActions.d.ts +6 -0
- package/dist/types/smartCheckout/actions/signActions.test.d.ts +1 -0
- package/dist/types/smartCheckout/actions/types.d.ts +32 -0
- package/dist/types/smartCheckout/aggregators/allowanceAggregator.d.ts +2 -0
- package/dist/types/smartCheckout/aggregators/allowanceAggregator.test.d.ts +1 -0
- package/dist/types/smartCheckout/aggregators/balanceAggregator.d.ts +5 -0
- package/dist/types/smartCheckout/aggregators/balanceAggregator.test.d.ts +1 -0
- package/dist/types/smartCheckout/aggregators/index.d.ts +2 -0
- package/dist/types/smartCheckout/aggregators/itemAggregator.d.ts +6 -0
- package/dist/types/smartCheckout/aggregators/itemAggregator.test.d.ts +1 -0
- package/dist/types/smartCheckout/allowList/allowListCheck.d.ts +11 -0
- package/dist/types/smartCheckout/allowList/allowListCheck.test.d.ts +1 -0
- package/dist/types/smartCheckout/allowList/index.d.ts +1 -0
- package/dist/types/smartCheckout/allowList/types.d.ts +6 -0
- package/dist/types/smartCheckout/allowance/erc1155.d.ts +9 -0
- package/dist/types/smartCheckout/allowance/erc1155.test.d.ts +1 -0
- package/dist/types/smartCheckout/allowance/erc20.d.ts +9 -0
- package/dist/types/smartCheckout/allowance/erc20.test.d.ts +1 -0
- package/dist/types/smartCheckout/allowance/erc721.d.ts +12 -0
- package/dist/types/smartCheckout/allowance/erc721.test.d.ts +1 -0
- package/dist/types/smartCheckout/allowance/index.d.ts +3 -0
- package/dist/types/smartCheckout/allowance/types.d.ts +30 -0
- package/dist/types/smartCheckout/balanceCheck/balanceCheck.d.ts +7 -0
- package/dist/types/smartCheckout/balanceCheck/balanceCheck.test.d.ts +1 -0
- package/dist/types/smartCheckout/balanceCheck/balanceRequirement.d.ts +17 -0
- package/dist/types/smartCheckout/balanceCheck/balanceRequirement.test.d.ts +1 -0
- package/dist/types/smartCheckout/balanceCheck/index.d.ts +1 -0
- package/dist/types/smartCheckout/balanceCheck/types.d.ts +30 -0
- package/dist/types/smartCheckout/buy/buy.d.ts +7 -0
- package/dist/types/smartCheckout/buy/buy.test.d.ts +1 -0
- package/dist/types/smartCheckout/buy/index.d.ts +1 -0
- package/dist/types/smartCheckout/cancel/cancel.d.ts +3 -0
- package/dist/types/smartCheckout/cancel/cancel.test.d.ts +1 -0
- package/dist/types/smartCheckout/cancel/index.d.ts +1 -0
- package/dist/types/smartCheckout/fees/fees.d.ts +5 -0
- package/dist/types/smartCheckout/fees/fees.test.d.ts +1 -0
- package/dist/types/smartCheckout/gas/gasCalculator.d.ts +6 -0
- package/dist/types/smartCheckout/gas/gasCalculator.test.d.ts +1 -0
- package/dist/types/smartCheckout/gas/index.d.ts +1 -0
- package/dist/types/smartCheckout/index.d.ts +1 -0
- package/dist/types/smartCheckout/itemRequirements/index.d.ts +1 -0
- package/dist/types/smartCheckout/itemRequirements/itemRequirements.d.ts +2 -0
- package/dist/types/smartCheckout/itemRequirements/itemRequirements.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridge/bridgeRoute.d.ts +11 -0
- package/dist/types/smartCheckout/routing/bridge/bridgeRoute.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridge/getBridgeFeeEstimate.d.ts +7 -0
- package/dist/types/smartCheckout/routing/bridge/getBridgeFeeEstimate.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridge/getEthBalance.d.ts +2 -0
- package/dist/types/smartCheckout/routing/bridge/getEthBalance.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.d.ts +15 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/bridgeAndSwapRoute.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/constructBridgeRequirements.d.ts +9 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/constructBridgeRequirements.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/fetchL1ToL2Mapping.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/fetchL1ToL2Mappings.d.ts +4 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/getBalancesByChain.d.ts +7 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/getBalancesByChain.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/getDexQuotes.d.ts +5 -0
- package/dist/types/smartCheckout/routing/bridgeAndSwap/getDexQuotes.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/geoBlocking.d.ts +3 -0
- package/dist/types/smartCheckout/routing/geoBlocking.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/index.d.ts +1 -0
- package/dist/types/smartCheckout/routing/indexer/fetchL1Representation.d.ts +9 -0
- package/dist/types/smartCheckout/routing/indexer/fetchL1Representation.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/onRamp/index.d.ts +1 -0
- package/dist/types/smartCheckout/routing/onRamp/onRampRoute.d.ts +4 -0
- package/dist/types/smartCheckout/routing/onRamp/onRampRoute.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/routingCalculator.d.ts +13 -0
- package/dist/types/smartCheckout/routing/routingCalculator.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/routingOptions.d.ts +7 -0
- package/dist/types/smartCheckout/routing/routingOptions.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/swap/quoteFetcher.d.ts +7 -0
- package/dist/types/smartCheckout/routing/swap/quoteFetcher.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/swap/swapRoute.d.ts +24 -0
- package/dist/types/smartCheckout/routing/swap/swapRoute.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/tokenBalances.d.ts +5 -0
- package/dist/types/smartCheckout/routing/tokenBalances.test.d.ts +1 -0
- package/dist/types/smartCheckout/routing/types.d.ts +15 -0
- package/dist/types/smartCheckout/sell/index.d.ts +1 -0
- package/dist/types/smartCheckout/sell/sell.d.ts +7 -0
- package/dist/types/smartCheckout/sell/sell.test.d.ts +1 -0
- package/dist/types/smartCheckout/smartCheckout.d.ts +6 -0
- package/dist/types/smartCheckout/smartCheckout.test.d.ts +1 -0
- package/dist/types/swap/index.d.ts +1 -0
- package/dist/types/swap/swap.d.ts +7 -0
- package/dist/types/swap/swap.test.d.ts +1 -0
- package/dist/types/tokens/index.d.ts +1 -0
- package/dist/types/tokens/tokens.d.ts +12 -0
- package/dist/types/tokens/tokens.test.d.ts +1 -0
- package/dist/types/transaction/index.d.ts +1 -0
- package/dist/types/transaction/transaction.d.ts +21 -0
- package/dist/types/transaction/transaction.test.d.ts +1 -0
- package/dist/types/types/balances.d.ts +52 -0
- package/dist/types/types/buy.d.ts +15 -0
- package/dist/types/types/cancel.d.ts +15 -0
- package/dist/types/types/chains.d.ts +48 -0
- package/dist/types/types/config.d.ts +265 -0
- package/dist/types/types/connect.d.ts +34 -0
- package/dist/types/types/eip1193.d.ts +47 -0
- package/dist/types/types/eip6963.d.ts +29 -0
- package/dist/types/types/fees.d.ts +10 -0
- package/dist/types/types/fiatRamp.d.ts +25 -0
- package/dist/types/types/gasEstimate.d.ts +64 -0
- package/dist/types/types/index.d.ts +20 -0
- package/dist/types/types/network.d.ts +77 -0
- package/dist/types/types/networkInfo.d.ts +15 -0
- package/dist/types/types/provider.d.ts +45 -0
- package/dist/types/types/sell.d.ts +13 -0
- package/dist/types/types/smartCheckout.d.ts +918 -0
- package/dist/types/types/swap.d.ts +47 -0
- package/dist/types/types/token.d.ts +40 -0
- package/dist/types/types/tokenInfo.d.ts +27 -0
- package/dist/types/types/transaction.d.ts +18 -0
- package/dist/types/types/wallet.d.ts +49 -0
- package/dist/types/types/widgets.d.ts +11 -0
- package/dist/types/utils/utils.d.ts +11 -0
- package/dist/types/utils/utils.test.d.ts +1 -0
- package/dist/types/wallet/index.d.ts +1 -0
- package/dist/types/wallet/wallet.d.ts +2 -0
- package/dist/types/wallet/wallet.test.d.ts +1 -0
- package/dist/types/widgets/definitions/configurations/addTokens.d.ts +5 -0
- package/dist/types/widgets/definitions/configurations/bridge.d.ts +5 -0
- package/dist/types/widgets/definitions/configurations/commerce.d.ts +17 -0
- package/dist/types/widgets/definitions/configurations/connect.d.ts +5 -0
- package/dist/types/widgets/definitions/configurations/index.d.ts +11 -0
- package/dist/types/widgets/definitions/configurations/onramp.d.ts +5 -0
- package/dist/types/widgets/definitions/configurations/purchase.d.ts +2 -0
- package/dist/types/widgets/definitions/configurations/sale.d.ts +8 -0
- package/dist/types/widgets/definitions/configurations/swap.d.ts +5 -0
- package/dist/types/widgets/definitions/configurations/theme.d.ts +7 -0
- package/dist/types/widgets/definitions/configurations/wallet.d.ts +12 -0
- package/dist/types/widgets/definitions/configurations/widget.d.ts +31 -0
- package/dist/types/widgets/definitions/events/addTokens.d.ts +41 -0
- package/dist/types/widgets/definitions/events/bridge.d.ts +52 -0
- package/dist/types/widgets/definitions/events/commerce.d.ts +134 -0
- package/dist/types/widgets/definitions/events/connect.d.ts +47 -0
- package/dist/types/widgets/definitions/events/index.d.ts +11 -0
- package/dist/types/widgets/definitions/events/onramp.d.ts +28 -0
- package/dist/types/widgets/definitions/events/orchestration.d.ts +84 -0
- package/dist/types/widgets/definitions/events/purchase.d.ts +30 -0
- package/dist/types/widgets/definitions/events/sale.d.ts +103 -0
- package/dist/types/widgets/definitions/events/swap.d.ts +40 -0
- package/dist/types/widgets/definitions/events/wallet.d.ts +28 -0
- package/dist/types/widgets/definitions/events/widgets.d.ts +35 -0
- package/dist/types/widgets/definitions/global.d.ts +73 -0
- package/dist/types/widgets/definitions/parameters/addTokens.d.ts +20 -0
- package/dist/types/widgets/definitions/parameters/bridge.d.ts +20 -0
- package/dist/types/widgets/definitions/parameters/commerce.d.ts +44 -0
- package/dist/types/widgets/definitions/parameters/connect.d.ts +16 -0
- package/dist/types/widgets/definitions/parameters/index.d.ts +9 -0
- package/dist/types/widgets/definitions/parameters/onramp.d.ts +20 -0
- package/dist/types/widgets/definitions/parameters/purchase.d.ts +18 -0
- package/dist/types/widgets/definitions/parameters/sale.d.ts +50 -0
- package/dist/types/widgets/definitions/parameters/swap.d.ts +31 -0
- package/dist/types/widgets/definitions/parameters/wallet.d.ts +12 -0
- package/dist/types/widgets/definitions/types.d.ts +282 -0
- package/dist/types/widgets/load.d.ts +2 -0
- package/dist/types/widgets/load.test.d.ts +1 -0
- package/dist/types/widgets/version.d.ts +23 -0
- package/dist/types/widgets/version.test.d.ts +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WalletProviderName } from '../../../types';
|
|
2
|
+
import { WidgetLanguage } from '../configurations';
|
|
3
|
+
/**
|
|
4
|
+
* Wallet Widget parameters
|
|
5
|
+
* @property {WalletProviderName | undefined} walletProviderName
|
|
6
|
+
*/
|
|
7
|
+
export type WalletWidgetParams = {
|
|
8
|
+
/** The wallet provider name to use for the wallet widget */
|
|
9
|
+
walletProviderName?: WalletProviderName;
|
|
10
|
+
/** The language to use for the wallet widget */
|
|
11
|
+
language?: WidgetLanguage;
|
|
12
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { Environment } from '@imtbl/config';
|
|
2
|
+
import { BridgeClaimWithdrawalFailed, BridgeClaimWithdrawalSuccess, BridgeEventType, BridgeFailed, BridgeTransactionSent, ConnectEventType, ConnectionFailed, ConnectionSuccess, OnRampEventType, OnRampFailed, OnRampSuccess, OrchestrationEventType, ProviderEventType, ProviderUpdated, RequestBridgeEvent, RequestConnectEvent, RequestOnrampEvent, RequestSwapEvent, RequestWalletEvent, SaleEventType, SaleFailed, SalePaymentMethod, SalePaymentToken, SaleSuccess, SaleTransactionSuccess, SwapEventType, SwapFailed, SwapRejected, SwapSuccess, WalletConnectProviderChanged, WalletDisconnect, WalletEventType, WalletNetworkSwitch, CommerceEventType, CommerceProviderUpdatedEvent, CommerceSuccessEvent, CommerceFailureEvent, CommerceUserActionEvent, RequestAddTokensEvent, RequestGoBackEvent, AddTokensEventType, AddTokensConnectSuccess, AddTokensSuccess, AddTokensFailed, PurchaseConnectSuccess, PurchaseEventType, PurchaseFailed, PurchaseSuccess } from './events';
|
|
3
|
+
import { BridgeWidgetParams, ConnectWidgetParams, SwapWidgetParams, WalletWidgetParams, OnRampWidgetParams, CommerceWidgetParams, AddTokensWidgetParams, SaleWidgetParams, PurchaseWidgetParams } from './parameters';
|
|
4
|
+
import { BridgeWidgetConfiguration, ConnectWidgetConfiguration, OnrampWidgetConfiguration, SaleWidgetConfiguration, SwapWidgetConfiguration, WalletWidgetConfiguration, CommerceWidgetConfiguration, AddTokensWidgetConfiguration, WidgetTheme, PurchaseWidgetConfiguration } from './configurations';
|
|
5
|
+
import { WrappedBrowserProvider } from '../../types';
|
|
6
|
+
/**
|
|
7
|
+
* Enum representing the list of widget types.
|
|
8
|
+
*/
|
|
9
|
+
export declare enum WidgetType {
|
|
10
|
+
CONNECT = "connect",
|
|
11
|
+
WALLET = "wallet",
|
|
12
|
+
SWAP = "swap",
|
|
13
|
+
BRIDGE = "bridge",
|
|
14
|
+
ONRAMP = "onramp",
|
|
15
|
+
SALE = "sale",
|
|
16
|
+
IMMUTABLE_COMMERCE = "immutableCommerce",
|
|
17
|
+
ADD_TOKENS = "addTokens",
|
|
18
|
+
PURCHASE = "purchase"
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Widget properties definition for each widget. Used for creating and updating widgets
|
|
22
|
+
*/
|
|
23
|
+
export type WidgetProperties<T extends WidgetType> = {
|
|
24
|
+
config?: WidgetConfigurations[T];
|
|
25
|
+
provider?: WrappedBrowserProvider;
|
|
26
|
+
};
|
|
27
|
+
export type WidgetConfigurations = {
|
|
28
|
+
[WidgetType.CONNECT]: ConnectWidgetConfiguration;
|
|
29
|
+
[WidgetType.WALLET]: WalletWidgetConfiguration;
|
|
30
|
+
[WidgetType.SWAP]: SwapWidgetConfiguration;
|
|
31
|
+
[WidgetType.BRIDGE]: BridgeWidgetConfiguration;
|
|
32
|
+
[WidgetType.ONRAMP]: OnrampWidgetConfiguration;
|
|
33
|
+
[WidgetType.SALE]: SaleWidgetConfiguration;
|
|
34
|
+
[WidgetType.ADD_TOKENS]: AddTokensWidgetConfiguration;
|
|
35
|
+
[WidgetType.PURCHASE]: PurchaseWidgetConfiguration;
|
|
36
|
+
[WidgetType.IMMUTABLE_COMMERCE]: CommerceWidgetConfiguration;
|
|
37
|
+
};
|
|
38
|
+
export type WidgetParameters = {
|
|
39
|
+
[WidgetType.CONNECT]: ConnectWidgetParams;
|
|
40
|
+
[WidgetType.WALLET]: WalletWidgetParams;
|
|
41
|
+
[WidgetType.SWAP]: SwapWidgetParams;
|
|
42
|
+
[WidgetType.BRIDGE]: BridgeWidgetParams;
|
|
43
|
+
[WidgetType.ONRAMP]: OnRampWidgetParams;
|
|
44
|
+
[WidgetType.SALE]: SaleWidgetParams;
|
|
45
|
+
[WidgetType.ADD_TOKENS]: AddTokensWidgetParams;
|
|
46
|
+
[WidgetType.PURCHASE]: PurchaseWidgetParams;
|
|
47
|
+
[WidgetType.IMMUTABLE_COMMERCE]: CommerceWidgetParams;
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* Represents all the possible event types that are emitted by the widgets.
|
|
51
|
+
*/
|
|
52
|
+
export type WidgetEventTypes = {
|
|
53
|
+
[WidgetType.CONNECT]: ConnectEventType | OrchestrationEventType;
|
|
54
|
+
[WidgetType.WALLET]: WalletEventType | OrchestrationEventType;
|
|
55
|
+
[WidgetType.SWAP]: SwapEventType | OrchestrationEventType;
|
|
56
|
+
[WidgetType.BRIDGE]: BridgeEventType | OrchestrationEventType;
|
|
57
|
+
[WidgetType.ONRAMP]: OnRampEventType | OrchestrationEventType;
|
|
58
|
+
[WidgetType.SALE]: SaleEventType | OrchestrationEventType;
|
|
59
|
+
[WidgetType.IMMUTABLE_COMMERCE]: CommerceEventType | OrchestrationEventType;
|
|
60
|
+
[WidgetType.ADD_TOKENS]: AddTokensEventType | OrchestrationEventType;
|
|
61
|
+
[WidgetType.PURCHASE]: PurchaseEventType | OrchestrationEventType;
|
|
62
|
+
};
|
|
63
|
+
type OrchestrationMapping = {
|
|
64
|
+
[OrchestrationEventType.REQUEST_CONNECT]: RequestConnectEvent;
|
|
65
|
+
[OrchestrationEventType.REQUEST_WALLET]: RequestWalletEvent;
|
|
66
|
+
[OrchestrationEventType.REQUEST_SWAP]: RequestSwapEvent;
|
|
67
|
+
[OrchestrationEventType.REQUEST_BRIDGE]: RequestBridgeEvent;
|
|
68
|
+
[OrchestrationEventType.REQUEST_ONRAMP]: RequestOnrampEvent;
|
|
69
|
+
[OrchestrationEventType.REQUEST_ADD_TOKENS]: RequestAddTokensEvent;
|
|
70
|
+
[OrchestrationEventType.REQUEST_GO_BACK]: RequestGoBackEvent;
|
|
71
|
+
};
|
|
72
|
+
type ProviderEventMapping = {
|
|
73
|
+
[ProviderEventType.PROVIDER_UPDATED]: ProviderUpdated;
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Mapping of widget type, to each of its events and then each event's payload
|
|
77
|
+
* Update this whenever a new event is created and used by a widget
|
|
78
|
+
* Each widget also has all the orchestration events
|
|
79
|
+
*/
|
|
80
|
+
export type WidgetEventData = {
|
|
81
|
+
[WidgetType.CONNECT]: {
|
|
82
|
+
[ConnectEventType.SUCCESS]: ConnectionSuccess;
|
|
83
|
+
[ConnectEventType.FAILURE]: ConnectionFailed;
|
|
84
|
+
[ConnectEventType.CLOSE_WIDGET]: {};
|
|
85
|
+
[ConnectEventType.WALLETCONNECT_PROVIDER_UPDATED]: WalletConnectProviderChanged;
|
|
86
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
87
|
+
[WidgetType.WALLET]: {
|
|
88
|
+
[WalletEventType.NETWORK_SWITCH]: WalletNetworkSwitch;
|
|
89
|
+
[WalletEventType.DISCONNECT_WALLET]: WalletDisconnect;
|
|
90
|
+
[WalletEventType.CLOSE_WIDGET]: {};
|
|
91
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
92
|
+
[WidgetType.SWAP]: {
|
|
93
|
+
[SwapEventType.SUCCESS]: SwapSuccess;
|
|
94
|
+
[SwapEventType.FAILURE]: SwapFailed;
|
|
95
|
+
[SwapEventType.REJECTED]: SwapRejected;
|
|
96
|
+
[SwapEventType.CLOSE_WIDGET]: {};
|
|
97
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
98
|
+
[WidgetType.BRIDGE]: {
|
|
99
|
+
[BridgeEventType.TRANSACTION_SENT]: BridgeTransactionSent;
|
|
100
|
+
[BridgeEventType.FAILURE]: BridgeFailed;
|
|
101
|
+
[BridgeEventType.CLOSE_WIDGET]: {};
|
|
102
|
+
[BridgeEventType.CLAIM_WITHDRAWAL_SUCCESS]: BridgeClaimWithdrawalSuccess;
|
|
103
|
+
[BridgeEventType.CLAIM_WITHDRAWAL_FAILURE]: BridgeClaimWithdrawalFailed;
|
|
104
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
105
|
+
[WidgetType.ONRAMP]: {
|
|
106
|
+
[OnRampEventType.SUCCESS]: OnRampSuccess;
|
|
107
|
+
[OnRampEventType.FAILURE]: OnRampFailed;
|
|
108
|
+
[OnRampEventType.CLOSE_WIDGET]: {};
|
|
109
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
110
|
+
[WidgetType.SALE]: {
|
|
111
|
+
[SaleEventType.SUCCESS]: SaleSuccess;
|
|
112
|
+
[SaleEventType.FAILURE]: SaleFailed;
|
|
113
|
+
[SaleEventType.REJECTED]: any;
|
|
114
|
+
[SaleEventType.CLOSE_WIDGET]: {};
|
|
115
|
+
[SaleEventType.TRANSACTION_SUCCESS]: SaleTransactionSuccess;
|
|
116
|
+
[SaleEventType.PAYMENT_METHOD]: SalePaymentMethod;
|
|
117
|
+
[SaleEventType.PAYMENT_TOKEN]: SalePaymentToken;
|
|
118
|
+
[SaleEventType.REQUEST_BRIDGE]: {};
|
|
119
|
+
[SaleEventType.REQUEST_SWAP]: {};
|
|
120
|
+
[SaleEventType.REQUEST_ONRAMP]: {};
|
|
121
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
122
|
+
[WidgetType.IMMUTABLE_COMMERCE]: {
|
|
123
|
+
[CommerceEventType.INITIALISED]: CommerceWidgetParams;
|
|
124
|
+
[CommerceEventType.PROVIDER_UPDATED]: CommerceProviderUpdatedEvent;
|
|
125
|
+
[CommerceEventType.CLOSE]: {};
|
|
126
|
+
[CommerceEventType.SUCCESS]: CommerceSuccessEvent;
|
|
127
|
+
[CommerceEventType.FAILURE]: CommerceFailureEvent;
|
|
128
|
+
[CommerceEventType.DISCONNECTED]: {};
|
|
129
|
+
[CommerceEventType.USER_ACTION]: CommerceUserActionEvent;
|
|
130
|
+
};
|
|
131
|
+
[WidgetType.ADD_TOKENS]: {
|
|
132
|
+
[AddTokensEventType.CLOSE_WIDGET]: {};
|
|
133
|
+
[AddTokensEventType.CONNECT_SUCCESS]: AddTokensConnectSuccess;
|
|
134
|
+
[AddTokensEventType.SUCCESS]: AddTokensSuccess;
|
|
135
|
+
[AddTokensEventType.FAILURE]: AddTokensFailed;
|
|
136
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
137
|
+
[WidgetType.PURCHASE]: {
|
|
138
|
+
[PurchaseEventType.CLOSE_WIDGET]: {};
|
|
139
|
+
[PurchaseEventType.CONNECT_SUCCESS]: PurchaseConnectSuccess;
|
|
140
|
+
[PurchaseEventType.SUCCESS]: PurchaseSuccess;
|
|
141
|
+
[PurchaseEventType.FAILURE]: PurchaseFailed;
|
|
142
|
+
} & OrchestrationMapping & ProviderEventMapping;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Represents an event emitted by a widget. The event type should match the event data
|
|
146
|
+
*/
|
|
147
|
+
/**
|
|
148
|
+
* Represents an event emitted by a widget.
|
|
149
|
+
* @template T - The widget type
|
|
150
|
+
* @template KEventName - The widget event name.
|
|
151
|
+
* @property {KEventName} type - The type of the event.
|
|
152
|
+
* @property {WidgetEventData[T][KEventName]} data - The data associated with the widget event.
|
|
153
|
+
*/
|
|
154
|
+
export type WidgetEvent<T extends WidgetType, KEventName extends keyof WidgetEventData[T]> = {
|
|
155
|
+
type: KEventName;
|
|
156
|
+
data: WidgetEventData[T][KEventName];
|
|
157
|
+
};
|
|
158
|
+
/**
|
|
159
|
+
* Represents an event emitted by a widget.
|
|
160
|
+
* @template KEventName - The orchestration event name.
|
|
161
|
+
* @property {KEventName} type
|
|
162
|
+
* @property {OrchestrationMapping[KEventName]} data
|
|
163
|
+
*/
|
|
164
|
+
export type OrchestrationEvent<KEventName extends keyof OrchestrationMapping> = {
|
|
165
|
+
/** The type of the event. */
|
|
166
|
+
type: KEventName;
|
|
167
|
+
/** The data associated with the event. */
|
|
168
|
+
data: OrchestrationMapping[KEventName];
|
|
169
|
+
};
|
|
170
|
+
/**
|
|
171
|
+
* Represents an event emitted by a widget.
|
|
172
|
+
* @template KEventName - The provider event name.
|
|
173
|
+
* @property {KEventName} type
|
|
174
|
+
* @property {ProviderEventMapping[KEventName]} data
|
|
175
|
+
*/
|
|
176
|
+
export type ProviderEvent<KEventName extends keyof ProviderEventMapping> = {
|
|
177
|
+
/** The type of the event. */
|
|
178
|
+
type: KEventName;
|
|
179
|
+
/** The data associated with the event. */
|
|
180
|
+
data: ProviderEventMapping[KEventName];
|
|
181
|
+
};
|
|
182
|
+
export interface IWidgetsFactory {
|
|
183
|
+
/**
|
|
184
|
+
* Create a new widget instance.
|
|
185
|
+
* @param type widget type to instantiate.
|
|
186
|
+
* @param props widget configurations and provider.
|
|
187
|
+
*/
|
|
188
|
+
create: IWidgetsFactoryCreate;
|
|
189
|
+
/**
|
|
190
|
+
* Update the widgets provider instance.
|
|
191
|
+
* @param provider the provider instance to update all widgets.
|
|
192
|
+
*/
|
|
193
|
+
updateProvider(provider: WrappedBrowserProvider): void;
|
|
194
|
+
}
|
|
195
|
+
export interface IWidgetsFactoryCreate {
|
|
196
|
+
(type: WidgetType.IMMUTABLE_COMMERCE, props?: WidgetProperties<WidgetType.IMMUTABLE_COMMERCE>): Widget<WidgetType.IMMUTABLE_COMMERCE>;
|
|
197
|
+
/** @deprecated
|
|
198
|
+
* Use WidgetType.IMMUTABLE_COMMERCE instead, see https://docs.immutable.com/products/zkEVM/checkout/commerce-widget
|
|
199
|
+
* */
|
|
200
|
+
<T extends Exclude<WidgetType, WidgetType.IMMUTABLE_COMMERCE>>(type: T, props?: WidgetProperties<T>): Widget<T>;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Widget interface. Every widget implements this interface.
|
|
204
|
+
*/
|
|
205
|
+
export interface Widget<T extends WidgetType> {
|
|
206
|
+
/**
|
|
207
|
+
* Mount a widget to a DOM ref element.
|
|
208
|
+
* @param id ID of the DOM element where the widget will be mounted.
|
|
209
|
+
* @param params widget parameters.
|
|
210
|
+
*/
|
|
211
|
+
mount(id: string, params?: WidgetParameters[T]): void;
|
|
212
|
+
/**
|
|
213
|
+
* Unmount a widget and reset parameters
|
|
214
|
+
*/
|
|
215
|
+
unmount(): void;
|
|
216
|
+
/**
|
|
217
|
+
* Update the widget properties
|
|
218
|
+
* @param props Widget specific properties including configuration
|
|
219
|
+
*/
|
|
220
|
+
update(props: WidgetProperties<T>): void;
|
|
221
|
+
/**
|
|
222
|
+
* Add a listener for a widget event.
|
|
223
|
+
* @param event Widget specific event name.
|
|
224
|
+
* @param callback function to execute when the event is received.
|
|
225
|
+
*/
|
|
226
|
+
addListener<KEventName extends keyof WidgetEventData[T]>(type: KEventName, callback: (data: WidgetEventData[T][KEventName]) => void): void;
|
|
227
|
+
/**
|
|
228
|
+
* Removes an event listener for a widget event.
|
|
229
|
+
* @param type Widget specific event name.
|
|
230
|
+
*/
|
|
231
|
+
removeListener<KEventName extends keyof WidgetEventData[T]>(type: KEventName): void;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Represents the version of the Commerce Widgets to use defaults to (0.1.9-alpha)
|
|
235
|
+
* @property {number} major
|
|
236
|
+
* @property {number | undefined} minor
|
|
237
|
+
* @property {number | undefined} patch
|
|
238
|
+
* @property {'alpha' | undefined} prerelease
|
|
239
|
+
* @property {number | undefined} build
|
|
240
|
+
*
|
|
241
|
+
* @example
|
|
242
|
+
* { major: 0 } - use default version 0.1.9-alpha
|
|
243
|
+
* { major: 1 } - use version 1.x.x, pickup all new minor and patch versions released
|
|
244
|
+
* { major: 1, minor: 1 } - use version 1.1.x, pickup all new patch versions released
|
|
245
|
+
* { major: 1, minor: 2, patch: 3 } - use version 1.2.3 specifically
|
|
246
|
+
*/
|
|
247
|
+
export type SemanticVersion = {
|
|
248
|
+
/** The major version of the widgets, must specify a major version even if it is 0. */
|
|
249
|
+
major: number;
|
|
250
|
+
/** The minor version of the widgets, leaving this blank will use the latest minor based on major */
|
|
251
|
+
minor?: number;
|
|
252
|
+
/** The patch version of the widgets, leaving this blank will use the latest minor based on minor */
|
|
253
|
+
patch?: number;
|
|
254
|
+
/** The prerelease version of the widgets, can only be 'alpha'. Do not use in production. */
|
|
255
|
+
prerelease?: 'alpha';
|
|
256
|
+
/** The build version of the widgets. Do not use in production. */
|
|
257
|
+
build?: number;
|
|
258
|
+
};
|
|
259
|
+
/**
|
|
260
|
+
* Represents the global configuration options for the Commerce Widgets.
|
|
261
|
+
* @property {WidgetTheme | undefined} theme
|
|
262
|
+
* @property {Environment | undefined} environment
|
|
263
|
+
* @property {SemanticVersion | undefined} version
|
|
264
|
+
* @property {boolean | undefined} isOnRampEnabled
|
|
265
|
+
* @property {boolean | undefined} isSwapEnabled
|
|
266
|
+
* @property {boolean | undefined} isBridgeEnabled
|
|
267
|
+
*/
|
|
268
|
+
export type CheckoutWidgetsConfig = {
|
|
269
|
+
/** The theme of the Checkout Widget (default: "DARK") */
|
|
270
|
+
theme?: WidgetTheme;
|
|
271
|
+
/** The environment configuration (default: "SANDBOX") */
|
|
272
|
+
environment?: Environment;
|
|
273
|
+
/** The version of the Checkout Widgets js file to use (default: "0.1.x") */
|
|
274
|
+
version?: SemanticVersion;
|
|
275
|
+
/** Enable on-ramp top-up method (default: "true") */
|
|
276
|
+
isOnRampEnabled?: boolean;
|
|
277
|
+
/** Enable swap top-up method (default: "true") */
|
|
278
|
+
isSwapEnabled?: boolean;
|
|
279
|
+
/** Enable bridge top-up method (default: "true") */
|
|
280
|
+
isBridgeEnabled?: boolean;
|
|
281
|
+
};
|
|
282
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SemanticVersion } from './definitions/types';
|
|
2
|
+
import { CheckoutWidgetsVersionConfig } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Validates and builds a version string based on the given SemanticVersion object.
|
|
5
|
+
* If the version is undefined or has an invalid major version, it returns the default checkout version.
|
|
6
|
+
* If the version is all zeros, it also returns the default checkout version.
|
|
7
|
+
* Otherwise, it constructs a validated version string based on the major, minor, patch, and build numbers.
|
|
8
|
+
*/
|
|
9
|
+
export declare function validateAndBuildVersion(version: SemanticVersion | undefined): string;
|
|
10
|
+
/**
|
|
11
|
+
* Fetches the latest version of the package from the NPM registry.
|
|
12
|
+
* Loads a specific latest version instead of relying on the latest tag helps with caching issues.
|
|
13
|
+
* Falls back to 'latest' if an error occurs or if the response is invalid.
|
|
14
|
+
* @returns {Promise<string>} A promise resolving to the latest version string or 'latest'.
|
|
15
|
+
*/
|
|
16
|
+
export declare function getLatestVersionFromNpm(): Promise<string>;
|
|
17
|
+
/**
|
|
18
|
+
* Determines the version of the widgets to use based on the provided validated build version and checkout version config.
|
|
19
|
+
* If a version is provided in the widget init parameters, it uses that version.
|
|
20
|
+
* If the build version is an alpha, it uses that version.
|
|
21
|
+
* Defaults to 'latest' if no compatible version markers are found.
|
|
22
|
+
*/
|
|
23
|
+
export declare function determineWidgetsVersion(validatedBuildVersion: string, initVersionProvided: boolean, versionConfig?: CheckoutWidgetsVersionConfig): Promise<string>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@imtbl/checkout-sdk",
|
|
3
|
+
"description": "Immutable Checkout SDK",
|
|
4
|
+
"version": "2.0.0-alpha.0",
|
|
5
|
+
"author": "immutable",
|
|
6
|
+
"bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
|
|
7
|
+
"dependencies": {
|
|
8
|
+
"@imtbl/blockchain-data": "2.0.0-alpha.0",
|
|
9
|
+
"@imtbl/bridge-sdk": "2.0.0-alpha.0",
|
|
10
|
+
"@imtbl/config": "2.0.0-alpha.0",
|
|
11
|
+
"@imtbl/dex-sdk": "2.0.0-alpha.0",
|
|
12
|
+
"@imtbl/generated-clients": "2.0.0-alpha.0",
|
|
13
|
+
"@imtbl/metrics": "2.0.0-alpha.0",
|
|
14
|
+
"@imtbl/orderbook": "2.0.0-alpha.0",
|
|
15
|
+
"@imtbl/passport": "2.0.0-alpha.0",
|
|
16
|
+
"@metamask/detect-provider": "^2.0.0",
|
|
17
|
+
"axios": "^1.6.5",
|
|
18
|
+
"ethers": "^6.13.4",
|
|
19
|
+
"semver": "^7.4.0",
|
|
20
|
+
"uuid": "^8.3.2"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@swc/core": "^1.3.36",
|
|
24
|
+
"@types/jest": "^29.4.3",
|
|
25
|
+
"@types/node": "^18.14.2",
|
|
26
|
+
"@types/semver": "^7.5.8",
|
|
27
|
+
"@types/uuid": "^8.3.4",
|
|
28
|
+
"esbuild-plugin-replace": "^1.4.0",
|
|
29
|
+
"eslint": "^8.40.0",
|
|
30
|
+
"jest": "^29.4.3",
|
|
31
|
+
"jest-environment-jsdom": "^29.4.3",
|
|
32
|
+
"text-encoding": "^0.7.0",
|
|
33
|
+
"tsup": "^8.3.5",
|
|
34
|
+
"typedoc": "^0.26.5",
|
|
35
|
+
"typedoc-plugin-markdown": "^4.2.3",
|
|
36
|
+
"typescript": "^5.6.2"
|
|
37
|
+
},
|
|
38
|
+
"exports": {
|
|
39
|
+
"development": {
|
|
40
|
+
"types": "./src/index.ts",
|
|
41
|
+
"browser": "./dist/browser/index.js",
|
|
42
|
+
"require": "./dist/node/index.cjs",
|
|
43
|
+
"default": "./dist/node/index.js"
|
|
44
|
+
},
|
|
45
|
+
"default": {
|
|
46
|
+
"types": "./dist/types/index.d.ts",
|
|
47
|
+
"browser": "./dist/browser/index.js",
|
|
48
|
+
"require": "./dist/node/index.cjs",
|
|
49
|
+
"default": "./dist/node/index.js"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"homepage": "https://github.com/immutable/ts-immutable-sdk",
|
|
56
|
+
"keywords": [
|
|
57
|
+
"immutablex"
|
|
58
|
+
],
|
|
59
|
+
"license": "Apache-2.0",
|
|
60
|
+
"main": "dist/node/index.cjs",
|
|
61
|
+
"module": "dist/node/index.js",
|
|
62
|
+
"browser": "dist/browser/index.js",
|
|
63
|
+
"publishConfig": {
|
|
64
|
+
"access": "public"
|
|
65
|
+
},
|
|
66
|
+
"repository": "immutable/ts-immutable-sdk.git",
|
|
67
|
+
"source": "src/index.ts",
|
|
68
|
+
"type": "module",
|
|
69
|
+
"types": "./dist/types/index.d.ts",
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "pnpm transpile && pnpm typegen",
|
|
72
|
+
"transpile": "tsup src/index.ts --config ./tsup.config.js",
|
|
73
|
+
"typegen": "tsc --customConditions default --emitDeclarationOnly --outDir dist/types",
|
|
74
|
+
"build:dev": "CHECKOUT_DEV_MODE=true pnpm build",
|
|
75
|
+
"docs": "typedoc --plugin typedoc-plugin-markdown --skipErrorChecking --disableSources --out docs src/index.ts",
|
|
76
|
+
"lint": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0",
|
|
77
|
+
"lint:fix": "eslint ./src --ext .ts,.jsx,.tsx --max-warnings=0 --fix",
|
|
78
|
+
"prepare:examplesdk": "pnpm --filter @examples/commerce-widget-nextjs exec mkdir -p tests/utils/local-widgets-js/ && cp ./dist/*.js $(pnpm --filter @examples/commerce-widget-nextjs exec pwd)/tests/utils/local-widgets-js/",
|
|
79
|
+
"prepare:testsdk": "pnpm --filter @tests/checkout-widgets-nextjs exec mkdir -p tests/utils/local-widgets-js/ && cp ./dist/*.js $(pnpm --filter @tests/checkout-widgets-nextjs exec pwd)/tests/utils/local-widgets-js/",
|
|
80
|
+
"start": "tsup --config ./tsup.config.js --watch",
|
|
81
|
+
"start:dev": "CHECKOUT_DEV_MODE=true pnpm start",
|
|
82
|
+
"start:local": "CHECKOUT_LOCAL_MODE=true pnpm start",
|
|
83
|
+
"test": "jest test",
|
|
84
|
+
"test:watch": "jest test --watch",
|
|
85
|
+
"typecheck": "tsc --customConditions default --noEmit"
|
|
86
|
+
}
|
|
87
|
+
}
|