-
Notifications
You must be signed in to change notification settings - Fork 103
Expand file tree
/
Copy pathindex.d.ts
More file actions
148 lines (130 loc) · 4.55 KB
/
index.d.ts
File metadata and controls
148 lines (130 loc) · 4.55 KB
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
import { CSSProperties } from 'react';
import { Root } from 'react-dom/client';
import { createStore } from 'jotai';
import { Wallet } from '@jup-ag/wallet-adapter';
import { Connection, PublicKey } from '@solana/web3.js';
import { WalletContextState } from '@jup-ag/wallet-adapter';
import EventEmitter from 'events';
import { QuoteResponse, SwapResult } from 'src/contexts/SwapContext';
import { TransactionError } from './TransactionError';
declare global {
interface Window {
Jupiter: JupiterPlugin;
}
}
/** 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 = 'ExactInOrOut' | 'ExactIn' | 'ExactOut';
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;
/** Initial output token to swap */
initialOutputMint?: string;
/** Based token that can never changed */
fixedMint?: string;
/** Referral account to use for the swap */
referralAccount?: string;
/** Referral fee to use for the swap */
referralFee?: number;
/** Exclude DEXes */
excludeDexes?: string[];
}
/** Built in support for these explorers */
export type DEFAULT_EXPLORER = 'Solana Explorer' | 'Solscan' | 'Solana Beach' | 'SolanaFM' | 'OrbMarkets';
export interface TransactionInstruction {
accounts: {
pubkey: string;
isSigner: boolean;
isWritable: boolean;
}[];
data: string;
programId: string;
}
export interface IInit {
/** Configure Plugin's behaviour and allowed actions for your user */
formProps?: FormProps;
/** Default explorer for your user */
defaultExplorer?: DEFAULT_EXPLORER;
/** Auto connect to wallet on subsequent visits */
autoConnect?: boolean;
/** 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;
offset?: {
x?: number;
y?: number;
};
};
/** In case additional styling is needed for Plugin container */
containerStyles?: CSSProperties;
/** In case additional styling is needed for Plugin container */
containerClassName?: string;
/** When true, wallet connection are handled by your dApp, and use `syncProps()` to syncronise wallet state with Plugin */
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 Plugin to callback your dApp's wallet connection flow */
onRequestConnectWallet?: () => void | Promise<void>;
/** Branding */
branding?: {
logoUri?: string;
name?: string;
};
/** 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 JupiterPlugin {
_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'];
}