Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uphold): check withdrawal capabilities #637

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions DashWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 53;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down Expand Up @@ -561,6 +561,12 @@
752C3ED22B1AF19C00F46CD3 /* BuySellPortal.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C9FAABB42AB793CE00878224 /* BuySellPortal.storyboard */; };
75303FE52AE7B70500870D8B /* CrowdNode.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 75303FE42AE7B70500870D8B /* CrowdNode.storyboard */; };
75303FE62AE7B70500870D8B /* CrowdNode.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 75303FE42AE7B70500870D8B /* CrowdNode.storyboard */; };
7531308D2B47EC910069C9B7 /* UpholdClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7531308C2B47EC910069C9B7 /* UpholdClient.swift */; };
7531308E2B47EC910069C9B7 /* UpholdClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7531308C2B47EC910069C9B7 /* UpholdClient.swift */; };
753130912B47EE920069C9B7 /* UpholdCapability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753130902B47EE920069C9B7 /* UpholdCapability.swift */; };
753130922B47EE920069C9B7 /* UpholdCapability.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753130902B47EE920069C9B7 /* UpholdCapability.swift */; };
753130972B4944130069C9B7 /* UpholdError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753130962B4944130069C9B7 /* UpholdError.swift */; };
753130982B4944130069C9B7 /* UpholdError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753130962B4944130069C9B7 /* UpholdError.swift */; };
753FDBEA2AEA422F0005EEC3 /* VotingPrefs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 753FDBE92AEA422F0005EEC3 /* VotingPrefs.swift */; };
753FDBEC2AECF4CC0005EEC3 /* VotingHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 753FDBEB2AECF4CC0005EEC3 /* VotingHeaderView.xib */; };
753FDBEE2AECF52B0005EEC3 /* UsernameVoting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 753FDBED2AECF52B0005EEC3 /* UsernameVoting.storyboard */; };
Expand Down Expand Up @@ -2410,6 +2416,9 @@
7527720E2AA9F58E0066557E /* TopperViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopperViewModel.swift; sourceTree = "<group>"; };
752772112AAA1CE30066557E /* Coinbase-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "Coinbase-Info.plist"; sourceTree = "<group>"; };
75303FE42AE7B70500870D8B /* CrowdNode.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = CrowdNode.storyboard; sourceTree = "<group>"; };
7531308C2B47EC910069C9B7 /* UpholdClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpholdClient.swift; sourceTree = "<group>"; };
753130902B47EE920069C9B7 /* UpholdCapability.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpholdCapability.swift; sourceTree = "<group>"; };
753130962B4944130069C9B7 /* UpholdError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpholdError.swift; sourceTree = "<group>"; };
753FDBE92AEA422F0005EEC3 /* VotingPrefs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = VotingPrefs.swift; sourceTree = "<group>"; };
753FDBEB2AECF4CC0005EEC3 /* VotingHeaderView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = VotingHeaderView.xib; sourceTree = "<group>"; };
753FDBED2AECF52B0005EEC3 /* UsernameVoting.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = UsernameVoting.storyboard; sourceTree = "<group>"; };
Expand Down Expand Up @@ -4546,6 +4555,8 @@
2A9FFDF62230FF2B00956D5F /* Uphold */ = {
isa = PBXGroup;
children = (
7531308F2B47EE480069C9B7 /* Model */,
7531308C2B47EC910069C9B7 /* UpholdClient.swift */,
FB8ACEB422E0502100EE5035 /* DWUpholdMainnetConstants.h */,
FB8ACEB522E0502100EE5035 /* DWUpholdMainnetConstants.m */,
2A9FFF282233E60F00956D5F /* DWUpholdAccountObject.h */,
Expand Down Expand Up @@ -5980,6 +5991,15 @@
path = Voting;
sourceTree = "<group>";
};
7531308F2B47EE480069C9B7 /* Model */ = {
isa = PBXGroup;
children = (
753130902B47EE920069C9B7 /* UpholdCapability.swift */,
753130962B4944130069C9B7 /* UpholdError.swift */,
);
path = Model;
sourceTree = "<group>";
};
754495DB2AE91AF700492817 /* Cells */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -8753,6 +8773,7 @@
119E8D082905409300D406C1 /* FullCrowdNodeSignUpTxSet.swift in Sources */,
2A4431E922D738C0009BAF7F /* DWSeedPhraseModel.m in Sources */,
478C983C2945801D00FAA0F0 /* Constants.swift in Sources */,
753130912B47EE920069C9B7 /* UpholdCapability.swift in Sources */,
2A9FFE852230FF4700956D5F /* DWBaseFormCellModel.m in Sources */,
47AE8BFB28C1306000490F5E /* ExploreMapAnnotationView.swift in Sources */,
2A1B7DC0232669FF00BA8C6A /* DWHomeViewController+DWBackupReminder.m in Sources */,
Expand Down Expand Up @@ -8789,6 +8810,7 @@
2A9172D325233F4F0024B4C5 /* DWPhraseRepairChildViewController.m in Sources */,
11B8449A28F6D5480082770C /* SingleInputAddressSelector.swift in Sources */,
0F6EDFCF28C896BD000427E7 /* CoinbaseAccountAddress.swift in Sources */,
7531308D2B47EC910069C9B7 /* UpholdClient.swift in Sources */,
2A7A7BBE2347950700451078 /* DWMainMenuTableViewCell.m in Sources */,
1141E4C2291BB12200ACDA9E /* CrowdNodeTransferViewController.swift in Sources */,
478483E829629C0700E05A5A /* CBAuthInterop.swift in Sources */,
Expand Down Expand Up @@ -8828,6 +8850,7 @@
4789D2312981069700BAFEFA /* UpholdTransferViewController.swift in Sources */,
2AD1CE8422DC9B5D00C99324 /* DWVerifySeedPhraseViewController.m in Sources */,
C909615529F297DD00002D82 /* DerivationPathKeysCell.swift in Sources */,
753130972B4944130069C9B7 /* UpholdError.swift in Sources */,
474C721D298B65C100475CA6 /* Cells.swift in Sources */,
2A913E9823A400D3006A2A59 /* DWContainerViewController.m in Sources */,
47B30D7A290D035B0080C326 /* DashTextAttachment.swift in Sources */,
Expand Down Expand Up @@ -9151,6 +9174,7 @@
C943B5132A40A54600AF23C5 /* DWHistoryFilterContentView.m in Sources */,
C943B4BC2A40A54600AF23C5 /* DWRootContactsViewController.m in Sources */,
C943B4C32A40A54600AF23C5 /* DWTitleActionHeaderView.m in Sources */,
7531308E2B47EC910069C9B7 /* UpholdClient.swift in Sources */,
C9D2C7502A320AA000D15901 /* ServiceOverviewViewController.swift in Sources */,
C9D2C7512A320AA000D15901 /* AccountListModel.swift in Sources */,
C9D2C7532A320AA000D15901 /* DWRecoverWalletCommand.m in Sources */,
Expand Down Expand Up @@ -9214,6 +9238,7 @@
C9D2C7852A320AA000D15901 /* BalanceModel.swift in Sources */,
C9D2C7862A320AA000D15901 /* TxReclassifyTransactionsInfoViewController.swift in Sources */,
C9D2C7872A320AA000D15901 /* DWTransactionListDataProvider.m in Sources */,
753130922B47EE920069C9B7 /* UpholdCapability.swift in Sources */,
C943B5902A40ED6F00AF23C5 /* DWFirstUsernameSymbolValidationRule.m in Sources */,
C943B53E2A40A6BE00AF23C5 /* DPAlertViewController.m in Sources */,
75C1F09E2AFF675400FE675E /* EnterVotingKeyViewController.swift in Sources */,
Expand Down Expand Up @@ -9432,6 +9457,7 @@
C943B5932A40ED7B00AF23C5 /* DWUsernameHeaderView.m in Sources */,
C9D2C8342A320AA000D15901 /* DWSeedUIConstants.m in Sources */,
C9D2C8352A320AA000D15901 /* DWWindow.m in Sources */,
753130982B4944130069C9B7 /* UpholdError.swift in Sources */,
C9D2C8362A320AA000D15901 /* BalanceNotifier.swift in Sources */,
C9D2C8372A320AA000D15901 /* DWSeedWordModel.m in Sources */,
C9D2C8382A320AA000D15901 /* DWRootModel.m in Sources */,
Expand Down Expand Up @@ -10061,7 +10087,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = dashwallet/dashwallet.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
"EXCLUDED_ARCHS[sdk=iphonesimulator*]" = "";
Expand Down Expand Up @@ -10169,6 +10195,7 @@
"\"UIKit\"",
"-weak_framework",
"\"WebKit\"",
"-ld64",
);
PRODUCT_BUNDLE_IDENTIFIER = org.dashfoundation.dash;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand All @@ -10190,7 +10217,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = dashwallet/dashwallet.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -10307,6 +10334,7 @@
"\"UIKit\"",
"-weak_framework",
"\"WebKit\"",
"-ld64",
);
PRODUCT_BUNDLE_IDENTIFIER = org.dashfoundation.dash;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -10395,7 +10423,6 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
Expand All @@ -10418,7 +10445,6 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
Expand Down Expand Up @@ -11178,7 +11204,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = dashwallet/dashwallet.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -11295,6 +11321,7 @@
"\"UIKit\"",
"-weak_framework",
"\"WebKit\"",
"-ld64",
);
PRODUCT_BUNDLE_IDENTIFIER = org.dashfoundation.dash;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down Expand Up @@ -11497,7 +11524,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = dashwallet/dashwallet.entitlements;
CURRENT_PROJECT_VERSION = 1;
CURRENT_PROJECT_VERSION = 10;
DEVELOPMENT_TEAM = 44RJ69WHFF;
EXCLUDED_ARCHS = "";
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand Down Expand Up @@ -11604,6 +11631,7 @@
"\"UIKit\"",
"-weak_framework",
"\"WebKit\"",
"-ld64",
);
PRODUCT_BUNDLE_IDENTIFIER = org.dashfoundation.dash;
PRODUCT_NAME = "$(TARGET_NAME)";
Expand Down
3 changes: 1 addition & 2 deletions DashWallet/Sources/Models/Uphold/DWUpholdClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern NSString *const DWUpholdClientUserDidLogoutNotification;
@class DWUpholdTransactionObject;
@class DWUpholdAccountObject;

