Skip to content
Closed
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
26 changes: 7 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@wormhole-labs/cctp-executor-route": "0.12.0",
"@wormhole-labs/wallet-aggregator-aptos": "1.3.0",
"@wormhole-labs/wallet-aggregator-core": "0.0.1",
"@wormhole-labs/wallet-aggregator-evm": "0.8.0",
"@wormhole-labs/wallet-aggregator-evm": "0.9.0",
"@wormhole-labs/wallet-aggregator-solana": "0.0.1",
"@wormhole-labs/wallet-aggregator-sui": "0.0.3",
"axios": "1.11.0",
Expand Down
11 changes: 4 additions & 7 deletions src/config/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,11 @@ export type Experimental = {
[Experiment in Experiments]?: boolean;
};

export interface ChainTokenPair {
chain: Chain;
token?: string;
}

export interface DefaultInputs {
source?: ChainTokenPair;
destination?: ChainTokenPair;
fromChain?: Chain;
toChain?: Chain;
fromToken?: string; // Address or symbol
toToken?: string; // Address or symbol
requiredChain?: Chain;
preferredRouteName?: string;
}
Expand Down
53 changes: 24 additions & 29 deletions src/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,77 +135,72 @@ export const validateDefaults = (
tokens: TokenCache,
) => {
if (!defaults) return;
if (defaults.source?.chain) {
const chain = chains[defaults.source.chain];
if (defaults.fromChain) {
const chain = chains[defaults.fromChain];
if (!chain) {
error(
`Invalid chain name "${defaults.source.chain}" specified for defaultInputs.source.chain`,
`Invalid chain name "${defaults.fromChain}" specified for defaultInputs.fromChain`,
);
delete defaults.source;
delete defaults.fromChain;
}
}
if (defaults.destination?.chain) {
const chain = chains[defaults.destination.chain];
if (defaults.toChain) {
const chain = chains[defaults.toChain];
if (!chain) {
error(
`Invalid chain name "${defaults.destination.chain}" specified for defaultInputs.destination.chain`,
`Invalid chain name "${defaults.toChain}" specified for defaultInputs.toChain`,
);
delete defaults.destination;
delete defaults.fromChain;
}
}

if (defaults.source?.token && defaults.destination?.token) {
if (defaults.source.token === defaults.destination.token) {
if (defaults.fromChain && defaults.toChain) {
if (defaults.fromChain === defaults.toChain) {
error(
`Source and destination token cannot be the same, check the defaultInputs configuration`,
`Source and destination chain cannot be the same, check the defaultInputs configuration`,
);
}
}

if (
defaults.source?.chain &&
defaults.destination?.chain &&
defaults.requiredChain
) {
if (defaults.fromChain && defaults.toChain && defaults.requiredChain) {
const requiredConfig = chains[defaults.requiredChain];
if (!requiredConfig) {
error(
`Invalid network value "${defaults.requiredChain}" specified for defaultInputs.requiredChain`,
);
}
if (
defaults.destination.chain !== defaults.requiredChain &&
defaults.source.chain !== defaults.requiredChain
defaults.toChain !== defaults.requiredChain &&
defaults.fromChain !== defaults.requiredChain
) {
error(
`Source chain or destination chain must equal the required network`,
);
}
}

if (defaults.source?.chain && defaults.source?.token) {
if (defaults.fromChain && defaults.fromToken) {
const token = tokens.findByAddressOrSymbol(
defaults.source.chain,
defaults.source.token,
defaults.fromChain,
defaults.fromToken,
);
if (!token) {
error(
`Invalid token "${defaults.source?.token}" specified for defaultInputs.fromToken`,
`Invalid token "${defaults.fromToken}" specified for defaultInputs.fromToken`,
);
delete defaults.source.token;
delete defaults.fromToken;
}
}

if (defaults.destination?.chain && defaults.destination?.token) {
if (defaults.toChain && defaults.toToken) {
const token = tokens.findByAddressOrSymbol(
defaults.destination.chain,
defaults.destination.token,
defaults.toChain,
defaults.toToken,
);
if (!token) {
error(
`Invalid token "${defaults.destination?.token}" specified for defaultInputs.toToken`,
`Invalid token "${defaults.toToken}" specified for defaultInputs.toToken`,
);
delete defaults.destination.token;
delete defaults.toToken;
}
}

Expand Down
12 changes: 5 additions & 7 deletions src/store/transferInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,15 @@ export interface TransferInputState {

// This is a function because config might have changed since we last cleared this store
function getInitialState(): TransferInputState {
const { source, destination } = config.ui.defaultInputs || {};
const fromChain = source?.chain;
const fromToken = source?.token;
const toChain = destination?.chain;
const toToken = destination?.token;
const { fromChain, toChain, fromToken, toToken } =
config.ui.defaultInputs || {};

const fromTokenTuple =
fromToken && fromChain
fromChain && fromToken
? config.tokens.findByAddressOrSymbol(fromChain, fromToken)?.tuple
: undefined;
const toTokenTuple =
toToken && toChain
toChain && toToken
? config.tokens.findByAddressOrSymbol(toChain, toToken)?.tuple
: undefined;

Expand Down
31 changes: 1 addition & 30 deletions src/telemetry/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Chain, amount as sdkAmount } from '@wormhole-foundation/sdk';
import type { WormholeConnectConfig } from 'config/types';
import type { Token } from 'config/tokens';
import type { TransferWallet } from 'utils/wallet';

export interface LoadEvent {
Expand Down Expand Up @@ -104,41 +103,13 @@ export interface HistoryLoadEvent {
};
}

export enum UserActions {
SelectSrcToken = 'select.src.token',
SelectSrcChain = 'select.src.chain',
SelectDestToken = 'select.dest.token',
SelectDestChain = 'select.dest.chain',
}

type UserActionValueMap = {
[UserActions.SelectSrcToken]: Token;
[UserActions.SelectDestToken]: Token;
[UserActions.SelectSrcChain]: Chain;
[UserActions.SelectDestChain]: Chain;
};

export type UserActionEvent<A extends UserActions = UserActions> = {
type: 'user.action';
details: {
action: A;
value: UserActionValueMap[A];
};
};

// Helper type to narrow value by action
export type UserActionEvents = {
[A in UserActions]: UserActionEvent<A>;
}[UserActions];

export type WormholeConnectEventCore =
| LoadEvent
| UpdateConfigEvent
| TransferEvent
| TransferErrorEvent
| ConnectWalletEvent
| HistoryLoadEvent
| UserActionEvent;
| HistoryLoadEvent;

export interface WormholeConnectEventMeta {
meta: {
Expand Down
34 changes: 0 additions & 34 deletions src/telemetry/utils.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/views/v2/Bridge/AssetPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ import AssetBadge from 'components/AssetBadge';
import type { Token } from 'config/tokens';
import { useTokenList } from 'hooks/useTokenList';
import { getTokenSymbol } from 'utils';
import {
handleTelemetryOnChainSelect,
handleTelemetryOnTokenSelect,
} from 'telemetry/utils';

type Props = {
chain?: Chain | undefined;
Expand Down Expand Up @@ -274,7 +270,6 @@ const AssetPicker = (props: Props) => {
setShowSearch={setShowChainSearch}
wallet={props.wallet}
onChainSelect={(key) => {
handleTelemetryOnChainSelect(key, props.isSource);
props.setChain(key);
setSearchQuery('');
}}
Expand All @@ -295,8 +290,6 @@ const AssetPicker = (props: Props) => {
searchQuery={searchQuery}
onSearchQueryChange={setSearchQuery}
onSelectToken={(key: Token) => {
handleTelemetryOnTokenSelect(key, props.isSource);
handleTelemetryOnChainSelect(key.chain, props.isSource);
props.setToken(key);
setIsDrawerOpen(false);
}}
Expand Down Expand Up @@ -330,7 +323,6 @@ const AssetPicker = (props: Props) => {
setShowSearch={setShowChainSearch}
wallet={props.wallet}
onChainSelect={(key) => {
handleTelemetryOnChainSelect(key, props.isSource);
props.setChain(key);
setSearchQuery('');
}}
Expand All @@ -351,8 +343,6 @@ const AssetPicker = (props: Props) => {
searchQuery={searchQuery}
onSearchQueryChange={setSearchQuery}
onSelectToken={(key: Token) => {
handleTelemetryOnTokenSelect(key, props.isSource);
handleTelemetryOnChainSelect(key.chain, props.isSource);
props.setToken(key);
popupState.close();
}}
Expand Down
7 changes: 0 additions & 7 deletions src/views/v3/Bridge/AssetPicker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ import AssetPickerDrawer from 'views/v3/Bridge/AssetPicker/PickerBottomSheet';
import AssetPickerPopover from 'views/v3/Bridge/AssetPicker/PickerModal';
import { calculateUSDPrice, getTokenSymbol } from 'utils';
import { formatWithCommas } from 'utils/formatNumber';
import {
handleTelemetryOnChainSelect,
handleTelemetryOnTokenSelect,
} from 'telemetry/utils';

type Props = {
chain?: Chain | undefined;
Expand Down Expand Up @@ -301,7 +297,6 @@ function AssetPicker(props: Props) {

const handleChainSelect = useCallback(
(chain: Chain) => {
handleTelemetryOnChainSelect(chain, props.isSource);
props.setChain(chain);
setSearchQuery('');
},
Expand All @@ -310,8 +305,6 @@ function AssetPicker(props: Props) {

const handleTokenSelect = useCallback(
(token: Token) => {
handleTelemetryOnTokenSelect(token, props.isSource);
handleTelemetryOnChainSelect(token.chain, props.isSource);
if (props.isSource && props.token?.key !== token.key) {
// Reset amount when source token is changed
handleAmountChange('');
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
],
"compilerOptions": {
"baseUrl": "src",
"allowImportingTsExtensions": true,
"declaration": true,
"declarationMap": true,
"esModuleInterop": true,
Expand Down
Loading