-
Notifications
You must be signed in to change notification settings - Fork 137
Expand file tree
/
Copy pathbackend-api.service.ts
More file actions
4139 lines (3834 loc) · 117 KB
/
backend-api.service.ts
File metadata and controls
4139 lines (3834 loc) · 117 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
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
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// FYI: any request that needs the HttpOnly cookie to be sent (e.g. b/c the server
// needs the seed phrase) needs the {withCredentials: true} option. It may also needed to
// get the browser to save the cookie in the response.
// https://github.com/github/fetch#sending-cookies
import { Injectable } from '@angular/core';
import { from, interval, Observable, of, throwError, zip } from 'rxjs';
import {
map,
switchMap,
catchError,
filter,
take,
concatMap,
timeout,
tap,
} from 'rxjs/operators';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { IdentityMessagingResponse, IdentityService } from './identity.service';
import { environment } from 'src/environments/environment';
import { Hex } from 'web3-utils/types';
import { SwalHelper } from '../lib/helpers/swal-helper';
export class BackendRoutes {
static ExchangeRateRoute = '/api/v0/get-exchange-rate';
static ExchangeBitcoinRoute = '/api/v0/exchange-bitcoin';
static SendDeSoRoute = '/api/v0/send-deso';
static MinerControlRoute = '/api/v0/miner-control';
static GetUsersStatelessRoute = '/api/v0/get-users-stateless';
static RoutePathSubmitPost = '/api/v0/submit-post';
static RoutePathUploadImage = '/api/v0/upload-image';
static RoutePathSubmitTransaction = '/api/v0/submit-transaction';
static RoutePathUpdateProfile = '/api/v0/update-profile';
static RoutePathGetPostsStateless = '/api/v0/get-posts-stateless';
static RoutePathGetHotFeed = '/api/v0/get-hot-feed';
static RoutePathGetProfiles = '/api/v0/get-profiles';
static RoutePathGetSingleProfile = '/api/v0/get-single-profile';
static RoutePathGetSingleProfilePicture =
'/api/v0/get-single-profile-picture';
static RoutePathGetPostsForPublicKey = '/api/v0/get-posts-for-public-key';
static RoutePathGetDiamondedPosts = '/api/v0/get-diamonded-posts';
static RoutePathGetHodlersForPublicKey = '/api/v0/get-hodlers-for-public-key';
static RoutePathIsHodlingPublicKey = '/api/v0/is-hodling-public-key';
static RoutePathSendMessageStateless = '/api/v0/send-message-stateless';
static RoutePathGetMessagesStateless = '/api/v0/get-messages-stateless';
static GetAllMessagingGroupKeys = '/api/v0/get-all-messaging-group-keys';
static RoutePathCheckPartyMessagingKeys =
'/api/v0/check-party-messaging-keys';
static RegisterGroupMessagingKey = '/api/v0/register-messaging-group-key';
static RoutePathMarkContactMessagesRead =
'/api/v0/mark-contact-messages-read';
static RoutePathMarkAllMessagesRead = '/api/v0/mark-all-messages-read';
static RoutePathGetFollowsStateless = '/api/v0/get-follows-stateless';
static RoutePathCreateFollowTxnStateless =
'/api/v0/create-follow-txn-stateless';
static RoutePathCreateLikeStateless = '/api/v0/create-like-stateless';
static RoutePathBuyOrSellCreatorCoin = '/api/v0/buy-or-sell-creator-coin';
static RoutePathTransferCreatorCoin = '/api/v0/transfer-creator-coin';
static RoutePathUpdateUserGlobalMetadata =
'/api/v0/update-user-global-metadata';
static RoutePathGetUserGlobalMetadata = '/api/v0/get-user-global-metadata';
static RoutePathGetNotifications = '/api/v0/get-notifications';
static RoutePathGetAppState = '/api/v0/get-app-state';
static RoutePathGetSinglePost = '/api/v0/get-single-post';
static RoutePathSendPhoneNumberVerificationText =
'/api/v0/send-phone-number-verification-text';
static RoutePathSubmitPhoneNumberVerificationCode =
'/api/v0/submit-phone-number-verification-code';
static RoutePathBlockPublicKey = '/api/v0/block-public-key';
static RoutePathGetBlockTemplate = '/api/v0/get-block-template';
static RoutePathGetTxn = '/api/v0/get-txn';
static RoutePathDeleteIdentities = '/api/v0/delete-identities';
static RoutePathSendDiamonds = '/api/v0/send-diamonds';
static RoutePathGetDiamondsForPublicKey =
'/api/v0/get-diamonds-for-public-key';
static RoutePathGetLikesForPost = '/api/v0/get-likes-for-post';
static RoutePathGetDiamondsForPost = '/api/v0/get-diamonds-for-post';
static RoutePathGetRepostsForPost = '/api/v0/get-reposts-for-post';
static RoutePathGetQuoteRepostsForPost = '/api/v0/get-quote-reposts-for-post';
static RoutePathGetJumioStatusForPublicKey =
'/api/v0/get-jumio-status-for-public-key';
static RoutePathGetUserMetadata = '/api/v0/get-user-metadata';
static RoutePathGetUsernameForPublicKey =
'/api/v0/get-user-name-for-public-key';
static RoutePathGetPublicKeyForUsername =
'/api/v0/get-public-key-for-user-name';
// Verify
static RoutePathVerifyEmail = '/api/v0/verify-email';
static RoutePathResendVerifyEmail = '/api/v0/resend-verify-email';
// Delete PII
static RoutePathDeletePII = '/api/v0/delete-pii';
// Tutorial
static RoutePathStartOrSkipTutorial = '/api/v0/start-or-skip-tutorial';
static RoutePathCompleteTutorial = '/api/v0/complete-tutorial';
static RoutePathGetTutorialCreators = '/api/v0/get-tutorial-creators';
// Media
static RoutePathUploadVideo = '/api/v0/upload-video';
static RoutePathGetVideoStatus = '/api/v0/get-video-status';
// NFT routes.
static RoutePathCreateNft = '/api/v0/create-nft';
static RoutePathUpdateNFT = '/api/v0/update-nft';
static RoutePathCreateNFTBid = '/api/v0/create-nft-bid';
static RoutePathAcceptNFTBid = '/api/v0/accept-nft-bid';
static RoutePathGetNFTBidsForNFTPost = '/api/v0/get-nft-bids-for-nft-post';
static RoutePathGetNFTsForUser = '/api/v0/get-nfts-for-user';
static RoutePathGetNFTBidsForUser = '/api/v0/get-nft-bids-for-user';
static RoutePathGetNFTShowcase = '/api/v0/get-nft-showcase';
static RoutePathGetNextNFTShowcase = '/api/v0/get-next-nft-showcase';
static RoutePathGetNFTCollectionSummary =
'/api/v0/get-nft-collection-summary';
static RoutePathGetNFTEntriesForPostHash =
'/api/v0/get-nft-entries-for-nft-post';
static RoutePathTransferNFT = '/api/v0/transfer-nft';
static RoutePathAcceptNFTTransfer = '/api/v0/accept-nft-transfer';
static RoutePathBurnNFT = '/api/v0/burn-nft';
// DAO routes
static RoutePathDAOCoin = '/api/v0/dao-coin';
static RoutePathTransferDAOCoin = '/api/v0/transfer-dao-coin';
// ETH
static RoutePathSubmitETHTx = '/api/v0/submit-eth-tx';
static RoutePathQueryETHRPC = '/api/v0/query-eth-rpc';
// Admin routes.
static NodeControlRoute = '/api/v0/admin/node-control';
static ReprocessBitcoinBlockRoute = '/api/v0/admin/reprocess-bitcoin-block';
static RoutePathSwapIdentity = '/api/v0/admin/swap-identity';
static RoutePathAdminUpdateUserGlobalMetadata =
'/api/v0/admin/update-user-global-metadata';
static RoutePathAdminUpdateUsernameBlacklist =
'/api/v0/admin/update-username-blacklist';
static RoutePathAdminResetPhoneNumber = '/api/v0/admin/reset-phone-number';
static RoutePathAdminGetAllUserGlobalMetadata =
'/api/v0/admin/get-all-user-global-metadata';
static RoutePathAdminGetUserGlobalMetadata =
'/api/v0/admin/get-user-global-metadata';
static RoutePathAdminUpdateGlobalFeed = '/api/v0/admin/update-global-feed';
static RoutePathAdminPinPost = '/api/v0/admin/pin-post';
static RoutePathAdminRemoveNilPosts = '/api/v0/admin/remove-nil-posts';
static RoutePathAdminGetMempoolStats = '/api/v0/admin/get-mempool-stats';
static RoutePathAdminGrantVerificationBadge =
'/api/v0/admin/grant-verification-badge';
static RoutePathAdminRemoveVerificationBadge =
'/api/v0/admin/remove-verification-badge';
static RoutePathAdminGetVerifiedUsers = '/api/v0/admin/get-verified-users';
static RoutePathAdminGetUserAdminData = '/api/v0/admin/get-user-admin-data';
static RoutePathAdminGetUsernameVerificationAuditLogs =
'/api/v0/admin/get-username-verification-audit-logs';
static RoutePathUpdateGlobalParams = '/api/v0/admin/update-global-params';
static RoutePathSetUSDCentsToDeSoReserveExchangeRate =
'/api/v0/admin/set-usd-cents-to-deso-reserve-exchange-rate';
static RoutePathGetUSDCentsToDeSoReserveExchangeRate =
'/api/v0/admin/get-usd-cents-to-deso-reserve-exchange-rate';
static RoutePathSetBuyDeSoFeeBasisPoints =
'/api/v0/admin/set-buy-deso-fee-basis-points';
static RoutePathAdminSetCaptchaRewardNanos =
'/api/v0/admin/set-captcha-reward-nanos';
static RoutePathGetBuyDeSoFeeBasisPoints =
'/api/v0/admin/get-buy-deso-fee-basis-points';
static RoutePathAdminGetGlobalParams = '/api/v0/admin/get-global-params';
static RoutePathGetGlobalParams = '/api/v0/get-global-params';
static RoutePathEvictUnminedBitcoinTxns =
'/api/v0/admin/evict-unmined-bitcoin-txns';
static RoutePathGetWyreWalletOrdersForPublicKey =
'/api/v0/admin/get-wyre-wallet-orders-for-public-key';
static RoutePathAdminGetNFTDrop = '/api/v0/admin/get-nft-drop';
static RoutePathAdminUpdateNFTDrop = '/api/v0/admin/update-nft-drop';
static RoutePathAdminResetJumioForPublicKey =
'/api/v0/admin/reset-jumio-for-public-key';
static RoutePathAdminUpdateJumioDeSo = '/api/v0/admin/update-jumio-deso';
static RoutePathAdminUpdateTutorialCreators =
'/api/v0/admin/update-tutorial-creators';
static RoutePathAdminResetTutorialStatus =
'/api/v0/admin/reset-tutorial-status';
static RoutePathAdminGetTutorialCreators =
'/api/v0/admin/get-tutorial-creators';
static RoutePathAdminJumioCallback = '/api/v0/admin/jumio-callback';
static RoutePathAdminGetAllCountryLevelSignUpBonuses =
'/api/v0/admin/get-all-country-level-sign-up-bonuses';
static RoutePathAdminUpdateJumioCountrySignUpBonus =
'/api/v0/admin/update-jumio-country-sign-up-bonus';
static RoutePathAdminUpdateJumioUSDCents =
'/api/v0/admin/update-jumio-usd-cents';
static RoutePathAdminUpdateJumioKickbackUSDCents =
'/api/v0/admin/update-jumio-kickback-usd-cents';
static RoutePathAdminGetUnfilteredHotFeed =
'/api/v0/admin/get-unfiltered-hot-feed';
static RoutePathAdminGetHotFeedAlgorithm =
'/api/v0/admin/get-hot-feed-algorithm';
static RoutePathAdminUpdateHotFeedAlgorithm =
'/api/v0/admin/update-hot-feed-algorithm';
static RoutePathAdminUpdateHotFeedPostMultiplier =
'/api/v0/admin/update-hot-feed-post-multiplier';
static RoutePathAdminUpdateHotFeedUserMultiplier =
'/api/v0/admin/update-hot-feed-user-multiplier';
static RoutePathAdminGetHotFeedUserMultiplier =
'/api/v0/admin/get-hot-feed-user-multiplier';
// Referral program admin routes.
static RoutePathAdminCreateReferralHash =
'/api/v0/admin/create-referral-hash';
static RoutePathAdminGetAllReferralInfoForUser =
'/api/v0/admin/get-all-referral-info-for-user';
static RoutePathAdminUpdateReferralHash =
'/api/v0/admin/update-referral-hash';
static RoutePathAdminDownloadReferralCSV =
'/api/v0/admin/download-referral-csv';
static RoutePathAdminUploadReferralCSV = '/api/v0/admin/upload-referral-csv';
// Referral program non-admin routes
static RoutePathGetReferralInfoForUser = '/api/v0/get-referral-info-for-user';
static RoutePathGetReferralInfoForReferralHash =
'/api/v0/get-referral-info-for-referral-hash';
static RoutePathGetFullTikTokURL = '/api/v0/get-full-tiktok-url';
// Wyre routes.
static RoutePathGetWyreWalletOrderQuotation =
'/api/v0/get-wyre-wallet-order-quotation';
static RoutePathGetWyreWalletOrderReservation =
'/api/v0/get-wyre-wallet-order-reservation';
// Admin Node Fee routes
static RoutePathAdminSetTransactionFeeForTransactionType =
'/api/v0/admin/set-txn-fee-for-txn-type';
static RoutePathAdminSetAllTransactionFees = '/api/v0/admin/set-all-txn-fees';
static RoutePathAdminGetTransactionFeeMap =
'/api/v0/admin/get-transaction-fee-map';
static RoutePathAdminAddExemptPublicKey =
'/api/v0/admin/add-exempt-public-key';
static RoutePathAdminGetExemptPublicKeys =
'/api/v0/admin/get-exempt-public-keys';
// Supply Monitoring endpoints
static RoutePathGetTotalSupply = '/api/v0/total-supply';
static RoutePathGetRichList = '/api/v0/rich-list';
static RoutePathGetCountKeysWithDESO = '/api/v0/count-keys-with-deso';
// Lockup endpoints
static RoutePathCoinLockup = '/api/v0/coin-lockup';
static RoutePathUpdateCoinLockupParams = '/api/v0/update-coin-lockup-params';
static RoutePathCoinLockupTransfer = '/api/v0/coin-lockup-transfer';
static RoutePathCoinUnlock = '/api/v0/coin-unlock';
static RoutePathLockupYieldCurvePoints = '/api/v0/lockup-yield-curve-points';
static RoutePathLockedBalanceEntries = '/api/v0/locked-balance-entries';
// GetBaseCurrencyPrice
static RoutePathGetBaseCurrencyPrice = '/api/v0/get-base-currency-price';
}
export class Transaction {
inputs: {
txID: string;
index: number;
}[];
outputs: {
amountNanos: number;
publicKeyBase58Check: string;
}[];
txnType: string;
publicKeyBase58Check: string;
signatureBytesHex: string;
}
export type DAOCoinEntryResponse = {
CoinsInCirculationNanos: Hex;
MintingDisabled: boolean;
NumberOfHolders: number;
TransferRestrictionStatus: TransferRestrictionStatusString;
LockupTransferRestrictionStatus: TransferRestrictionStatusString;
};
export class ProfileEntryResponse {
Username: string;
Description: string;
ProfilePic?: string;
CoinEntry?: {
DeSoLockedNanos: number;
CoinWatermarkNanos: number;
CoinsInCirculationNanos: number;
CreatorBasisPoints: number;
};
DAOCoinEntry?: DAOCoinEntryResponse;
CoinPriceDeSoNanos?: number;
StakeMultipleBasisPoints?: number;
PublicKeyBase58Check?: string;
UsersThatHODL?: any;
Posts?: PostEntryResponse[];
IsReserved?: boolean;
IsVerified?: boolean;
}
export enum TutorialStatus {
EMPTY = '',
STARTED = 'TutorialStarted',
SKIPPED = 'TutorialSkipped',
CREATE_PROFILE = 'TutorialCreateProfileComplete',
INVEST_OTHERS_BUY = 'InvestInOthersBuyComplete',
INVEST_OTHERS_SELL = 'InvestInOthersSellComplete',
INVEST_SELF = 'InvestInYourselfComplete',
DIAMOND = 'GiveADiamondComplete',
COMPLETE = 'TutorialComplete',
}
export class User {
ProfileEntryResponse: ProfileEntryResponse;
PublicKeyBase58Check: string;
PublicKeysBase58CheckFollowedByUser: string[];
EncryptedSeedHex: string;
BalanceNanos: number;
UnminedBalanceNanos: number;
NumActionItems: any;
NumMessagesToRead: any;
UsersYouHODL: BalanceEntryResponse[];
UsersWhoHODLYouCount: number;
HasPhoneNumber: boolean;
CanCreateProfile: boolean;
HasEmail: boolean;
EmailVerified: boolean;
JumioVerified: boolean;
JumioReturned: boolean;
JumioFinishedTime: number;
ReferralInfoResponses: any;
IsFeaturedTutorialWellKnownCreator: boolean;
IsFeaturedTutorialUpAndComingCreator: boolean;
BlockedPubKeys: { [key: string]: object };
IsAdmin?: boolean;
IsSuperAdmin?: boolean;
TutorialStatus: TutorialStatus;
CreatorPurchasedInTutorialUsername?: string;
CreatorCoinsPurchasedInTutorial: number;
MustCompleteTutorial: boolean;
}
export class PostEntryResponse {
PostHashHex: string;
PosterPublicKeyBase58Check: string;
ParentStakeID: string;
Body: string;
RepostedPostHashHex: string;
ImageURLs: string[];
VideoURLs: string[];
RepostPost: PostEntryResponse;
CreatorBasisPoints: number;
StakeMultipleBasisPoints: number;
TimestampNanos: number;
IsHidden: boolean;
ConfirmationBlockHeight: number;
// PostEntryResponse of the post that this post reposts.
RepostedPostEntryResponse: PostEntryResponse;
// The profile associated with this post.
ProfileEntryResponse: ProfileEntryResponse;
// The comments associated with this post.
Comments: PostEntryResponse[];
LikeCount: number;
RepostCount: number;
QuoteRepostCount: number;
DiamondCount: number;
// Information about the reader's state w/regard to this post (e.g. if they liked it).
PostEntryReaderState?: PostEntryReaderState;
// True if this post hash hex is in the global feed.
InGlobalFeed: boolean;
CommentCount: number;
// A list of parent posts for this post (ordered: root -> closest parent post).
ParentPosts: PostEntryResponse[];
InMempool: boolean;
IsPinned: boolean;
DiamondsFromSender?: number;
NumNFTCopies: number;
NumNFTCopiesForSale: number;
HasUnlockable: boolean;
IsNFT: boolean;
NFTRoyaltyToCoinBasisPoints: number;
NFTRoyaltyToCreatorBasisPoints: number;
AdditionalDESORoyaltiesMap: { [k: string]: number };
AdditionalCoinRoyaltiesMap: { [k: string]: number };
}
export class DiamondsPost {
Post: PostEntryResponse;
// Boolean that is set to true when this is the first post at a given diamond level.
ShowDiamondDivider?: boolean;
}
export class PostEntryReaderState {
// This is true if the reader has liked the associated post.
LikedByReader?: boolean;
// This is true if the reader has reposted the associated post.
RepostedByReader?: boolean;
// This is the post hash hex of the repost
RepostPostHashHex?: string;
// Level of diamond the user gave this post.
DiamondLevelBestowed?: number;
}
export class PostTxnBody {
Body?: string;
ImageURLs?: string[];
VideoURLs?: string[];
}
export class BalanceEntryResponse {
// The public keys are provided for the frontend
HODLerPublicKeyBase58Check: string;
// The public keys are provided for the frontend
CreatorPublicKeyBase58Check: string;
// Has the hodler purchased these creator coins
HasPurchased: boolean;
// How much this HODLer owns of a particular creator coin.
BalanceNanos: number;
// Use this balance for DAO Coin balances
BalanceNanosUint256: Hex;
// The net effect of transactions in the mempool on a given BalanceEntry's BalanceNanos.
// This is used by the frontend to convey info about mining.
NetBalanceInMempool: number;
ProfileEntryResponse: ProfileEntryResponse;
}
export class CumulativeLockedBalanceEntryResponse {
// The public key associated with the holder.
HODLerPublicKeyBase58Check: string;
// The public key associated with the locked DAO coins.
ProfilePublicKeyBase58Check: string;
// The total amount locked across all locked balance entries.
TotalLockedBaseUnits: Hex;
// The total amount that can be unlocked at the time the response was generated.
UnlockableBaseUnits: Hex;
// All unvested and vested locked balance entries.
UnvestedLockedBalanceEntries: LockedBalanceEntryResponse[];
VestedLockedBalanceEntries: LockedBalanceEntryResponse[];
// The profile entry associated with the given profile.
ProfileEntryResponse: ProfileEntryResponse;
}
export class LockedBalanceEntryResponse {
// The public key associated with the holder.
HODLerPublicKeyBase58Check: string;
// The public key associated with the locked DAO coins.
ProfilePublicKeyBase58Check: string;
// When the unlock can begin to be unlocked.
UnlockTimestampNanoSecs: number;
// When the vesting schedule ends.
VestingEndTimestampNanoSecs: number;
// The amount of coins locked in the balance entry.
BalanceBaseUnits: Hex;
}
export class LockupYieldCurvePointResponse {
ProfilePublicKeyBase58Check: string;
LockupDurationNanoSecs: number;
LockupYieldAPYBasisPoints: number;
ProfileEntryResponse: ProfileEntryResponse;
}
export class NFTEntryResponse {
OwnerPublicKeyBase58Check: string;
ProfileEntryResponse: ProfileEntryResponse | undefined;
PostEntryResponse: PostEntryResponse | undefined;
SerialNumber: number;
IsForSale: boolean;
IsPending?: boolean;
MinBidAmountNanos: number;
LastAcceptedBidAmountNanos: number;
IsBuyNow: boolean;
BuyNowPriceNanos: number;
HighestBidAmountNanos: number;
LowestBidAmountNanos: number;
// only populated when the reader is the owner of the nft and there is an unlockable.
LastOwnerPublicKeyBase58Check: string | undefined;
EncryptedUnlockableText: string | undefined;
DecryptedUnlockableText: string | undefined;
}
export class NFTBidEntryResponse {
PublicKeyBase58Check: string;
ProfileEntryResponse: ProfileEntryResponse;
PostHashHex: string;
PostEntryResponse: PostEntryResponse | undefined;
SerialNumber: number;
BidAmountNanos: number;
HighestBidAmountNanos: number | undefined;
LowestBidAmountNanos: number | undefined;
BidderBalanceNanos: number;
selected?: boolean;
}
export class NFTCollectionResponse {
AvailableSerialNumbers: number[];
PostEntryResponse: PostEntryResponse;
ProfileEntryResponse: ProfileEntryResponse;
NumCopiesForSale: number;
HighestBidAmountNanos: number;
LowestBidAmountNanos: number;
}
export class NFTBidData {
PostEntryResponse: PostEntryResponse;
NFTEntryResponses: NFTEntryResponse[];
BidEntryResponses: NFTBidEntryResponse[];
}
export class TransactionFee {
PublicKeyBase58Check: string;
AmountNanos: number;
ProfileEntryResponse?: ProfileEntryResponse;
}
export class DeSoNode {
Name: string;
URL: string;
Owner: string;
}
type GetUserMetadataResponse = {
HasPhoneNumber: boolean;
CanCreateProfile: boolean;
BlockedPubKeys: { [k: string]: any };
HasEmail: boolean;
EmailVerified: boolean;
JumioFinishedTime: number;
JumioVerified: boolean;
JumioReturned: boolean;
};
type GetUsersStatelessResponse = {
UserList: User[];
DefaultFeeRateNanosPerKB: number;
ParamUpdaters: { [k: string]: boolean };
};
export type RichListEntryResponse = {
PublicKeyBase58Check: string;
BalanceNanos: number;
BalanceDESO: number;
Percentage: number;
Value: number;
};
export type CountryLevelSignUpBonus = {
AllowCustomReferralAmount: boolean;
ReferralAmountOverrideUSDCents: number;
AllowCustomKickbackAmount: boolean;
KickbackAmountOverrideUSDCents: number;
};
export type CountryCodeDetails = {
Name: string;
CountryCode: string;
Alpha3: string;
};
export type CountryLevelSignUpBonusResponse = {
CountryLevelSignUpBonus: CountryLevelSignUpBonus;
CountryCodeDetails: CountryCodeDetails;
};
export enum DAOCoinOperationTypeString {
MINT = 'mint',
BURN = 'burn',
UPDATE_TRANSFER_RESTRICTION_STATUS = 'update_transfer_restriction_status',
DISABLE_MINTING = 'disable_minting',
}
export enum TransferRestrictionStatusString {
UNRESTRICTED = 'unrestricted',
PROFILE_OWNER_ONLY = 'profile_owner_only',
DAO_MEMBERS_ONLY = 'dao_members_only',
PERMANENTLY_UNRESTRICTED = 'permanently_unrestricted',
}
export type MessagingGroupMember = {
GroupMemberPublicKeyBase58Check: string;
GroupMemberKeyName: string;
EncryptedKey: string;
};
export type MessagingGroupEntryResponse = {
GroupOwnerPublicKeyBase58Check: string;
MessagingPublicKeyBase58Check: string;
MessagingGroupKeyName: string;
MessagingGroupMembers: MessagingGroupMember[];
EncryptedKey: string;
ExtraData: { [k: string]: string };
};
export type GetAllMessagingGroupKeysResponse = {
MessagingGroupEntries: MessagingGroupEntryResponse[];
};
export type MessagingGroupMemberResponse = {
// GroupMemberPublicKeyBase58Check is the main public key of the group member.
GroupMemberPublicKeyBase58Check: string;
// GroupMemberKeyName is the key name of the member that we encrypt the group messaging public key to. The group
// messaging public key should not be confused with the GroupMemberPublicKeyBase58Check, the former is the public
// key of the whole group, while the latter is the public key of the group member.
GroupMemberKeyName: string;
// EncryptedKey is the encrypted private key corresponding to the group messaging public key that's encrypted
// to the member's registered messaging key labeled with GroupMemberKeyName.
EncryptedKey: string;
};
@Injectable({
providedIn: 'root',
})
export class BackendApiService {
constructor(
private httpClient: HttpClient,
private identityService: IdentityService
) {}
static GET_PROFILES_ORDER_BY_INFLUENCER_COIN_PRICE = 'influencer_coin_price';
static BUY_CREATOR_COIN_OPERATION_TYPE = 'buy';
static SELL_CREATOR_COIN_OPERATION_TYPE = 'sell';
// TODO: Cleanup - this should be a configurable value on the node. Leaving it in the frontend
// is fine for now because BlockCypher has strong anti-abuse measures in place.
blockCypherToken = 'cd455c8a5d404bb0a23880b72f56aa86';
// Store sent messages and associated metadata in localStorage
MessageMetaKey = 'messageMetaKey';
// Store the identity users in localStorage
IdentityUsersKey = 'identityUsersV2';
// Store last local node URL in localStorage
LastLocalNodeKey = 'lastLocalNodeV2';
// Store last logged in user public key in localStorage
LastLoggedInUserKey = 'lastLoggedInUserV2';
// Store the last identity service URL in localStorage
LastIdentityServiceKey = 'lastIdentityServiceURLV2';
// Messaging V3 default key name.
DefaultKey = 'default-key';
// TODO: Wipe all this data when transition is complete
LegacyUserListKey = 'userList';
LegacySeedListKey = 'seedList';
SetStorage(key: string, value: any) {
localStorage.setItem(
key,
value || value === false ? JSON.stringify(value) : ''
);
}
RemoveStorage(key: string) {
localStorage.removeItem(key);
}
GetStorage(key: string) {
const data = localStorage.getItem(key);
if (data === '') {
return null;
}
return JSON.parse(data);
}
SetEncryptedMessagingKeyRandomnessForPublicKey(
publicKeyBase58Check: string,
encryptedMessagingKeyRandomness: string
): void {
const users = this.GetStorage(this.IdentityUsersKey);
this.setIdentityServiceUsers({
...users,
[publicKeyBase58Check]: {
...users[publicKeyBase58Check],
encryptedMessagingKeyRandomness,
},
});
}
// Assemble a URL to hit the BE with.
_makeRequestURL(
endpoint: string,
routeName: string,
adminPublicKey?: string
): string {
let queryURL = location.protocol + '//' + endpoint + routeName;
// If the protocol is specified within the endpoint then use that.
if (endpoint.startsWith('http')) {
queryURL = endpoint + routeName;
}
if (adminPublicKey) {
queryURL += `?admin_public_key=${adminPublicKey}`;
}
return queryURL;
}
_handleError(error: HttpErrorResponse) {
if (error.error instanceof ErrorEvent) {
// A client-side or network error occurred. Handle it accordingly.
console.error('An error occurred:', error.error.message);
} else {
// The backend returned an unsuccessful response code.
// The response body may contain clues as to what went wrong,
console.error(
`Backend returned code ${error.status}, ` +
`body was: ${JSON.stringify(error.error)}`
);
}
// return an observable with a user-facing error message
return throwError(error);
}
// Stores identity service users in identityService and localStorage
setIdentityServiceUsers(users: any, publicKeyAdded?: string) {
this.SetStorage(this.IdentityUsersKey, users);
this.identityService.identityServiceUsers = users;
this.identityService.identityServicePublicKeyAdded = publicKeyAdded;
}
signAndSubmitTransaction(
endpoint: string,
request: Observable<any>,
PublicKeyBase58Check: string
): Observable<any> {
return request
.pipe(
switchMap((res) =>
this.identityService
.sign({
transactionHex: res.TransactionHex,
...this.identityService.identityServiceParamsForKey(
PublicKeyBase58Check
),
})
.pipe(
switchMap((signed) => {
if (signed.approvalRequired) {
return this.identityService
.launch('/approve', {
tx: res.TransactionHex,
})
.pipe(
map((approved) => {
this.setIdentityServiceUsers(approved.users);
return { ...res, ...approved };
})
);
} else {
return of({ ...res, ...signed });
}
})
)
)
)
.pipe(
switchMap((res) =>
this.SubmitTransaction(endpoint, res.signedTransactionHex).pipe(
map((broadcasted) => ({ ...res, ...broadcasted }))
)
)
)
.pipe(catchError(this._handleError));
}
get(endpoint: string, path: string) {
return this.httpClient
.get<any>(this._makeRequestURL(endpoint, path))
.pipe(catchError(this._handleError));
}
post(endpoint: string, path: string, body: any): Observable<any> {
return this.httpClient
.post<any>(this._makeRequestURL(endpoint, path), body)
.pipe(catchError(this._handleError));
}
jwtPost(
endpoint: string,
path: string,
publicKey: string,
body: any
): Observable<any> {
const request = this.identityService.jwt({
...this.identityService.identityServiceParamsForKey(publicKey),
});
return request.pipe(
switchMap((signed) => {
body = {
JWT: signed.jwt,
...body,
};
return this.post(endpoint, path, body).pipe(
map((res) => ({ ...res, ...signed }))
);
})
);
}
GetExchangeRate(endpoint: string): Observable<any> {
return this.get(endpoint, BackendRoutes.ExchangeRateRoute);
}
// Use empty string to return all top categories.
GetBitcoinFeeRateSatoshisPerKB(): Observable<any> {
return this.httpClient
.get<any>('https://api.blockchain.com/mempool/fees')
.pipe(catchError(this._handleError));
}
SendPhoneNumberVerificationText(
endpoint: string,
PublicKeyBase58Check: string,
PhoneNumber: string,
PhoneNumberCountryCode: string
): Observable<any> {
return this.jwtPost(
endpoint,
BackendRoutes.RoutePathSendPhoneNumberVerificationText,
PublicKeyBase58Check,
{
PublicKeyBase58Check,
PhoneNumber,
PhoneNumberCountryCode,
}
);
}
SubmitPhoneNumberVerificationCode(
endpoint: string,
PublicKeyBase58Check: string,
PhoneNumber: string,
PhoneNumberCountryCode: string,
VerificationCode: string
): Observable<any> {
return this.jwtPost(
endpoint,
BackendRoutes.RoutePathSubmitPhoneNumberVerificationCode,
PublicKeyBase58Check,
{
PublicKeyBase58Check,
PhoneNumber,
PhoneNumberCountryCode,
VerificationCode,
}
);
}
GetBlockTemplate(
endpoint: string,
PublicKeyBase58Check: string
): Observable<any> {
return this.post(endpoint, BackendRoutes.RoutePathGetBlockTemplate, {
PublicKeyBase58Check,
HeaderVersion: 1,
});
}
GetTxn(endpoint: string, TxnHashHex: string): Observable<any> {
return this.post(endpoint, BackendRoutes.RoutePathGetTxn, {
TxnHashHex,
});
}
DeleteIdentities(endpoint: string): Observable<any> {
return this.httpClient
.post<any>(
this._makeRequestURL(endpoint, BackendRoutes.RoutePathDeleteIdentities),
{},
{ withCredentials: true }
)
.pipe(catchError(this._handleError));
}
ExchangeBitcoin(
endpoint: string,
LatestBitcionAPIResponse: any,
BTCDepositAddress: string,
PublicKeyBase58Check: string,
BurnAmountSatoshis: number,
FeeRateSatoshisPerKB: number,
Broadcast: boolean
): Observable<any> {
// Check if the user is logged in with a derived key and operating as the owner key.
const DerivedPublicKeyBase58Check =
this.identityService.identityServiceUsers[PublicKeyBase58Check]
?.derivedPublicKeyBase58Check;
let req = this.post(endpoint, BackendRoutes.ExchangeBitcoinRoute, {
PublicKeyBase58Check,
DerivedPublicKeyBase58Check,
BurnAmountSatoshis,
LatestBitcionAPIResponse,
BTCDepositAddress,
FeeRateSatoshisPerKB,
Broadcast: false,
});
if (Broadcast) {
req = req.pipe(
switchMap((res) =>
this.identityService
.burn({
...this.identityService.identityServiceParamsForKey(
PublicKeyBase58Check
),
unsignedHashes: res.UnsignedHashes,
})
.pipe(map((signed) => ({ ...res, ...signed })))
)
);
req = req.pipe(
switchMap((res) =>
this.post(endpoint, BackendRoutes.ExchangeBitcoinRoute, {
PublicKeyBase58Check,
DerivedPublicKeyBase58Check,
BurnAmountSatoshis,
LatestBitcionAPIResponse,
BTCDepositAddress,
FeeRateSatoshisPerKB,
SignedHashes: res.signedHashes,
Broadcast,
}).pipe(map((broadcasted) => ({ ...res, ...broadcasted })))
)
);
}
return req.pipe(catchError(this._handleError));
}
// TODO: Use Broadcast bool isntead
SendDeSoPreview(
endpoint: string,
SenderPublicKeyBase58Check: string,
RecipientPublicKeyOrUsername: string,
AmountNanos: number,
MinFeeRateNanosPerKB: number
): Observable<any> {
return this.post(endpoint, BackendRoutes.SendDeSoRoute, {
SenderPublicKeyBase58Check,
RecipientPublicKeyOrUsername,
AmountNanos: Math.floor(AmountNanos),
MinFeeRateNanosPerKB,
});
}
SendDeSo(
endpoint: string,
SenderPublicKeyBase58Check: string,
RecipientPublicKeyOrUsername: string,
AmountNanos: number,
MinFeeRateNanosPerKB: number
): Observable<any> {
const request = this.SendDeSoPreview(
endpoint,
SenderPublicKeyBase58Check,
RecipientPublicKeyOrUsername,
AmountNanos,
MinFeeRateNanosPerKB
);
return this.signAndSubmitTransaction(
endpoint,
request,
SenderPublicKeyBase58Check