// TODO: move methods to UpholdClient.swift
@interface DWUpholdClient : NSObject

@property (readonly, assign, nonatomic, getter=isAuthorized) BOOL authorized;
Expand All @@ -37,7 +38,6 @@ extern NSString *const DWUpholdClientUserDidLogoutNotification;
- (NSURL *)startAuthRoutineByURL;
- (void)completeAuthRoutineWithURL:(NSURL *)url completion:(void (^)(BOOL success))completion;

- (void)getAccounts:(void (^)(NSArray<DWUpholdAccountObject *> *_Nullable accounts))completion;
- (void)getCards:(void (^)(DWUpholdCardObject *_Nullable dashCard, NSArray<DWUpholdCardObject *> *fiatCards))completion;

- (DWUpholdCancellationToken)createTransactionForDashCard:(DWUpholdCardObject *)card
Expand All @@ -61,7 +61,6 @@ extern NSString *const DWUpholdClientUserDidLogoutNotification;
- (nullable NSURL *)buyDashURLForCard:(DWUpholdCardObject *)card;
- (nullable NSURL *)transactionURLForTransaction:(DWUpholdTransactionObject *)transaction;

- (void)updateLastAccessDate;
- (void)logOut;

@end
Expand Down
57 changes: 0 additions & 57 deletions DashWallet/Sources/Models/Uphold/DWUpholdClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,8 @@
NS_ASSUME_NONNULL_BEGIN

