Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .oxlintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
}
],

"eslint/preserve-caught-error": "error",

"eslint/no-unused-vars": [
"warn",
{
Expand All @@ -80,7 +82,7 @@
"typescript/restrict-template-expressions": "warn",
"typescript/await-thenable": "warn",
"typescript/no-redundant-type-constituents": "warn",
"typescript/no-non-null-asserted-optional-chain": "warn",
"typescript/no-non-null-asserted-optional-chain": "error",
"typescript/no-duplicate-type-constituents": "warn",
"typescript/no-unsafe-type-assertion": "off",
"typescript/no-unnecessary-type-assertion": "off",
Expand All @@ -90,7 +92,7 @@
"typescript/no-duplicate-enum-values": "warn",
"typescript/no-unnecessary-parameter-property-assignment": "off",
"typescript/no-this-alias": "warn",
"typescript/no-base-to-string": "warn",
"typescript/no-base-to-string": "error",
"typescript/no-wrapper-object-types": "warn",
"typescript/no-for-in-array": "warn",

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ export const connectEIP6963Provider = async (
case CheckoutErrorType.USER_REJECTED_REQUEST_ERROR:
throw new Error(
ConnectEIP6963ProviderError.USER_REJECTED_REQUEST_ERROR,
{ cause: error },
);
default:
throw new Error(ConnectEIP6963ProviderError.CONNECT_ERROR);
throw new Error(ConnectEIP6963ProviderError.CONNECT_ERROR, { cause: error });
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -305,24 +305,28 @@ export function BridgeReviewSummary() {
}, []);

const handleNetworkSwitch = useCallback((provider: WrappedBrowserProvider) => {
// Both sides must already be selected — this only ever runs after the review
// screen has them. Bail rather than dispatching undefined into bridge state.
if (!from || !to) return;

bridgeDispatch({
payload: {
type: BridgeActions.SET_WALLETS_AND_NETWORKS,
from: {
browserProvider: provider,
walletAddress: from?.walletAddress!,
walletProviderInfo: from?.walletProviderInfo!,
network: from?.network!,
walletAddress: from.walletAddress,
walletProviderInfo: from.walletProviderInfo,
network: from.network,
},
to: {
browserProvider: to?.browserProvider!,
walletAddress: to?.walletAddress!,
walletProviderInfo: to?.walletProviderInfo!,
network: to?.network!,
browserProvider: to.browserProvider,
walletAddress: to.walletAddress,
walletProviderInfo: to.walletProviderInfo,
network: to.network,
},
},
});
}, [from?.browserProvider, from?.network, to?.browserProvider, to?.network]);
}, [from, to]);

