-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathfiatPluginTypes.ts
More file actions
250 lines (231 loc) · 7.27 KB
/
Copy pathfiatPluginTypes.ts
File metadata and controls
250 lines (231 loc) · 7.27 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
import { asValue } from 'cleaners'
import type { EdgeAccount } from 'edge-core-js'
import type {
EdgeAssetAction,
EdgeMetadata,
EdgeTokenId,
EdgeTransaction,
EdgeTxAction
} from 'edge-core-js/types'
import type { PluginPromotion } from 'edge-info-server'
import type { DisablePluginMap } from '../../actions/ExchangeInfoActions'
import type { LaunchPaymentProtoParams } from '../../actions/PaymentProtoActions'
import type {
ButtonInfo,
ButtonModalProps
} from '../../components/modals/ButtonsModal'
import type { SendScene2Params } from '../../components/scenes/SendScene2'
import type { Permission } from '../../reducers/PermissionsReducer'
import type { FiatProviderLink } from '../../types/DeepLinkTypes'
import type { HomeAddress, SepaInfo } from '../../types/FormTypes'
import type { GuiPlugin } from '../../types/GuiPluginTypes'
import type { AppParamList } from '../../types/routerTypes'
import type { EdgeAsset } from '../../types/types'
import type {
getHistoricalCryptoRate,
getHistoricalFiatRate
} from '../../util/exchangeRates'
import type {
BuyConversionValues,
SellConversionValues,
TrackingEventName,
TrackingValues
} from '../../util/tracking'
import type { FiatPluginAddressFormParams } from './scenes/AddressFormScene'
import type { FiatPluginOpenWebViewParams } from './scenes/FiatPluginWebView'
import type { FiatPluginSepaTransferParams } from './scenes/InfoDisplayScene'
import type { RewardsCardDashboardParams } from './scenes/RewardsCardDashboardScene'
import type { RewardsCardWelcomeParams } from './scenes/RewardsCardWelcomeScene'
import type { FiatPluginSepaFormParams } from './scenes/SepaFormScene'
export const asFiatDirection = asValue('buy', 'sell')
export type FiatDirection = ReturnType<typeof asFiatDirection>
export const asFiatPaymentType = asValue(
'ach',
'applepay',
'cash',
'colombiabank',
'credit',
'directtobank',
'fasterpayments',
'googlepay',
// TODO: Remove `iach` from the variants when old fiat plugin code has been gutted.
/** @deprecated because Instant ACH isn't different from regular ACH. Use `ach` instead. */
'iach',
'ideal',
'interac',
'iobank',
'klarna',
'mexicobank',
'payid',
'paypal',
'pix',
'pse',
'revolut',
'sepa',
'spei',
'turkishbank',
'venmo',
'wire'
)
export type FiatPaymentType = ReturnType<typeof asFiatPaymentType>
export type LinkHandler = (url: FiatProviderLink) => void | Promise<void>
export interface FiatPluginSepaTransferInfo {
input: {
amount: string
currency: string
}
output: {
amount: string
currency: string
walletAddress: string
}
paymentDetails: {
id: string
iban: string
swiftBic: string
recipient: string
reference: string
}
}
export interface FiatPluginListModalParams {
title: string
items: Array<{
icon: string | number | React.ReactNode
name: string
text?: string
}> // Icon strings are image uri, numbers are local files
selected?: string // Must match one of the name param in the items array
}
export interface FiatPluginEnterAmountResponse {
lastUsed: number
value1: string
value2: string
}
export interface FiatPluginOpenExternalWebViewParams {
url: string
/**
* Use a webview that is fully external to the app instead of any semi integrated
* webview like a SafariWebView. If set, this will not kill the app but only
* redirect to the external webview.
*/
redirectExternal?: boolean
/**
* @param url
* @returns void
*
* providerId is required if deeplinkHandler is provided
*/
deeplinkHandler?: LinkHandler
providerId?: string
}
export interface FiatPluginWalletPickerResult {
walletId: string
tokenId: EdgeTokenId
}
export interface SaveTxMetadataParams {
txid: string
walletId: string
tokenId: EdgeTokenId
metadata?: EdgeMetadata
}
export interface SaveTxActionParams {
txid: string
walletId: string
tokenId: EdgeTokenId
savedAction: EdgeTxAction
assetAction: EdgeAssetAction
}
export type FiatPluginPermissions = Permission[]
export interface FiatPluginUi {
addressWarnings: (parsedUri: any, currencyCode: string) => Promise<boolean>
buttonModal: <Buttons extends Record<string, ButtonInfo>>(
params: Omit<ButtonModalProps<Buttons>, 'bridge'>
) => Promise<keyof Buttons | undefined>
confirmation: (params: { title: string; message: string }) => Promise<void>
showToastSpinner: <T>(message: string, promise: Promise<T>) => Promise<T>
openWebView: (params: FiatPluginOpenWebViewParams) => Promise<void>
openExternalWebView: (
params: FiatPluginOpenExternalWebViewParams
) => Promise<void>
walletPicker: (params: {
headerTitle: string
allowedAssets?: EdgeAsset[]
showCreateWallet?: boolean
}) => Promise<FiatPluginWalletPickerResult | undefined>
showError: (error: unknown) => Promise<void>
listModal: (params: FiatPluginListModalParams) => Promise<string | undefined>
enterAmount: (params: AppParamList['guiPluginEnterAmount']) => void
emailForm: (params: {
message?: string
}) => Promise<
{ email: string; firstName: string; lastName: string } | undefined
>
addressForm: (
params: FiatPluginAddressFormParams
) => Promise<HomeAddress | undefined>
requestPermission: (
permissions: FiatPluginPermissions,
displayName: string,
mandatory: boolean
) => Promise<boolean>
rewardsCardDashboard: (params: RewardsCardDashboardParams) => Promise<void>
rewardsCardWelcome: (params: RewardsCardWelcomeParams) => Promise<void>
saveTxAction: (params: SaveTxActionParams) => Promise<void>
saveTxMetadata: (params: SaveTxMetadataParams) => Promise<void>
send: (params: SendScene2Params) => Promise<EdgeTransaction>
sendPaymentProto: (params: {
uri: string
params: LaunchPaymentProtoParams
}) => Promise<void>
sepaForm: (params: FiatPluginSepaFormParams) => Promise<SepaInfo | undefined>
sepaTransferInfo: (params: FiatPluginSepaTransferParams) => Promise<void>
setClipboard: (value: string) => Promise<void>
showToast: (message: string, autoHideMs?: number) => Promise<void>
trackConversion: (
event: TrackingEventName,
opts: {
conversionValues: SellConversionValues | BuyConversionValues
}
) => Promise<void>
exitScene: () => Promise<void>
waitForAnimationFrame: () => Promise<void>
}
export interface FiatPluginUtils {
getHistoricalCryptoRate: typeof getHistoricalCryptoRate
getHistoricalFiatRate: typeof getHistoricalFiatRate
}
export interface FiatPluginFactoryArgs {
// TODO:
// io: {
// log: EdgeLog, // scoped logs
// }
account: EdgeAccount
deviceId: string
disablePlugins: DisablePluginMap
longPress?: boolean
guiPlugin: GuiPlugin
showUi: FiatPluginUi
pluginUtils: FiatPluginUtils
onLogEvent: (event: TrackingEventName, values?: TrackingValues) => void
}
export interface FiatPluginRegionCode {
countryCode: string
stateProvinceCode?: string
}
export interface FiatPluginStartParams {
direction: 'buy' | 'sell'
defaultIsoFiat: string
paymentTypes: FiatPaymentType[]
regionCode: FiatPluginRegionCode
forceFiatCurrencyCode?: string
defaultFiatAmount?: string
pluginPromotions?: PluginPromotion[]
providerId?: string
}
export interface FiatPlugin {
pluginId: string
startPlugin: (params: FiatPluginStartParams) => Promise<void>
}
export type FiatPluginFactory = (
params: FiatPluginFactoryArgs
) => Promise<FiatPlugin>