static NSString *const UPHOLD_ACCESS_TOKEN = @"DW_UPHOLD_ACCESS_TOKEN";
static NSString *const UPHOLD_LAST_ACCESS = @"DW_UPHOLD_LAST_ACCESS";
static NSString *const UPHOLD_LAST_KNOWN_BALANCE = @"UPHOLD_LAST_KNOWN_BALANCE";

static NSTimeInterval const UPHOLD_KEEP_ALIVE_INTERVAL = 60.0 * 10.0; // 10 min

NSString *const DWUpholdClientUserDidLogoutNotification = @"DWUpholdClientUserDidLogoutNotification";

@interface DWUpholdClient ()
Expand Down Expand Up @@ -66,14 +63,6 @@ - (BOOL)isAuthorized {
return NO;
}

NSTimeInterval timeInterval = -[self.lastAccessDate timeIntervalSinceNow];
if (timeInterval > UPHOLD_KEEP_ALIVE_INTERVAL) {
[self performLogOutShouldNotifyObservers:NO];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a 10 minute force logout. It's annoying for the user and we don't have it on Android.

return NO;
}

[self updateLastAccessDate];

return YES;
}

Expand Down Expand Up @@ -132,38 +121,6 @@ - (void)completeAuthRoutineWithURL:(NSURL *)url completion:(void (^)(BOOL succes
}];
}

