Skip to content

Commit

Permalink
Update iOS to use new environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
kylehickinson authored and NejcZdovc committed Oct 8, 2019
1 parent 2ede397 commit ff277a0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
17 changes: 11 additions & 6 deletions vendor/brave-ios/BATBraveRewards.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ NS_SWIFT_NAME(BraveRewardsConfiguration)

/// Whether or not rewards is being tested
@property (nonatomic, getter=isTesting) BOOL testing;
/// Whether or not rewards is in production
@property (nonatomic, getter=isProduction) BOOL production;
//@property (nonatomic, getter=isDebug) BOOL debug;
/// The rewards environment
@property (nonatomic) BATEnvironment environment;
/// Where ledger and ads should save their state
@property (nonatomic, copy) NSString *stateStoragePath;
/// The number of seconds between overrides. Defaults to 0 (no override) which means reconciles
Expand All @@ -25,16 +26,20 @@ NS_SWIFT_NAME(BraveRewardsConfiguration)
/// Whether or not to enable short retries between contribution attempts
@property (nonatomic) BOOL useShortRetries;

/// The default configuration. Channel is debug, no changes to ledger configuration
/// The default configuration. Environment is dev, no changes to ledger configuration
///
/// State is stored in Application Support
@property (nonatomic, class, readonly) BATBraveRewardsConfiguration *defaultConfiguration NS_SWIFT_NAME(default);
/// The production configuration. Channel is production, no changes to ledger configuration
/// The staging configuration. Environment is staging, no changes to ledger configuration
///
/// State is stored in Application Support
@property (nonatomic, class, readonly) BATBraveRewardsConfiguration *stagingConfiguration NS_SWIFT_NAME(staging);
/// The production configuration. Environment is production, no changes to ledger configuration
///
/// State is stored in Application Support
@property (nonatomic, class, readonly) BATBraveRewardsConfiguration *productionConfiguration NS_SWIFT_NAME(production);
/// The testing configuration. Channel is debug & testing. Short retries are enabled, number of
/// seconds between reconciles is set to 30 seconds instead of 30 days.
/// The testing configuration. Environment is development & is_testing is set to true. Short retries are enabled,
/// number of seconds between reconciles is set to 30 seconds instead of 30 days.
///
/// State is saved to a directory created in /tmp
@property (nonatomic, class, readonly) BATBraveRewardsConfiguration *testingConfiguration NS_SWIFT_NAME(testing);
Expand Down
20 changes: 14 additions & 6 deletions vendor/brave-ios/BATBraveRewards.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ @implementation BATBraveRewardsConfiguration
+ (BATBraveRewardsConfiguration *)defaultConfiguration
{
__auto_type config = [[BATBraveRewardsConfiguration alloc] init];
config.environment = BATEnvironmentDevelopment;
config.stateStoragePath = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES).firstObject;
return config;
}

+ (BATBraveRewardsConfiguration *)stagingConfiguration
{
__auto_type config = [self defaultConfiguration];
config.environment = BATEnvironmentStaging;
return config;
}

+ (BATBraveRewardsConfiguration *)productionConfiguration
{
__auto_type config = [self defaultConfiguration];
config.production = YES;
config.environment = BATEnvironmentProduction;
return config;
}

Expand All @@ -35,7 +43,7 @@ - (id)copyWithZone:(NSZone *)zone
{
__auto_type config = [[BATBraveRewardsConfiguration alloc] init];
config.stateStoragePath = self.stateStoragePath;
config.production = self.production;
config.environment = self.environment;
config.testing = self.testing;
config.useShortRetries = self.useShortRetries;
config.overridenNumberOfSecondsBetweenReconcile = self.overridenNumberOfSecondsBetweenReconcile;
Expand Down Expand Up @@ -79,12 +87,12 @@ - (instancetype)initWithConfiguration:(BATBraveRewardsConfiguration *)configurat
self.ledgerClass = ledgerClass ?: BATBraveLedger.class;
self.adsClass = adsClass ?: BATBraveAds.class;

BATBraveAds.debug = !configuration.production;
BATBraveAds.production = configuration.production;
BATBraveAds.debug = configuration.environment != BATEnvironmentProduction;
BATBraveAds.production = configuration.environment == BATEnvironmentProduction;
BATBraveAds.testing = configuration.testing;

BATBraveLedger.debug = !configuration.production;
BATBraveLedger.production = configuration.production;
BATBraveLedger.debug = configuration.environment != BATEnvironmentProduction;
BATBraveLedger.environment = configuration.environment;
BATBraveLedger.testing = configuration.testing;
BATBraveLedger.useShortRetries = configuration.useShortRetries;
BATBraveLedger.reconcileTime = configuration.overridenNumberOfSecondsBetweenReconcile;
Expand Down
2 changes: 1 addition & 1 deletion vendor/brave-ios/Ledger/BATBraveLedger.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ NS_SWIFT_NAME(BraveLedger)
/// Whether or not to use staging servers. Defaults to false
@property (nonatomic, class, getter=isDebug) BOOL debug;
/// Whether or not to use production servers. Defaults to true
@property (nonatomic, class, getter=isProduction) BOOL production;
@property (nonatomic, class) BATEnvironment environment;
/// Marks if this is being ran in a test environment. Defaults to false
@property (nonatomic, class, getter=isTesting) BOOL testing;
/// Number of minutes between reconciles override. Defaults to 0 (no override)
Expand Down
11 changes: 10 additions & 1 deletion vendor/brave-ios/Ledger/BATBraveLedger.mm
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,19 @@ - (void)removeObserver:(BATBraveLedgerObserver *)observer

BATClassLedgerBridge(BOOL, isDebug, setDebug, is_debug)
BATClassLedgerBridge(BOOL, isTesting, setTesting, is_testing)
BATClassLedgerBridge(BOOL, isProduction, setProduction, is_production)
BATClassLedgerBridge(int, reconcileTime, setReconcileTime, reconcile_time)
BATClassLedgerBridge(BOOL, useShortRetries, setUseShortRetries, short_retries)

+ (BATEnvironment)environment
{
return static_cast<BATEnvironment>(ledger::_environment);
}

+ (void)setEnvironment:(BATEnvironment)environment
{
ledger::_environment = static_cast<ledger::Environment>(environment);
}

#pragma mark - Wallet

BATLedgerReadonlyBridge(BOOL, isWalletCreated, IsWalletCreated)
Expand Down

0 comments on commit ff277a0

Please sign in to comment.