Skip to content

Commit

Permalink
[NO CHANGELOG][Add Funds Widget] Slice 4 MVP Feature Branch (#2276)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Paul <[email protected]>
  • Loading branch information
jhesgodi and glomotion authored Oct 14, 2024
1 parent 574efd8 commit 6d960c6
Show file tree
Hide file tree
Showing 67 changed files with 3,245 additions and 1,027 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Web3Provider } from '@ethersproject/providers';
import GetAllBalances from '../components/GetAllBalances';
import CheckConnection from '../components/CheckConnection';
import GetAllowList from '../components/GetAllowList';
import { Body, Box, Checkbox, Divider, Heading, Toggle } from '@biom3/react';
import { Body, Box, Checkbox, Divider, Heading } from '@biom3/react';
import GetBalance from '../components/GetBalance';
import { Checkout } from '@imtbl/checkout-sdk';
import { Environment } from '@imtbl/config';
Expand Down
6 changes: 3 additions & 3 deletions packages/checkout/sdk/src/errors/checkoutError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ export type ErrorType = {

/* The CheckoutError class is a custom error class in TypeScript that includes a message, type, and
optional data object. */
export class CheckoutError extends Error {
export class CheckoutError<T = CheckoutErrorType> extends Error {
public message: string;

public type: CheckoutErrorType;
public type: T;

public data?: { [key: string]: any };

constructor(
message: string,
type: CheckoutErrorType,
type: T,
data?: {
[key: string]: any
},
Expand Down
2 changes: 1 addition & 1 deletion packages/checkout/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ export { isAddressSanctioned } from './sanctions';

export type { ErrorType } from './errors';

export { CheckoutErrorType } from './errors';
export { CheckoutErrorType, CheckoutError } from './errors';
export { CheckoutConfiguration } from './config';
export { BlockExplorerService } from './blockExplorer';
11 changes: 11 additions & 0 deletions packages/checkout/sdk/src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import { WidgetConfiguration } from './widgets/definitions/configurations';
import { getWidgetsEsmUrl, loadUnresolvedBundle } from './widgets/load';
import { determineWidgetsVersion, validateAndBuildVersion } from './widgets/version';
import { globalPackageVersion } from './env';
import { isAddressSanctioned } from './sanctions';

const SANDBOX_CONFIGURATION = {
baseConfig: {
Expand Down Expand Up @@ -333,6 +334,16 @@ export class Checkout {
return connect.checkIsWalletConnected(web3Provider);
}

/**
* Checks if an address is sanctioned.
* @param {string} address - The address to check.
* @param {Environment} environment - The environment to check.
* @returns {Promise<boolean>} - A promise that resolves to the result of the check.
*/
public async checkIsAddressSanctioned(address: string, environment: Environment): Promise<boolean> {
return await isAddressSanctioned(address, environment);
}

/**
* Connects to a blockchain network using the specified provider.
* @param {ConnectParams} params - The parameters for connecting to the network.
Expand Down
16 changes: 16 additions & 0 deletions packages/checkout/sdk/src/widgets/definitions/events/addFunds.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { Web3Provider } from '@ethersproject/providers';
import { EIP6963ProviderInfo } from '../../../types';

/**
* Enum of possible Add Funds Widget event types.
*/
export enum AddFundsEventType {
CLOSE_WIDGET = 'close-widget',
LANGUAGE_CHANGED = 'language-changed',
CONNECT_SUCCESS = 'connect-success',
REQUEST_BRIDGE = 'request-bridge',
REQUEST_ONRAMP = 'request-onramp',
REQUEST_SWAP = 'request-swap',
Expand All @@ -29,3 +33,15 @@ export type AddFundsFailed = {
/** The timestamp of the failed transaction. */
timestamp: number;
};

/**
* Type representing a successfull provider connection
* @property {Web3Provider} provider
* @property {EIP6963ProviderInfo} providerInfo
* @property {'from' | 'to'} providerType
*/
export type AddFundsConnectSuccess = {
provider: Web3Provider;
providerInfo: EIP6963ProviderInfo;
providerType: 'from' | 'to';
};
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from './bridge';
import { SwapFailed, SwapRejected, SwapSuccess } from './swap';
import { WalletNetworkSwitch } from './wallet';
import { AddFundsFailed, AddFundsSuccess } from './addFunds';
import { AddFundsFailed, AddFundsSuccess, AddFundsConnectSuccess } from './addFunds';

export enum CheckoutEventType {
INITIALISED = 'INITIALISED',
Expand Down Expand Up @@ -106,8 +106,14 @@ export type CheckoutAddFundsSuccessEvent = {
data: AddFundsSuccess;
};

export type CheckoutAddFundsConnectSuccessEvent = {
type: CheckoutSuccessEventType.CONNECT_SUCCESS;
data: AddFundsConnectSuccess;
};

export type CheckoutSuccessEvent =
| CheckoutAddFundsSuccessEvent
| CheckoutAddFundsConnectSuccessEvent
| CheckoutConnectSuccessEvent
| CheckoutBridgeSuccessEvent
| CheckoutBridgeClaimWithdrawalSuccessEvent
Expand Down
5 changes: 2 additions & 3 deletions packages/checkout/sdk/src/widgets/definitions/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
RequestAddFundsEvent,
RequestGoBackEvent,
AddFundsEventType,
AddFundsConnectSuccess,
} from './events';
import {
BridgeWidgetParams,
Expand Down Expand Up @@ -212,9 +213,7 @@ export type WidgetEventData = {

[WidgetType.ADD_FUNDS]: {
[AddFundsEventType.CLOSE_WIDGET]: {};
[AddFundsEventType.REQUEST_BRIDGE]: {};
[AddFundsEventType.REQUEST_SWAP]: {};
[AddFundsEventType.REQUEST_ONRAMP]: {};
[AddFundsEventType.CONNECT_SUCCESS]: AddFundsConnectSuccess;
} & OrchestrationMapping &
ProviderEventMapping;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function ChangedYourMindDrawer({
/>
<ButtCon
icon="Close"
size="small"
variant="tertiary"
sx={{
pos: 'absolute',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export interface ConnectLoaderProps {
params: ConnectLoaderParams;
closeEvent: () => void;
widgetConfig: StrongCheckoutWidgetsConfig;
goBackEvent?: () => void;
showBackButton?: boolean;
}

export interface ConnectLoaderParams {
Expand All @@ -47,6 +49,8 @@ export function ConnectLoader({
params,
widgetConfig,
closeEvent,
goBackEvent,
showBackButton,
}: ConnectLoaderProps) {
const {
checkout,
Expand Down Expand Up @@ -250,6 +254,8 @@ export function ConnectLoader({
sendCloseEventOverride={closeEvent}
allowedChains={allowedChains}
isCheckNetworkEnabled={isCheckNetworkEnabled ?? true}
showBackButton={showBackButton}
sendGoBackEventOverride={goBackEvent}
/>
)}
{/* If the user has connected then render the widget */}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Box, BoxProps } from '@biom3/react';
import merge from 'ts-deepmerge';
import {
simpleLayoutStyle,
headerStyle,
Expand All @@ -18,40 +19,42 @@ export interface SimpleLayoutProps {
floatHeader?: boolean;
footerBackgroundColor?: string;
bodyStyleOverrides?: BoxProps['sx'];
containerSx?: BoxProps['sx'];
}

export function SimpleLayout({
header,
footer,
children,
heroContent,
testId,
testId = 'container',
floatHeader = false,
footerBackgroundColor,
bodyStyleOverrides,
containerSx = {},
}: SimpleLayoutProps) {
return (
<Box sx={responsiveStyles}>
<Box testId={testId} sx={simpleLayoutStyle}>
<Box sx={responsiveStyles} testId="simpleLayout">
<Box testId={testId} sx={merge(simpleLayoutStyle, containerSx)}>
{header && (
<Box sx={headerStyle(floatHeader)}>
<Box sx={headerStyle(floatHeader)} testId="header">
{header}
</Box>
)}
<Box sx={contentStyle}>
<Box sx={contentStyle} testId="main">
{heroContent && (
<Box sx={heroContentStyle}>
{heroContent}
</Box>
)}
{children && (
<Box sx={{ ...bodyStyle, ...bodyStyleOverrides }}>
<Box sx={{ ...bodyStyle, ...bodyStyleOverrides }} testId="children">
{children}
</Box>
)}
</Box>
{footer && (
<Box sx={footerStyle(footerBackgroundColor)}>
<Box sx={footerStyle(footerBackgroundColor)} testId="footer">
{footer}
</Box>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export function UnableToConnectDrawer({
<ButtCon
icon="Close"
variant="tertiary"
size="small"
sx={{
pos: 'absolute',
top: 'base.spacing.x5',
Expand Down
Loading

0 comments on commit 6d960c6

Please sign in to comment.