useEffect(() => {
if (!from?.browserProvider) return;
Expand Down Expand Up @@ -627,14 +631,16 @@ export function BridgeReviewSummary() {
</Button>
)}
</Box>
<NetworkSwitchDrawer
visible={showSwitchNetworkDrawer}
targetChainId={from?.network!}
provider={from?.browserProvider!}
checkout={checkout}
onCloseDrawer={() => setShowSwitchNetworkDrawer(false)}
onNetworkSwitch={handleNetworkSwitch}
/>
{from && (
<NetworkSwitchDrawer
visible={showSwitchNetworkDrawer}
targetChainId={from.network}
provider={from.browserProvider}
checkout={checkout}
onCloseDrawer={() => setShowSwitchNetworkDrawer(false)}
onNetworkSwitch={handleNetworkSwitch}
/>
)}
<NotEnoughGas
environment={checkout.config.environment}
visible={showNotEnoughGasDrawer}
Expand Down
10 changes: 6 additions & 4 deletions packages/checkout/widgets-lib/src/widgets/sale/SaleWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,12 @@ export default function SaleWidget(props: SaleWidgetProps) {
errorType={viewState.view.data?.errorType}
transactionHash={viewState.view.data?.transactionHash}
vendorMessage={viewState.view.data?.vendorError?.message}
blockExplorerLink={BlockExplorerService.getTransactionLink(
chainId.current as ChainId,
viewState.view.data?.transactionHash!,
)}
blockExplorerLink={viewState.view.data?.transactionHash
? BlockExplorerService.getTransactionLink(
chainId.current as ChainId,
viewState.view.data.transactionHash,
)
: undefined}
/>
)}
{viewState.view.type === SaleWidgetViews.ORDER_SUMMARY && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ export const getFundingBalanceFeeBreakDown = (
}

const addFee = (fee: Fee, label: string, prefix: string = '~ ') => {
if (fee.amount > 0) {
const formattedFee = formatUnits(fee.amount, fee?.token?.decimals);
// A fee without a token can't be rendered — FormattedFee.token is required
// and consumers read token.symbol, so skip rather than push a hole.
if (fee.amount > 0 && fee.token) {
const formattedFee = formatUnits(fee.amount, fee.token.decimals);

feesBreakdown.push({
label,
Expand All @@ -103,7 +105,7 @@ export const getFundingBalanceFeeBreakDown = (
)}`,
amount: `${tokenValueFormat(formattedFee)}`,
prefix,
token: fee?.token!,
token: fee.token,
});
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ export function OrderSummary({ subView }: OrderSummaryProps) {
// suggest to top up base currency balance
const smartCheckoutResult = fundingBalancesResult.find(
(result) => result.currency.base,
)?.smartCheckoutResult!;
)?.smartCheckoutResult;
if (!smartCheckoutResult) return;

const data = getTopUpViewData(
smartCheckoutResult.transactionRequirements,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ export function PayWithCoins() {
},
(error, txns) => {
const details = { transactionId: signResponse?.transactionId };
sendFailedEvent(error.toString(), error, txns, undefined, details); // checkoutPrimarySalePaymentMethods_FailEventFailed
// `error` is a SignOrderError ({ type, data }), not an Error. Its default
// toString is "[object Object]", so this event was reporting nothing
// useful — `type` is the field that identifies the failure.
const reason = error instanceof Error ? error.message : error.type;
sendFailedEvent(reason, error, txns, undefined, details); // checkoutPrimarySalePaymentMethods_FailEventFailed
goToErrorView(error.type, error.data);
},
onTxnStepExecuteAll,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ export class Wallet extends Base<WidgetType.WALLET> {
config={this.strongConfig()}
walletConfig={{
showDisconnectButton:
this.properties.config?.showDisconnectButton!,
showNetworkMenu: this.properties.config?.showNetworkMenu!,
this.properties.config?.showDisconnectButton ?? false,
showNetworkMenu: this.properties.config?.showNetworkMenu ?? false,
}}
/>
</Suspense>
Expand Down
8 changes: 4 additions & 4 deletions packages/internal/bridge/sdk/src/lib/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Validation', () => {
try {
await validateChainConfiguration(bridgeConfig);
} catch (error: any) {
throw new Error(`Should not have thrown an error, but threw ${error}`);
throw new Error(`Should not have thrown an error, but threw ${error}`, { cause: error });
}
});

Expand Down Expand Up @@ -107,7 +107,7 @@ describe('Validation', () => {
try {
await checkReceiver(tokenSent, destinationChainId, '0x123', config);
} catch (error: any) {
throw new Error(`Should not have thrown an error, but threw ${error}`);
throw new Error(`Should not have thrown an error, but threw ${error}`, { cause: error });
}
});

Expand All @@ -125,7 +125,7 @@ describe('Validation', () => {
try {
await checkReceiver(tokenSent, destinationChainId, '0x123', config);
} catch (error: any) {
throw new Error(`Should not have thrown an error, but threw ${error}`);
throw new Error(`Should not have thrown an error, but threw ${error}`, { cause: error });
}
});

Expand All @@ -147,7 +147,7 @@ describe('Validation', () => {
await checkReceiver(tokenSent, destinationChainId, '0x123', config);
expect(mockProvider.getCode).toHaveBeenCalledTimes(1);
} catch (error: any) {
throw new Error(`Should not have thrown an error, but threw ${error}`);
throw new Error(`Should not have thrown an error, but threw ${error}`, { cause: error });
}
});

Expand Down
9 changes: 6 additions & 3 deletions packages/internal/bridge/sdk/src/tokenBridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,14 @@ export class TokenBridge {
public async getFee(req: BridgeFeeRequest): Promise<BridgeFeeResponse> {
const [, , res] = await Promise.all([
this.initialise(),
async () => {
// Note the trailing `()`. This was previously passed as an uninvoked async
// function, so Promise.all resolved it to the function object and the
// chain-id validation never ran.
(async () => {
if (req.action !== BridgeFeeActions.FINALISE_WITHDRAWAL) {
await validateChainIds(req.sourceChainId, req.destinationChainId, this.config);
}
},
})(),
this.getFeePrivate(req),
]);
return res;
Expand Down Expand Up @@ -702,7 +705,7 @@ export class TokenBridge {
const [allowance, feeData, tenderlyRes] = await Promise.all([
this.getAllowance(direction, token, sender),
this.config.childProvider.getFeeData(),
await this.getDynamicWithdrawGasRootChain(
this.getDynamicWithdrawGasRootChain(
direction.destinationChainId,
sender,
recipient,
Expand Down
2 changes: 1 addition & 1 deletion packages/internal/dex/sdk/src/lib/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const provider = {
if (payload.to === USDC_TEST_TOKEN.address) {
return USDC_TEST_TOKEN.decimals.toString(16);
}
throw new Error(`Unrecognized ERC20: ${payload.to}`);
throw new Error(`Unrecognized ERC20: ${JSON.stringify(payload.to)}`);
}
throw new Error(`Call not supported: ${payload.data}`);
}),
Expand Down
4 changes: 2 additions & 2 deletions packages/orderbook/src/orderbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export class Orderbook {

if (config.overrides?.jsonRpcProviderUrl) {
finalConfig.provider = getConfiguredProvider(
config.overrides?.jsonRpcProviderUrl!,
config.overrides.jsonRpcProviderUrl,
config.baseConfig.rateLimitingKey,
);
}
Expand Down Expand Up @@ -778,7 +778,7 @@ export class Orderbook {

if (orderResult.status.name !== OrderStatusName.ACTIVE) {
throw new Error(
`Cannot fulfil order that is not active. Current status: ${orderResult.status}`,
`Cannot fulfil order that is not active. Current status: ${orderResult.status.name}`,
);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/src/magic/magicTEESigner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ export default class MagicTEESigner implements WalletSigner {
errorMessage += `: ${(error as Error).message}`;
}

throw new Error(errorMessage);
throw new Error(errorMessage, { cause: error });
}
}, 'magicSignMessage');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/wallet/src/zkEvm/relayerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class RelayerClient {
} catch (parseError) {
const preview = RelayerClient.getResponsePreview(responseText);
// eslint-disable-next-line max-len
throw new Error(`Relayer JSON parse error: ${parseError instanceof Error ? parseError.message : 'Unknown error'}. Content: "${preview}"`);
throw new Error(`Relayer JSON parse error: ${parseError instanceof Error ? parseError.message : 'Unknown error'}. Content: "${preview}"`, { cause: parseError });
}

if (jsonResponse.error) {
Expand Down
Loading