Skip to content

Commit b8a3bea

Browse files
authored
fix: bump version of widget-lib + iframe-transport (#7493)
* fix: bump version of widget-lib + iframe-transport * chore: add jsdock * chore: fix
1 parent ee578b4 commit b8a3bea

3 files changed

Lines changed: 48 additions & 5 deletions

File tree

libs/iframe-transport/src/iframeRpcProvider/IframeRpcProviderBridge.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,28 @@ import { getEip6963ProviderInfo, getProviderWcMetadata } from './utils'
1010

1111
import type { EthereumProvider, JsonRpcRequestMessage } from '../types'
1212

13-
type EthereumProviderWithRemoveListener = EthereumProvider & {
13+
/**
14+
* An {@link EthereumProvider} that may also expose `removeListener` for
15+
* subscription cleanup.
16+
*
17+
* EIP-1193 standardizes `on(event, handler)` for subscribing to provider
18+
* events but does not formally specify the removal counterpart. Most wallet
19+
* providers (MetaMask, Rabby, Coinbase Wallet, WalletConnect) implement
20+
* `removeListener` to match Node's `EventEmitter` API, but it is not
21+
* guaranteed. Use this type — or a `typeof provider.removeListener ===
22+
* 'function'` runtime check — to narrow before calling it.
23+
*
24+
* Within this library it is used by {@link IframeRpcProviderBridge.disconnect}
25+
* to detach the forwarded `connect` / `disconnect` / `chainChanged` /
26+
* `accountsChanged` listeners before dropping the provider reference,
27+
* preventing stale handlers from firing against the parent dapp.
28+
*/
29+
export type EthereumProviderWithRemoveListener = EthereumProvider & {
1430
removeListener?(event: string, handler: (...args: unknown[]) => void): void
1531
}
1632

1733
const EVENTS_TO_FORWARD_TO_IFRAME = ['connect', 'disconnect', 'close', 'chainChanged', 'accountsChanged']
34+
1835
const eip6963Providers: EIP6963ProviderDetail[] = []
1936

2037
if (typeof window !== 'undefined') {

libs/iframe-transport/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export { IframeRpcProviderBridge } from './iframeRpcProvider/IframeRpcProviderBridge'
2+
export type { EthereumProviderWithRemoveListener } from './iframeRpcProvider/IframeRpcProviderBridge'
23
export { WidgetEthereumProvider } from './iframeRpcProvider/WidgetEthereumProvider'
34
export { IframeTransport } from './IframeTransport'
45
export { getParentOrigin } from './getParentOrigin'

libs/widget-lib/src/types.ts

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ export type FlexibleConfig<T> =
2020
| PerTradeTypeConfig<PerNetworkConfig<T>>
2121
| PerNetworkConfig<PerTradeTypeConfig<T>>
2222

23+
/**
24+
* A single forbidden sell→buy token combination for the widget.
25+
*
26+
* Used as an entry in {@link CowSwapWidgetParams.tokenPairConstraints} to
27+
* prevent users from creating orders that swap the given `sell` token for
28+
* the given `buy` token (in that direction). Reversing the direction —
29+
* trading `buy` for `sell` — is **not** blocked unless an explicit entry
30+
* for the reverse pair is also supplied.
31+
*
32+
* Addresses are matched case-insensitively against the user's selected
33+
* tokens; `chainId` must match the active widget chain for the entry to
34+
* apply.
35+
*
36+
* @example
37+
* ```ts
38+
* tokenPairConstraints: [
39+
* {
40+
* sell: { address: '0xA0b8...eB48', chainId: SupportedChainId.MAINNET },
41+
* buy: { address: '0xdAC1...1ec7', chainId: SupportedChainId.MAINNET },
42+
* },
43+
* ]
44+
* ```
45+
*/
46+
export type TokenPairConstraint = {
47+
sell: { address: string; chainId: SupportedChainId }
48+
buy: { address: string; chainId: SupportedChainId }
49+
}
50+
2351
export enum WidgetMethodsEmit {
2452
ACTIVATE = 'ACTIVATE',
2553
READY = 'READY',
@@ -453,10 +481,7 @@ export interface CowSwapWidgetParams {
453481
/**
454482
* Disables trading of specific token pair
455483
*/
456-
tokenPairConstraints?: {
457-
sell: { address: string; chainId: SupportedChainId }
458-
buy: { address: string; chainId: SupportedChainId }
459-
}[]
484+
tokenPairConstraints?: TokenPairConstraint[]
460485

461486
hooks?: Partial<{
462487
onBeforeApproval(payload: OnApprovalPayload): WidgetHookResult

0 commit comments

Comments
 (0)