Skip to content

Commit

Permalink
Merge branch 'main' into eg/docs-release-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericHgorski authored Oct 12, 2024
2 parents d706442 + 116dc6b commit 6c0b07e
Show file tree
Hide file tree
Showing 50 changed files with 713 additions and 637 deletions.
33 changes: 33 additions & 0 deletions examples/nextjs/pages/gobg-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions examples/nextjs/pages/gobg-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 30 additions & 9 deletions examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { SwapWidget } from '@skip-go/widget';
import { Widget } from '@skip-go/widget';
import { defaultTheme, lightTheme } from '@skip-go/widget';
import darkbg from './gobg-dark.svg';
import lightbg from './gobg-light.svg';

import { useState } from 'react';

const Home = () => {
const [theme, setTheme] = useState<"dark" | "light">("dark");
const [theme, setTheme] = useState<'dark' | 'light'>('dark');

const toggleTheme = () => {
if (theme === "dark") {
setTheme("light");
if (theme === 'dark') {
setTheme('light');
} else {
setTheme("dark");
setTheme('dark');
}
};

Expand All @@ -18,12 +21,30 @@ const Home = () => {
style={{
display: 'flex',
flexDirection: 'row',
padding: 20
width: '100vw',
height: '100vh',
alignItems: 'center',
justifyContent: 'center',
backgroundImage: `url('${theme === 'dark' ? darkbg.src : lightbg.src
}')`,
backgroundSize: 'cover',
backgroundPosition: 'bottom',
}}
>
<SwapWidget theme={theme === "dark" ? defaultTheme : lightTheme} />
<div>
<button onClick={() => toggleTheme()}> Toggle theme (current theme: {theme})</button>
<button
style={{ position: 'absolute', top: 0, right: 0 }}
onClick={() => toggleTheme()}
>
Toggle theme (current theme: {theme})
</button>
<div
style={{
position: 'absolute',
top: '50%',
transform: 'translateY(-185px)',
}}
>
<Widget theme={theme === 'dark' ? defaultTheme : lightTheme} />
</div>
</div>
);
Expand Down
146 changes: 63 additions & 83 deletions packages/client/src/client-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import { WalletClient } from 'viem';

import * as types from './types';
import { Adapter } from '@solana/wallet-adapter-base';
import { TransactionCallbacks } from './types';

/** Common Types */
export interface UserAddress {
chainID: string;
address: string;
Expand All @@ -26,12 +28,40 @@ export type EndpointOptions = {
rest?: string;
};

export interface SkipClientOptions {
apiURL?: string;
apiKey?: string;
/** Signer Getters */
export interface SignerGetters {
getEVMSigner?: (chainID: string) => Promise<WalletClient>;
getCosmosSigner?: (chainID: string) => Promise<OfflineSigner>;
getSVMSigner?: () => Promise<Adapter>;
}

/** Gas Options */
export type GetFallbackGasAmount = (
chainID: string,
chainType: types.ChainType
) => Promise<number | undefined>;

export type GetGasPrice = (
chainID: string,
chainType: types.ChainType
) => Promise<GasPrice | undefined>;

interface GasOptions {
/**
* If `getGasPrice` is undefined, or returns undefined, the router will attempt to set the recommended gas price
**/
getGasPrice?: GetGasPrice;
/**
* If `getFallbackGasAmount` is set, when router fails to simulate the gas amount, it will use the fallback gas amount
*/
getFallbackGasAmount?: GetFallbackGasAmount;
gasAmountMultiplier?: number;
}

/** Skip Client Options */
export interface SkipClientOptions extends SignerGetters {
apiURL?: string;
apiKey?: string;
endpointOptions?: {
endpoints?: Record<string, EndpointOptions>;
getRpcEndpointForChain?: (chainID: string) => Promise<string>;
Expand All @@ -42,55 +72,24 @@ export interface SkipClientOptions {
chainIDsToAffiliates?: Record<string, types.ChainAffiliates>;
}

export type ExecuteRouteOptions = {
route: types.RouteResponse;
/**
* addresses should be in the same order with the `chainIDs` in the `route`
/** Execute Route Options */
export type ExecuteRouteOptions = SignerGetters &
GasOptions &
types.TransactionCallbacks & {
route: types.RouteResponse;
/**
* Addresses should be in the same order with the `chainIDs` in the `route`
*/
userAddresses: UserAddress[];
validateGasBalance?: boolean;
slippageTolerancePercent?: string;
/**
* Arbitrary Tx to be executed before or after route msgs
*/
userAddresses: UserAddress[];
getEVMSigner?: (chainID: string) => Promise<WalletClient>;
getCosmosSigner?: (chainID: string) => Promise<OfflineSigner>;
getSVMSigner?: () => Promise<Adapter>;
onTransactionSigned?: (txInfo: {
txHash: string;
chainID: string;
}) => Promise<void>;
onTransactionBroadcast?: (txInfo: {
txHash: string;
chainID: string;
}) => Promise<void>;
onTransactionTracked?: (txInfo: {
txHash: string;
chainID: string;
explorerLink: string;
}) => Promise<void>;
onTransactionCompleted?: (
chainID: string,
txHash: string,
status: types.TxStatusResponse
) => Promise<void>;
onValidateGasBalance?: (value: {
chainID?: string;
txIndex?: number;
status: "success" | "error" | "pending" | "completed"
}) => Promise<void>;
validateGasBalance?: boolean;
slippageTolerancePercent?: string;
/**
* If `getGasPrice` is undefined, or returns undefined, the router will attempt to set the recommended gas price
**/
getGasPrice?: (chainID: string) => Promise<GasPrice | undefined>;
/**
* If `getFallbackGasAmount` is set, when router fails to simulate the gas amount, it will use the fallback gas amount
*/
getFallbackGasAmount?: GetFallbackGasAmount;
gasAmountMultiplier?: number;
/**
* Arbitrary Tx to be executed before or after route msgs
*/
beforeMsg?: types.CosmosMsg;
afterMsg?: types.CosmosMsg;
};
beforeMsg?: types.CosmosMsg;
afterMsg?: types.CosmosMsg;
};


export type ExecuteCosmosMessageOptions = {
signerAddress: string;
Expand All @@ -99,48 +98,29 @@ export type ExecuteCosmosMessageOptions = {
fee: StdFee;
};

export type ExecuteCosmosMessage = {
export type ExecuteCosmosMessage = GasOptions & {
signerAddress: string;
getCosmosSigner?: (chainID: string) => Promise<OfflineSigner>;
/**
* If `getGasPrice` is undefined, or returns undefined, the router will attempt to set the recommended gas price
**/
getGasPrice?: GetGasPrice;
/**
* If `getFallbackGasAmount` is set, when router fails to simulate the gas amount, it will use the fallback gas amount
*/
getFallbackGasAmount?: GetFallbackGasAmount;
getCosmosSigner?: SignerGetters['getCosmosSigner'];
chainID: string;
messages: types.CosmosMsg[];
gasAmountMultiplier?: number;
gasTokenUsed?: Coin;
onTransactionSigned?: ExecuteRouteOptions['onTransactionSigned'];
onTransactionSigned?: TransactionCallbacks['onTransactionSigned'];
};

export type SignCosmosMessageDirectOptions = {
interface SignCosmosMessageOptionsBase {
signerAddress: string;
signer: OfflineDirectSigner;
chainID: string;
cosmosMsgs: types.CosmosMsg[];
fee: StdFee;
signerData: SignerData;
};

export type SignCosmosMessageAminoOptions = {
signerAddress: string;
signer: OfflineAminoSigner;
chainID: string;
cosmosMsgs: types.CosmosMsg[];
fee: StdFee;
signerData: SignerData;
};
}

export type GetFallbackGasAmount = (
chainID: string,
chainType: 'cosmos' | 'evm' | 'svm'
) => Promise<number | undefined>;
export type SignCosmosMessageDirectOptions =
SignCosmosMessageOptionsBase & {
signer: OfflineDirectSigner;
};

export type GetGasPrice = (
chainID: string,
chainType: 'cosmos' | 'evm' | 'svm'
) => Promise<GasPrice | undefined>;
export type SignCosmosMessageAminoOptions =
SignCosmosMessageOptionsBase & {
signer: OfflineAminoSigner;
};
10 changes: 5 additions & 5 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ export class SkipClient {
getRestEndpointForChain?: (chainID: string) => Promise<string>;
};

protected getCosmosSigner?: (chainID: string) => Promise<OfflineSigner>;
protected getEVMSigner?: (chainID: string) => Promise<WalletClient>;
protected getSVMSigner?: () => Promise<Adapter>;
protected chainIDsToAffiliates?: Record<string, types.ChainAffiliates>;
protected getCosmosSigner?: clientTypes.SignerGetters['getCosmosSigner'];
protected getEVMSigner?: clientTypes.SignerGetters['getEVMSigner'];
protected getSVMSigner?: clientTypes.SignerGetters['getSVMSigner'];
protected chainIDsToAffiliates?: clientTypes.SkipClientOptions['chainIDsToAffiliates'];
protected cumulativeAffiliateFeeBPS?: string = '0';

constructor(options: clientTypes.SkipClientOptions = {}) {
Expand Down Expand Up @@ -774,7 +774,7 @@ export class SkipClient {
}: {
signer: Adapter;
message: types.SvmTx;
onTransactionSigned?: clientTypes.ExecuteRouteOptions['onTransactionSigned'];
onTransactionSigned?: types.TransactionCallbacks['onTransactionSigned'];
}) {
const _tx = Buffer.from(message.tx, 'base64');
const transaction = Transaction.from(_tx);
Expand Down
3 changes: 2 additions & 1 deletion packages/client/src/types/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ import {
BridgeJSON,
BridgesResponse,
BridgesResponseJSON,
ChainType,
EstimatedFee,
EstimatedFeeJSON,
Msg,
Expand Down Expand Up @@ -314,7 +315,7 @@ export function chainFromJSON(chainJSON: ChainJSON): Chain {
logoURI: chainJSON.logo_uri,
bech32Prefix: chainJSON.bech32_prefix,
feeAssets: chainJSON.fee_assets.map(feeAssetFromJSON),
chainType: chainJSON.chain_type,
chainType: chainJSON.chain_type as ChainType,
ibcCapabilities: ibcCapabilitiesFromJSON(chainJSON.ibc_capabilities),
isTestnet: chainJSON.is_testnet,
prettyName: chainJSON.pretty_name,
Expand Down
Loading

0 comments on commit 6c0b07e

Please sign in to comment.