forked from keybase/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wallets.js
664 lines (605 loc) · 26.5 KB
/
wallets.js
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
// @flow
import * as Constants from '../constants/wallets'
import * as Types from '../constants/types/wallets'
import * as RPCStellarTypes from '../constants/types/rpc-stellar-gen'
import * as RPCTypes from '../constants/types/rpc-gen'
import * as Saga from '../util/saga'
import * as WalletsGen from './wallets-gen'
import * as Chat2Gen from './chat2-gen'
import * as ConfigGen from './config-gen'
import * as NotificationsGen from './notifications-gen'
import * as RouteTreeGen from './route-tree-gen'
import HiddenString from '../util/hidden-string'
import * as Route from './route-tree'
import logger from '../logger'
import type {TypedState} from '../constants/reducer'
import {getPath} from '../route-tree'
import * as Tabs from '../constants/tabs'
import * as SettingsConstants from '../constants/settings'
import flags from '../util/feature-flags'
import {getEngine} from '../engine'
import {anyWaiting} from '../constants/waiting'
import {RPCError} from '../util/errors'
import {isMobile} from '../constants/platform'
const build = (state: TypedState, action: any) =>
(state.wallets.building.isRequest
? RPCStellarTypes.localBuildRequestLocalRpcPromise(
{
amount: state.wallets.building.amount,
currency: state.wallets.building.currency === 'XLM' ? null : state.wallets.building.currency,
secretNote: state.wallets.building.secretNote.stringValue(),
to: state.wallets.building.to,
},
Constants.buildPaymentWaitingKey
).then(build =>
WalletsGen.createBuiltRequestReceived({
build: Constants.buildRequestResultToBuiltRequest(build),
forBuilding: state.wallets.building,
})
)
: RPCStellarTypes.localBuildPaymentLocalRpcPromise(
{
amount: state.wallets.building.amount,
currency: state.wallets.building.currency === 'XLM' ? null : state.wallets.building.currency,
fromPrimaryAccount: state.wallets.building.from === Types.noAccountID,
from: state.wallets.building.from === Types.noAccountID ? '' : state.wallets.building.from,
fromSeqno: '',
publicMemo: state.wallets.building.publicMemo.stringValue(),
secretNote: state.wallets.building.secretNote.stringValue(),
to: state.wallets.building.to,
toIsAccountID:
state.wallets.building.recipientType !== 'keybaseUser' &&
!Constants.isFederatedAddress(state.wallets.building.to),
},
Constants.buildPaymentWaitingKey
).then(build =>
WalletsGen.createBuiltPaymentReceived({
build: Constants.buildPaymentResultToBuiltPayment(build),
forBuilding: state.wallets.building,
})
)
).catch(error => {
if (error instanceof RPCError && error.code === RPCTypes.constantsStatusCode.sccanceled) {
// ignore cancellation
} else {
throw error
}
})
const openSendRequestForm = (state: TypedState, action: WalletsGen.OpenSendRequestFormPayload) =>
state.wallets.acceptedDisclaimer
? Saga.sequentially(
[
WalletsGen.createClearBuilding(),
action.payload.isRequest
? WalletsGen.createClearBuiltRequest()
: WalletsGen.createClearBuiltPayment(),
WalletsGen.createSetBuildingAmount({amount: action.payload.amount || ''}),
WalletsGen.createSetBuildingCurrency({currency: action.payload.currency || 'XLM'}),
WalletsGen.createLoadDisplayCurrency({
accountID: action.payload.from || Types.noAccountID,
setBuildingCurrency: !action.payload.currency,
}),
WalletsGen.createLoadDisplayCurrencies(),
WalletsGen.createSetBuildingFrom({from: action.payload.from || Types.noAccountID}),
WalletsGen.createSetBuildingIsRequest({isRequest: !!action.payload.isRequest}),
WalletsGen.createSetBuildingPublicMemo({
publicMemo: action.payload.publicMemo || new HiddenString(''),
}),
WalletsGen.createSetBuildingRecipientType({
recipientType: action.payload.recipientType || 'keybaseUser',
}),
WalletsGen.createSetBuildingSecretNote({
secretNote: action.payload.secretNote || new HiddenString(''),
}),
WalletsGen.createSetBuildingTo({to: action.payload.to || ''}),
RouteTreeGen.createNavigateAppend({
path: [Constants.sendReceiveFormRouteKey],
}),
].map(a => Saga.put(a))
)
: Saga.put(
isMobile
? Route.navigateTo([Tabs.settingsTab, SettingsConstants.walletsTab])
: Route.switchTo([Tabs.walletsTab])
)
const createNewAccount = (state: TypedState, action: WalletsGen.CreateNewAccountPayload) => {
const {name} = action.payload
return RPCStellarTypes.localCreateWalletAccountLocalRpcPromise({name}, Constants.createNewAccountWaitingKey)
.then(accountIDString => Types.stringToAccountID(accountIDString))
.then(accountID =>
WalletsGen.createCreatedNewAccount({
accountID,
showOnCreation: action.payload.showOnCreation,
setBuildingTo: action.payload.setBuildingTo,
})
)
.catch(err => {
logger.warn(`Error creating new account: ${err.desc}`)
return WalletsGen.createCreatedNewAccountError({error: err.desc, name})
})
}
const emptyAsset = {type: 'native', code: '', issuer: '', issuerName: '', verifiedDomain: ''}
const sendPayment = (state: TypedState) => {
const notXLM = state.wallets.building.currency !== '' && state.wallets.building.currency !== 'XLM'
return RPCStellarTypes.localSendPaymentLocalRpcPromise(
{
amount: notXLM ? state.wallets.builtPayment.worthAmount : state.wallets.building.amount,
// FIXME -- support other assets.
asset: emptyAsset,
from: state.wallets.builtPayment.from,
fromSeqno: '',
publicMemo: state.wallets.building.publicMemo.stringValue(),
quickReturn: true,
secretNote: state.wallets.building.secretNote.stringValue(),
to: state.wallets.building.to,
toIsAccountID:
state.wallets.building.recipientType !== 'keybaseUser' &&
!Constants.isFederatedAddress(state.wallets.building.to),
worthAmount: notXLM ? state.wallets.building.amount : state.wallets.builtPayment.worthAmount,
worthCurrency: state.wallets.builtPayment.worthCurrency,
},
Constants.sendPaymentWaitingKey
)
.then(res => WalletsGen.createSentPayment({kbTxID: new HiddenString(res.kbTxID)}))
.catch(err => WalletsGen.createSentPaymentError({error: err.desc}))
}
const requestPayment = (state: TypedState) =>
RPCStellarTypes.localMakeRequestLocalRpcPromise(
{
amount: state.wallets.building.amount,
// FIXME -- support other assets.
asset: state.wallets.building.currency === 'XLM' ? emptyAsset : undefined,
currency:
state.wallets.building.currency && state.wallets.building.currency !== 'XLM'
? state.wallets.building.currency
: undefined,
recipient: state.wallets.building.to,
note: state.wallets.building.secretNote.stringValue(),
},
Constants.requestPaymentWaitingKey
).then(kbRqID => WalletsGen.createRequestedPayment({kbRqID: new HiddenString(kbRqID)}))
const clearBuiltPayment = () => Saga.put(WalletsGen.createClearBuiltPayment())
const clearBuiltRequest = () => Saga.put(WalletsGen.createClearBuiltRequest())
const clearBuilding = () => Saga.put(WalletsGen.createClearBuilding())
const clearErrors = () => Saga.put(WalletsGen.createClearErrors())
const loadWalletSettings = () =>
RPCStellarTypes.localGetWalletSettingsLocalRpcPromise().then(settings =>
WalletsGen.createWalletSettingsReceived({settings})
)
const loadAccount = (state: TypedState, action: WalletsGen.BuiltPaymentReceivedPayload) => {
const {from: _accountID} = action.payload.build
const accountID = Types.stringToAccountID(_accountID)
// Don't load the account if we already have a call doing this
const waitingKey = Constants.loadAccountWaitingKey(accountID)
if (!Constants.isAccountLoaded(state, accountID) && !anyWaiting(state, waitingKey)) {
return RPCStellarTypes.localGetWalletAccountLocalRpcPromise({accountID: accountID}, waitingKey).then(
account => WalletsGen.createAccountsReceived({accounts: [Constants.accountResultToAccount(account)]})
)
}
}
const loadAccounts = (
state: TypedState,
action:
| WalletsGen.LoadAccountsPayload
| WalletsGen.LinkedExistingAccountPayload
| WalletsGen.RefreshPaymentsPayload
| WalletsGen.DidSetAccountAsDefaultPayload
| ConfigGen.LoggedInPayload
) =>
!action.error &&
RPCStellarTypes.localGetWalletAccountsLocalRpcPromise().then(res =>
WalletsGen.createAccountsReceived({
accounts: (res || []).map(account => Constants.accountResultToAccount(account)),
})
)
const loadAssets = (
state: TypedState,
action:
| WalletsGen.LoadAssetsPayload
| WalletsGen.SelectAccountPayload
| WalletsGen.LinkedExistingAccountPayload
| WalletsGen.RefreshPaymentsPayload
) =>
!action.error &&
RPCStellarTypes.localGetAccountAssetsLocalRpcPromise({accountID: action.payload.accountID}).then(res =>
WalletsGen.createAssetsReceived({
accountID: action.payload.accountID,
assets: (res || []).map(assets => Constants.assetsResultToAssets(assets)),
})
)
const createPaymentsReceived = (accountID, payments, pending) =>
WalletsGen.createPaymentsReceived({
accountID,
oldestUnread: payments.oldestUnread
? Types.rpcPaymentIDToPaymentID(payments.oldestUnread)
: Types.noPaymentID,
paymentCursor: payments.cursor,
payments: (payments.payments || [])
.map(elem => Constants.rpcPaymentResultToPaymentResult(elem, 'history'))
.filter(Boolean),
pending: (pending || [])
.map(elem => Constants.rpcPaymentResultToPaymentResult(elem, 'pending'))
.filter(Boolean),
})
const loadPayments = (
state: TypedState,
action:
| WalletsGen.LoadPaymentsPayload
| WalletsGen.SelectAccountPayload
| WalletsGen.LinkedExistingAccountPayload
| WalletsGen.RefreshPaymentsPayload
) =>
!action.error &&
Promise.all([
RPCStellarTypes.localGetPendingPaymentsLocalRpcPromise({accountID: action.payload.accountID}),
RPCStellarTypes.localGetPaymentsLocalRpcPromise({accountID: action.payload.accountID}),
]).then(([pending, payments]) => createPaymentsReceived(action.payload.accountID, payments, pending))
const loadMorePayments = (state: TypedState, action: WalletsGen.LoadMorePaymentsPayload) => {
const cursor = state.wallets.paymentCursorMap.get(action.payload.accountID)
return (
cursor &&
RPCStellarTypes.localGetPaymentsLocalRpcPromise({accountID: action.payload.accountID, cursor}).then(
payments => createPaymentsReceived(action.payload.accountID, payments, [])
)
)
}
const loadDisplayCurrencies = (state: TypedState, action: WalletsGen.LoadDisplayCurrenciesPayload) =>
RPCStellarTypes.localGetDisplayCurrenciesLocalRpcPromise().then(res =>
WalletsGen.createDisplayCurrenciesReceived({
currencies: (res || []).map(c => Constants.currenciesResultToCurrencies(c)),
})
)
const loadSendAssetChoices = (state: TypedState, action: WalletsGen.LoadSendAssetChoicesPayload) =>
RPCStellarTypes.localGetSendAssetChoicesLocalRpcPromise({
from: action.payload.from,
to: action.payload.to,
}).then(res => {
res && WalletsGen.createSendAssetChoicesReceived({sendAssetChoices: res})
})
const loadDisplayCurrency = (state: TypedState, action: WalletsGen.LoadDisplayCurrencyPayload) => {
let accountID = action.payload.accountID
if (accountID && !Types.isValidAccountID(accountID)) {
accountID = null
}
return RPCStellarTypes.localGetDisplayCurrencyLocalRpcPromise({
accountID: accountID,
}).then(res =>
WalletsGen.createDisplayCurrencyReceived({
accountID: accountID,
currency: Constants.makeCurrencies(res),
setBuildingCurrency: action.payload.setBuildingCurrency,
})
)
}
const changeDisplayCurrency = (state: TypedState, action: WalletsGen.ChangeDisplayCurrencyPayload) =>
RPCStellarTypes.localChangeDisplayCurrencyLocalRpcPromise(
{
accountID: action.payload.accountID,
currency: action.payload.code, // called currency, though it is a code
},
Constants.changeDisplayCurrencyWaitingKey
).then(res => WalletsGen.createLoadDisplayCurrency({accountID: action.payload.accountID}))
const changeAccountName = (state: TypedState, action: WalletsGen.ChangeAccountNamePayload) =>
RPCStellarTypes.localChangeWalletAccountNameLocalRpcPromise(
{
accountID: action.payload.accountID,
newName: action.payload.name,
},
Constants.changeAccountNameWaitingKey
).then(res => WalletsGen.createChangedAccountName({accountID: action.payload.accountID}))
const deleteAccount = (state: TypedState, action: WalletsGen.DeleteAccountPayload) =>
RPCStellarTypes.localDeleteWalletAccountLocalRpcPromise(
{
accountID: action.payload.accountID,
userAcknowledged: 'yes',
},
Constants.deleteAccountWaitingKey
).then(res => WalletsGen.createDeletedAccount())
const setAccountAsDefault = (state: TypedState, action: WalletsGen.SetAccountAsDefaultPayload) =>
RPCStellarTypes.localSetWalletAccountAsDefaultLocalRpcPromise(
{
accountID: action.payload.accountID,
},
Constants.setAccountAsDefaultWaitingKey
).then(res => WalletsGen.createDidSetAccountAsDefault({accountID: action.payload.accountID}))
const loadPaymentDetail = (state: TypedState, action: WalletsGen.LoadPaymentDetailPayload) =>
RPCStellarTypes.localGetPaymentDetailsLocalRpcPromise({
accountID: action.payload.accountID,
id: Types.paymentIDToRPCPaymentID(action.payload.paymentID),
}).then(res =>
WalletsGen.createPaymentDetailReceived({
accountID: action.payload.accountID,
payment: Constants.rpcPaymentDetailToPaymentDetail(res),
})
)
const markAsRead = (state: TypedState, action: WalletsGen.MarkAsReadPayload) =>
RPCStellarTypes.localMarkAsReadLocalRpcPromise({
accountID: action.payload.accountID,
mostRecentID: Types.paymentIDToRPCPaymentID(action.payload.mostRecentID),
})
const linkExistingAccount = (state: TypedState, action: WalletsGen.LinkExistingAccountPayload) => {
const {name, secretKey} = action.payload
return RPCStellarTypes.localLinkNewWalletAccountLocalRpcPromise(
{
name,
secretKey: secretKey.stringValue(),
},
Constants.linkExistingWaitingKey
)
.then(accountIDString => Types.stringToAccountID(accountIDString))
.then(accountID =>
WalletsGen.createLinkedExistingAccount({
accountID,
showOnCreation: action.payload.showOnCreation,
setBuildingTo: action.payload.setBuildingTo,
})
)
.catch(err => {
logger.warn(`Error linking existing account: ${err.desc}`)
return WalletsGen.createLinkedExistingAccountError({error: err.desc, name, secretKey})
})
}
const validateAccountName = (state: TypedState, action: WalletsGen.ValidateAccountNamePayload) => {
const {name} = action.payload
return RPCStellarTypes.localValidateAccountNameLocalRpcPromise({name})
.then(() => WalletsGen.createValidatedAccountName({name}))
.catch(err => {
logger.warn(`Error validating account name: ${err.desc}`)
return WalletsGen.createValidatedAccountNameError({error: err.desc, name})
})
}
const validateSecretKey = (state: TypedState, action: WalletsGen.ValidateSecretKeyPayload) => {
const {secretKey} = action.payload
return RPCStellarTypes.localValidateSecretKeyLocalRpcPromise({secretKey: secretKey.stringValue()})
.then(() => WalletsGen.createValidatedSecretKey({secretKey}))
.catch(err => {
logger.warn(`Error validating secret key: ${err.desc}`)
return WalletsGen.createValidatedSecretKeyError({error: err.desc, secretKey})
})
}
const deletedAccount = (state: TypedState) =>
Saga.put(
WalletsGen.createSelectAccount({
accountID: state.wallets.accountMap.find(account => account.isDefault).accountID,
show: true,
})
)
const createdOrLinkedAccount = (
state: TypedState,
action: WalletsGen.CreatedNewAccountPayload | WalletsGen.LinkedExistingAccountPayload
) => {
if (action.error) {
// Create new account failed, don't nav
return
}
if (action.payload.showOnCreation) {
return Saga.put(WalletsGen.createSelectAccount({accountID: action.payload.accountID, show: true}))
}
if (action.payload.setBuildingTo) {
return Saga.put(WalletsGen.createSetBuildingTo({to: action.payload.accountID}))
}
return Saga.put(Route.navigateUp())
}
const navigateUp = (
state: TypedState,
action: WalletsGen.DidSetAccountAsDefaultPayload | WalletsGen.ChangedAccountNamePayload
) => {
if (action.error) {
// we don't want to nav on error
return
}
return Saga.put(Route.navigateUp())
}
const navigateToAccount = (state: TypedState, action: WalletsGen.SelectAccountPayload) => {
if (action.type === WalletsGen.selectAccount && !action.payload.show) {
// we don't want to show, don't nav
return
}
const wallet = isMobile
? [Tabs.settingsTab, SettingsConstants.walletsTab, 'wallet']
: [{props: {}, selected: Tabs.walletsTab}, {props: {}, selected: null}]
return Saga.put(Route.navigateTo(wallet))
}
const exportSecretKey = (state: TypedState, action: WalletsGen.ExportSecretKeyPayload) =>
RPCStellarTypes.localGetWalletAccountSecretKeyLocalRpcPromise({accountID: action.payload.accountID}).then(
res =>
WalletsGen.createSecretKeyReceived({
accountID: action.payload.accountID,
secretKey: new HiddenString(res),
})
)
const maybeSelectDefaultAccount = (action: WalletsGen.AccountsReceivedPayload, state: TypedState) =>
state.wallets.selectedAccount === Types.noAccountID &&
Saga.put(
WalletsGen.createSelectAccount({
accountID: state.wallets.accountMap.find(account => account.isDefault).accountID,
})
)
const loadRequestDetail = (state: TypedState, action: WalletsGen.LoadRequestDetailPayload) =>
RPCStellarTypes.localGetRequestDetailsLocalRpcPromise({reqID: action.payload.requestID})
.then(request => WalletsGen.createRequestDetailReceived({request}))
.catch(err => logger.error(`Error loading request detail: ${err.message}`))
const cancelPayment = (state: TypedState, action: WalletsGen.CancelPaymentPayload) => {
const {paymentID, showAccount} = action.payload
const pid = Types.paymentIDToString(paymentID)
logger.info(`cancelPayment: cancelling payment with ID ${pid}`)
return RPCStellarTypes.localCancelPaymentLocalRpcPromise(
{paymentID: Types.paymentIDToRPCPaymentID(paymentID)},
Constants.cancelPaymentWaitingKey(paymentID)
)
.then(_ => {
logger.info(`cancelPayment: successfully cancelled payment with ID ${pid}`)
if (showAccount) {
return WalletsGen.createSelectAccount({accountID: Constants.getSelectedAccount(state), show: true})
}
})
.catch(err => {
logger.error(`cancelPayment: failed to cancel payment with ID ${pid}. Error: ${err.message}`)
throw err
})
}
const cancelRequest = (state: TypedState, action: WalletsGen.CancelRequestPayload) => {
const {conversationIDKey, ordinal, requestID} = action.payload
return RPCStellarTypes.localCancelRequestLocalRpcPromise({reqID: requestID})
.then(
() => (conversationIDKey && ordinal ? Chat2Gen.createMessageDelete({conversationIDKey, ordinal}) : null)
)
.catch(err => logger.error(`Error cancelling request: ${err.message}`))
}
const maybeNavigateAwayFromSendForm = (state: TypedState, action: WalletsGen.AbandonPaymentPayload) => {
const routeState = state.routeTree.routeState
const path = getPath(routeState)
const lastNode = path.last()
if (Constants.sendReceiveFormRoutes.includes(lastNode)) {
if (path.first() === Tabs.walletsTab) {
// User is on send form in wallets tab, navigate back to root of tab
return Saga.put(Route.navigateTo([{props: {}, selected: Tabs.walletsTab}, {props: {}, selected: null}]))
}
// User is somewhere else, send them to most recent parent that isn't a form route
const firstFormIndex = path.findIndex(node => Constants.sendReceiveFormRoutes.includes(node))
const pathAboveForm = path.slice(0, firstFormIndex)
return Saga.put(Route.navigateTo(pathAboveForm))
}
}
const setupEngineListeners = () => {
getEngine().setIncomingCallMap({
'stellar.1.notify.paymentNotification': refreshPayments,
'stellar.1.notify.paymentStatusNotification': refreshPayments,
})
}
const refreshPayments = ({accountID}) =>
Saga.put(WalletsGen.createRefreshPayments({accountID: Types.stringToAccountID(accountID)}))
const maybeClearErrors = (state: TypedState) => {
const routePath = getPath(state.routeTree.routeState)
const selectedTab = routePath.first()
if (selectedTab === Tabs.walletsTab) {
return Saga.put(WalletsGen.createClearErrors())
}
}
const receivedBadgeState = (state: TypedState, action: NotificationsGen.ReceivedBadgeStatePayload) =>
Saga.put(WalletsGen.createBadgesUpdated({accounts: action.payload.badgeState.unreadWalletAccounts || []}))
const acceptDisclaimer = (state: TypedState, action: WalletsGen.AcceptDisclaimerPayload) =>
RPCStellarTypes.localAcceptDisclaimerLocalRpcPromise(undefined, Constants.acceptDisclaimerWaitingKey)
.then(res =>
RPCStellarTypes.localGetWalletSettingsLocalRpcPromise().then(settings =>
WalletsGen.createWalletSettingsReceived({settings})
)
)
.then(
action.payload.nextScreen === 'linkExisting'
? Saga.put(
Route.navigateTo(
isMobile
? [Tabs.settingsTab, SettingsConstants.walletsTab, 'linkExisting']
: [Tabs.walletsTab, 'wallet', 'linkExisting']
)
)
: undefined
)
const rejectDisclaimer = (state: TypedState, action: WalletsGen.AcceptDisclaimerPayload) =>
Saga.put(
isMobile
? Route.navigateTo([{props: {}, selected: Tabs.settingsTab}, {props: {}, selected: null}])
: Route.switchTo([state.routeTree.get('previousTab') || Tabs.peopleTab])
)
function* walletsSaga(): Saga.SagaGenerator<any, any> {
if (!flags.walletsEnabled) {
console.log('Wallets saga disabled')
return
}
yield Saga.actionToPromise(WalletsGen.createNewAccount, createNewAccount)
yield Saga.actionToPromise(WalletsGen.builtPaymentReceived, loadAccount)
yield Saga.actionToPromise(
[
WalletsGen.loadAccounts,
WalletsGen.createdNewAccount,
WalletsGen.linkedExistingAccount,
WalletsGen.refreshPayments,
WalletsGen.didSetAccountAsDefault,
WalletsGen.changedAccountName,
WalletsGen.deletedAccount,
],
loadAccounts
)
yield Saga.actionToPromise(
[
WalletsGen.loadAssets,
WalletsGen.refreshPayments,
WalletsGen.selectAccount,
WalletsGen.linkedExistingAccount,
],
loadAssets
)
yield Saga.actionToPromise(
[
WalletsGen.loadPayments,
WalletsGen.refreshPayments,
WalletsGen.selectAccount,
WalletsGen.linkedExistingAccount,
],
loadPayments
)
yield Saga.actionToPromise(WalletsGen.loadMorePayments, loadMorePayments)
yield Saga.actionToPromise(WalletsGen.deleteAccount, deleteAccount)
yield Saga.actionToPromise(WalletsGen.loadPaymentDetail, loadPaymentDetail)
yield Saga.actionToPromise(WalletsGen.markAsRead, markAsRead)
yield Saga.actionToPromise(WalletsGen.linkExistingAccount, linkExistingAccount)
yield Saga.actionToPromise(WalletsGen.validateAccountName, validateAccountName)
yield Saga.actionToPromise(WalletsGen.validateSecretKey, validateSecretKey)
yield Saga.actionToPromise(WalletsGen.exportSecretKey, exportSecretKey)
yield Saga.actionToPromise(WalletsGen.loadDisplayCurrencies, loadDisplayCurrencies)
yield Saga.actionToPromise(WalletsGen.loadSendAssetChoices, loadSendAssetChoices)
yield Saga.actionToPromise(WalletsGen.loadDisplayCurrency, loadDisplayCurrency)
yield Saga.actionToPromise(WalletsGen.changeDisplayCurrency, changeDisplayCurrency)
yield Saga.actionToPromise(WalletsGen.setAccountAsDefault, setAccountAsDefault)
yield Saga.actionToPromise(WalletsGen.changeAccountName, changeAccountName)
yield Saga.actionToAction(WalletsGen.selectAccount, navigateToAccount)
yield Saga.actionToAction([WalletsGen.didSetAccountAsDefault, WalletsGen.changedAccountName], navigateUp)
yield Saga.actionToAction(
[WalletsGen.createdNewAccount, WalletsGen.linkedExistingAccount],
createdOrLinkedAccount
)
yield Saga.safeTakeEveryPure(WalletsGen.accountsReceived, maybeSelectDefaultAccount)
yield Saga.actionToPromise(
[
WalletsGen.setBuildingAmount,
WalletsGen.setBuildingCurrency,
WalletsGen.setBuildingFrom,
WalletsGen.setBuildingIsRequest,
WalletsGen.setBuildingPublicMemo,
WalletsGen.setBuildingSecretNote,
WalletsGen.setBuildingTo,
],
build
)
yield Saga.actionToAction(WalletsGen.openSendRequestForm, openSendRequestForm)
yield Saga.actionToAction(WalletsGen.deletedAccount, deletedAccount)
yield Saga.actionToPromise(WalletsGen.sendPayment, sendPayment)
yield Saga.actionToAction(WalletsGen.sentPayment, clearBuilding)
yield Saga.actionToAction(WalletsGen.sentPayment, clearBuiltPayment)
yield Saga.actionToAction(WalletsGen.sentPayment, clearErrors)
yield Saga.actionToAction(WalletsGen.sentPayment, maybeNavigateAwayFromSendForm)
yield Saga.actionToPromise(WalletsGen.requestPayment, requestPayment)
yield Saga.actionToAction(WalletsGen.requestedPayment, clearBuilding)
yield Saga.actionToAction(WalletsGen.requestedPayment, clearBuiltRequest)
yield Saga.actionToAction(WalletsGen.requestedPayment, maybeNavigateAwayFromSendForm)
// Effects of abandoning payments
yield Saga.actionToAction(WalletsGen.abandonPayment, clearBuilding)
yield Saga.actionToAction(WalletsGen.abandonPayment, clearBuiltRequest)
yield Saga.actionToAction(WalletsGen.abandonPayment, clearErrors)
yield Saga.actionToAction(WalletsGen.abandonPayment, maybeNavigateAwayFromSendForm)
yield Saga.actionToPromise(WalletsGen.loadRequestDetail, loadRequestDetail)
yield Saga.actionToPromise(WalletsGen.cancelRequest, cancelRequest)
yield Saga.actionToPromise(WalletsGen.cancelPayment, cancelPayment)
yield Saga.actionToAction(ConfigGen.setupEngineListeners, setupEngineListeners)
// Clear some errors on navigateUp.
yield Saga.actionToAction(RouteTreeGen.navigateUp, maybeClearErrors)
yield Saga.actionToAction(NotificationsGen.receivedBadgeState, receivedBadgeState)
yield Saga.actionToPromise(
[WalletsGen.loadAccounts, ConfigGen.loggedIn, WalletsGen.loadWalletSettings],
loadWalletSettings
)
yield Saga.actionToPromise(WalletsGen.acceptDisclaimer, acceptDisclaimer)
yield Saga.actionToAction(WalletsGen.rejectDisclaimer, rejectDisclaimer)
}
export default walletsSaga