- (void)getAccounts:(void (^)(NSArray<DWUpholdAccountObject *> *_Nullable accounts))completion {
NSParameterAssert(self.accessToken);

__weak typeof(self) weakSelf = self;
[DWUpholdAPIProvider getUserAccountsAccessToken:self.accessToken
completion:^(BOOL success, DWUpholdAPIProviderResponseStatusCode statusCode, NSArray<DWUpholdAccountObject *> *_Nullable accounts) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return;
}

NSAssert(statusCode != DWUpholdAPIProviderResponseStatusCodeOTPRequired, @"OTP shouldn't be required here");

// We support funding only by `card` accounts
// (and seems there is no other way to fund your Uphold account via API using other types)
NSArray<DWUpholdAccountObject *> *cardAccounts = nil;
if (success) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"type == %@",
@(DWUpholdAccountObjectTypeCard)];
cardAccounts = [accounts filteredArrayUsingPredicate:predicate];
}

if (completion) {
completion(cardAccounts);
}

if (statusCode == DWUpholdAPIProviderResponseStatusCodeUnauthorized) {
[strongSelf performLogOutShouldNotifyObservers:YES];
}
}];
}

- (void)getCards:(void (^)(DWUpholdCardObject *_Nullable dashCard, NSArray<DWUpholdCardObject *> *fiatCards))completion {
NSParameterAssert(self.accessToken);

Expand Down Expand Up @@ -366,12 +323,6 @@ - (nullable NSURL *)transactionURLForTransaction:(DWUpholdTransactionObject *)tr
return url;
}

- (void)updateLastAccessDate {
if (self.accessToken) {
self.lastAccessDate = [NSDate date];
}
}

- (void)logOut {
[self performLogOutShouldNotifyObservers:YES];
}
Expand Down Expand Up @@ -432,14 +383,6 @@ - (void)createDashCardAddress:(DWUpholdCardObject *)card completion:(void (^)(DW
}];
}

- (nullable NSDate *)lastAccessDate {
return [[NSUserDefaults standardUserDefaults] objectForKey:UPHOLD_LAST_ACCESS];
}

- (void)setLastAccessDate:(nullable NSDate *)lastAccessDate {
[[NSUserDefaults standardUserDefaults] setObject:lastAccessDate forKey:UPHOLD_LAST_ACCESS];
}

- (nullable NSDecimalNumber *)lastKnownBalance {
return [[NSUserDefaults standardUserDefaults] objectForKey:UPHOLD_LAST_KNOWN_BALANCE];
}
Expand Down
34 changes: 34 additions & 0 deletions DashWallet/Sources/Models/Uphold/Model/UpholdCapability.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// Created by Andrei Ashikhmin
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

struct UpholdCapability: Codable {
var key: String
var name: String
var category: String
var enabled: Bool
var requirements: [String]
var restrictions: [String]

init(key: String = "", name: String = "", category: String = "", enabled: Bool = true, requirements: [String] = [], restrictions: [String] = []) {
self.key = key
self.name = name
self.category = category
self.enabled = enabled
self.requirements = requirements
self.restrictions = restrictions
}
}
57 changes: 57 additions & 0 deletions DashWallet/Sources/Models/Uphold/Model/UpholdError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by Andrei Ashikhmin
// Copyright © 2024 Dash Core Group. All rights reserved.
//
// Licensed under the MIT License (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://opensource.org/licenses/MIT
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

enum UpholdError: LocalizedError {
case dueDiligence
case submitIdentity
case proofOfAddress
case unknown

var errorDescription: String? {
switch self {
case .dueDiligence:
NSLocalizedString("Please go to your Uphold account to answer some questions about yourself.", comment: "Uphold")
case .submitIdentity:
NSLocalizedString("Please go to your Uphold account to verify your identity.", comment: "Uphold")
case .proofOfAddress:
NSLocalizedString("Please contact Uphold to update your proof of address.", comment: "Uphold")
default:
""
}
}

var failureReason: String? {
NSLocalizedString("Uphold error", comment: "Uphold")
}

var recoverySuggestion: String? {
NSLocalizedString("Go to Website", comment: "Uphold")
}

static func errorCodeToError(code: String) -> UpholdError {
switch code {
case "user-must-submit-enhanced-due-diligence":
.dueDiligence
case "user-must-submit-identity":
.submitIdentity
case "user-must-submit-proof-of-address":
.proofOfAddress
default:
.unknown
}
}
}
Loading