-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathindex.d.ts
150 lines (133 loc) · 5.06 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { CSSProperties } from 'react';
import { Root } from 'react-dom/client';
import { createStore } from 'jotai';
import { Wallet } from '@jup-ag/wallet-adapter';
import { Connection, PublicKey, TransactionError } from '@solana/web3.js';
import { SwapResult } from '@jup-ag/react-hook';
import { WalletContextState } from '@jup-ag/wallet-adapter';
import EventEmitter from 'events';
import { QuoteResponse } from 'src/contexts/SwapContext';
import { SwapMode } from './constants';
declare global {
interface Window {
Jupiter: JupiterTerminal;
}
}
/** The position of the widget */
export type WidgetPosition = 'bottom-left' | 'bottom-right' | 'top-left' | 'top-right';
/** The size of the widget */
export type WidgetSize = 'sm' | 'default';
export type SwapMode = (typeof SwapMode)[keyof typeof SwapMode];
export interface FormProps {
/** Default to `ExactInOrOut`. ExactOut can be used to get an exact output of a token (e.g. for Payments) */
swapMode?: SwapMode;
/** Initial amount to swap */
initialAmount?: string;
/** When true, user cannot change the amount (e.g. for Payments) */
fixedAmount?: boolean;
/** Initial input token to swap */
initialInputMint?: string;
/** When true, user cannot change the input token */
fixedInputMint?: boolean;
/** Initial output token to swap */
initialOutputMint?: string;
/** When true, user cannot change the output token (e.g. to buy your project's token) */
fixedOutputMint?: boolean;
}
/** Built in support for these explorers */
export type DEFAULT_EXPLORER = 'Solana Explorer' | 'Solscan' | 'Solana Beach' | 'SolanaFM';
export interface TransactionInstruction {
accounts: {
pubkey: string;
isSigner: boolean;
isWritable: boolean;
}[];
data: string;
programId: string;
}
export interface IInit {
/** Settings saved in local storage will be prefixed with this
* You can reset your user's local storage by changing this value
*/
localStoragePrefix?: string;
/** Solana RPC, declare either endpoint, or Connection object */
/** Solana RPC endpoint */
endpoint?: string;
/** Solana RPC Connection object */
connectionObj?: Connection;
/** Configure Terminal's behaviour and allowed actions for your user */
formProps?: FormProps;
/** Only allow strict token by [Jupiter Token List API](https://station.jup.ag/docs/token-list/token-list-api) */
strictTokenList?: boolean;
/** Default explorer for your user */
defaultExplorer?: DEFAULT_EXPLORER;
/** Auto connect to wallet on subsequent visits */
autoConnect?: boolean;
/** RPC refetch interval for getTABO in milliseconds, defaults to 10000 */
refetchIntervalForTokenAccounts?: number;
/** Display & Styling */
/** Display mode */
displayMode?: 'modal' | 'integrated' | 'widget';
/** When displayMode is 'integrated', this is the id of the element to render the integrated widget into */
integratedTargetId?: string;
/** When displayMode is 'widget', this is the behaviour and style of the widget */
widgetStyle?: {
position?: WidgetPosition;
size?: WidgetSize;
};
/** In case additional styling is needed for Terminal container */
containerStyles?: CSSProperties;
/** In case additional styling is needed for Terminal container */
containerClassName?: string;
/** When true, wallet connection are handled by your dApp, and use `syncProps()` to syncronise wallet state with Terminal */
enableWalletPassthrough?: boolean;
/** Optional, if wallet state is ready, you can pass it in here, or just use `syncProps()` */
passthroughWalletContextState?: WalletContextState;
/** When enableWalletPassthrough is true, this allows Terminal to callback your dApp's wallet connection flow */
onRequestConnectWallet?: () => void | Promise<void>;
/** Callbacks */
/** When an error has occured during swap */
onSwapError?: ({
error,
quoteResponseMeta,
}: {
error?: TransactionError;
quoteResponseMeta: QuoteResponse | null;
}) => void;
/** When a swap has been successful */
onSuccess?: ({
txid,
swapResult,
quoteResponseMeta,
}: {
txid: string;
swapResult: SwapResult;
quoteResponseMeta: QuoteResponse | null;
}) => void;
/** Callback when there's changes to the form */
onFormUpdate?: (form: IForm) => void;
/** Callback when there's changes to the screen */
onScreenUpdate?: (screen: IScreen) => void;
/** Internal resolves */
/** Internal use to resolve domain when loading script */
scriptDomain?: string;
}
export interface JupiterTerminal {
_instance: JSX.Element | null;
init: (props: IInit) => void;
resume: () => void;
close: () => void;
root: Root | null;
/** Passthrough */
enableWalletPassthrough: boolean;
onRequestConnectWallet: IInit['onRequestConnectWallet'];
store: ReturnType<typeof createStore>;
syncProps: (props: { passthroughWalletContextState?: IInit['passthroughWalletContextState'] }) => void;
/** Callbacks */
onSwapError: IInit['onSwapError'];
onSuccess: IInit['onSuccess'];
onFormUpdate: IInit['onFormUpdate'];
onScreenUpdate: IInit['onScreenUpdate'];
/** Special props */
localStoragePrefix: string;
}