Skip to content

Commit

Permalink
Ecosia for companies hacking
Browse files Browse the repository at this point in the history
  • Loading branch information
ecotopian committed May 16, 2024
1 parent 54a062f commit c92a985
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 24 deletions.
19 changes: 18 additions & 1 deletion Client.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1145,6 +1145,7 @@
CA24B52224ABD7D40093848C /* PasswordManagerViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA24B52024ABD7D40093848C /* PasswordManagerViewModelTests.swift */; };
CA24B53924ABFE250093848C /* PasswordManagerSelectionHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA24B53824ABFE250093848C /* PasswordManagerSelectionHelperTests.swift */; };
CA24B53B24ABFE5D0093848C /* PasswordManagerDataSourceHelperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA24B53A24ABFE5D0093848C /* PasswordManagerDataSourceHelperTests.swift */; };
CA3F57992BF638C5004F16B5 /* SVGKit in Frameworks */ = {isa = PBXBuildFile; productRef = CA3F57982BF638C5004F16B5 /* SVGKit */; };
CA4ACE4924C8C91600F55894 /* BreachAlertsDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA4ACE4824C8C91500F55894 /* BreachAlertsDetailView.swift */; };
CA520E7A24913C1B00CCAB48 /* PasswordManagerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA520E7924913C1B00CCAB48 /* PasswordManagerViewModel.swift */; };
CA77ABFD24773C92005079F9 /* BreachAlertsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CA77ABF424772D98005079F9 /* BreachAlertsManager.swift */; };
Expand Down Expand Up @@ -7737,6 +7738,7 @@
0B8E0FF41A932BD500161DC3 /* ImageIO.framework in Frameworks */,
435C85F02788F4D00072B526 /* Glean in Frameworks */,
433F87CE2788EAB600693368 /* GCDWebServers in Frameworks */,
CA3F57992BF638C5004F16B5 /* SVGKit in Frameworks */,
5A06135A29D6052E008F3D38 /* TabDataStore in Frameworks */,
2CE294472B7CDD56006C22B2 /* Core in Frameworks */,
216A0D762A40E7AB008077BA /* Redux in Frameworks */,
Expand Down Expand Up @@ -12463,6 +12465,7 @@
8AF2D0FB2A5F272A00C7DD69 /* ComponentLibrary */,
2C6189F02B7B7D5D006B70D7 /* SnowplowTracker */,
2CE294462B7CDD56006C22B2 /* Core */,
CA3F57982BF638C5004F16B5 /* SVGKit */,
);
productName = Client;
productReference = F84B21BE1A090F8100AAB793 /* Client.app */;
Expand Down Expand Up @@ -12762,6 +12765,7 @@
5A37861729A2C337006B3A34 /* XCRemoteSwiftPackageReference "sentry-cocoa" */,
2C61887D2B7A89E4006B70D7 /* XCRemoteSwiftPackageReference "ios-core" */,
2C6189EF2B7B7D48006B70D7 /* XCRemoteSwiftPackageReference "snowplow-ios-tracker" */,
CA3F57972BF638C5004F16B5 /* XCRemoteSwiftPackageReference "SVGKit" */,
);
productRefGroup = F84B21BF1A090F8100AAB793 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -20905,7 +20909,7 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/ecosia/ios-core.git";
requirement = {
branch = "MOB-2498_upgrade_braze";
branch = "ecosia-for-companies";
kind = branch;
};
};
Expand Down Expand Up @@ -20989,6 +20993,14 @@
version = 8.17.1;
};
};
CA3F57972BF638C5004F16B5 /* XCRemoteSwiftPackageReference "SVGKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SVGKit/SVGKit.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 3.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -21173,6 +21185,11 @@
isa = XCSwiftPackageProductDependency;
productName = ComponentLibrary;
};
CA3F57982BF638C5004F16B5 /* SVGKit */ = {
isa = XCSwiftPackageProductDependency;
package = CA3F57972BF638C5004F16B5 /* XCRemoteSwiftPackageReference "SVGKit" */;
productName = SVGKit;
};
D433852B27ABC8150069DD33 /* MappaMundi */ = {
isa = XCSwiftPackageProductDependency;
package = 43C6A47D27A0679300C79856 /* XCRemoteSwiftPackageReference "MappaMundi" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/braze-inc/braze-swift-sdk",
"state" : {
"revision" : "f893978502a08b02124d2d15c6117eb1a06b7f6f",
"version" : "8.4.0"
"revision" : "2973b623ab2c270bfa5acf3142397b0e1f4806af",
"version" : "7.7.0"
}
},
{
"identity" : "cocoalumberjack",
"kind" : "remoteSourceControl",
"location" : "https://github.com/CocoaLumberjack/CocoaLumberjack.git",
"state" : {
"revision" : "4b8714a7fb84d42393314ce897127b3939885ec3",
"version" : "3.8.5"
}
},
{
Expand Down Expand Up @@ -68,8 +77,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/ecosia/ios-core.git",
"state" : {
"branch" : "MOB-2498_upgrade_braze",
"revision" : "253c093dd95d6cd629b78b147d89287db4d30d6d"
"branch" : "ecosia-for-companies",
"revision" : "991799d2ee33a85983f8b59e9c596de616b508c8"
}
},
{
Expand Down Expand Up @@ -122,8 +131,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/SDWebImage/SDWebImage.git",
"state" : {
"revision" : "f6afa0132961d593f07970d84e2d8b588c29ea04",
"version" : "5.19.1"
"revision" : "5642d1ffe3dbe628592443bd14154e31929727b4",
"version" : "5.19.2"
}
},
{
Expand Down Expand Up @@ -153,6 +162,24 @@
"version" : "5.2.0"
}
},
{
"identity" : "svgkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SVGKit/SVGKit.git",
"state" : {
"revision" : "58152b9f7c85eab239160b36ffdfd364aa43d666",
"version" : "3.0.0"
}
},
{
"identity" : "swift-log",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-log",
"state" : {
"revision" : "e97a6fcb1ab07462881ac165fdbb37f067e205d5",
"version" : "1.5.4"
}
},
{
"identity" : "swiftsoup",
"kind" : "remoteSourceControl",
Expand Down
9 changes: 9 additions & 0 deletions Client/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
try? await Statistics.shared.fetchAndUpdate()
}

// Ecosia: fetching statistics before they are used
Task.detached {
do {
try await Companies.shared.fetchAndUpdate()
} catch(let e) {
debugPrint(e)
}
}

let topSitesProvider = TopSitesProviderImplementation(
placesFetcher: profile.places,
pinnedSiteFetcher: profile.pinnedSites,
Expand Down
9 changes: 8 additions & 1 deletion Client/Coordinators/Browser/BrowserCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class BrowserCoordinator: BaseCoordinator,
}

switch route {
case .searchQuery, .search, .searchURL, .glean, .homepanel, .action, .fxaSignIn, .defaultBrowser:
case .searchQuery, .search, .searchURL, .glean, .homepanel, .action, .fxaSignIn, .defaultBrowser, .company:
return true
case let .settings(section):
return canHandleSettings(with: section)
Expand Down Expand Up @@ -260,6 +260,9 @@ class BrowserCoordinator: BaseCoordinator,
case .tutorial:
startLaunch(with: .defaultBrowser)
}

case let .company(typeTag):
handleCompanyConnect(typeTag: typeTag)
}
}

Expand Down Expand Up @@ -308,6 +311,10 @@ class BrowserCoordinator: BaseCoordinator,
browserViewController.handle(url: searchURL, tabId: tabId)
}

private func handleCompanyConnect(typeTag: String) {
browserViewController.handleCompanyConnect(typeTag: typeTag)
}

private func handle(fxaParams: FxALaunchParams) {
browserViewController.presentSignInViewController(fxaParams)
}
Expand Down
5 changes: 5 additions & 0 deletions Client/Coordinators/Router/Route.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ enum Route: Equatable {
///
/// - Parameter section: An instance of `DefaultBrowserSection` indicating the section of the default browser settings to be displayed.
case defaultBrowser(section: DefaultBrowserSection)

/// Represents a default browser route that takes a `DefaultBrowserSection` value indicating the section to be displayed.
///
/// - Parameter section: An instance of `DefaultBrowserSection` indicating the section of the default browser settings to be displayed.
case company(typeTag: String)

/// An enumeration representing different sections of the home panel.
enum HomepanelSection: String, CaseIterable, Equatable {
Expand Down
5 changes: 5 additions & 0 deletions Client/Coordinators/Router/RouteBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ final class RouteBuilder {
RatingPromptManager.isBrowserDefault = true
// Use the last browsing mode the user was in
return .search(url: url, isPrivate: isPrivate, options: [.focusLocationField])
} else if urlScanner.scheme == "ecosia",
urlScanner.host == "companies",
let typeTag = urlScanner.components.last {
return .company(typeTag: typeTag)
} else {
return nil
}

}

func makeRoute(userActivity: NSUserActivity) -> Route? {
Expand Down
19 changes: 16 additions & 3 deletions Client/Ecosia/UI/NTP/Impact/ClimateImpactInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ enum ClimateImpactInfo: Equatable {
case referral(value: Int, invites: Int)
case totalTrees(value: Int)
case totalInvested(value: Int)
case organisation(value:Int, name: String)


var title: String {
switch self {
Expand All @@ -23,6 +25,9 @@ enum ClimateImpactInfo: Equatable {
case .totalInvested(let value):
return NumberFormatter.ecosiaCurrency()
.string(from: .init(integerLiteral: value)) ?? ""
case .organisation(let value, _):
return NumberFormatter.ecosiaCurrency(withoutEuroSymbol: true)
.string(from: .init(integerLiteral: value)) ?? ""
}
}

Expand All @@ -36,6 +41,8 @@ enum ClimateImpactInfo: Equatable {
return .localized(.treesPlantedByTheCommunity)
case .totalInvested:
return .localized(.dedicatedToClimateAction)
case .organisation(let value, let name):
return "estimated trees planted by \(name)"
}
}

Expand All @@ -49,6 +56,8 @@ enum ClimateImpactInfo: Equatable {
return value.spelledOutString + " " + .localized(.treesPlantedByTheCommunity)
case .totalInvested(let value):
return value.spelledOutString + " " + .localized(.dedicatedToClimateAction)
case .organisation(let value, _):
return value.spelledOutString + " " + .localized(.dedicatedToClimateAction)
}
}

Expand All @@ -62,6 +71,8 @@ enum ClimateImpactInfo: Equatable {
return .init(named: "hand")
case .totalInvested:
return .init(named: "financialReports")
case .organisation:
return .init(named: "treesUpdate")
}
}

Expand All @@ -71,7 +82,7 @@ enum ClimateImpactInfo: Equatable {
return .localized(.howItWorks)
case .referral:
return .localized(.inviteFriends)
case .totalTrees, .totalInvested:
case .totalTrees, .totalInvested, .organisation:
return nil
}
}
Expand All @@ -82,7 +93,7 @@ enum ClimateImpactInfo: Equatable {
return .localized(.howItWorks)
case .referral:
return .localized(.inviteFriends)
case .totalTrees, .totalInvested:
case .totalTrees, .totalInvested, .organisation:
return nil
}
}
Expand All @@ -91,7 +102,7 @@ enum ClimateImpactInfo: Equatable {
switch self {
case .search:
return User.shared.progress
case .referral, .totalInvested, .totalTrees:
case .referral, .totalInvested, .totalTrees, .organisation:
return nil
}
}
Expand All @@ -107,6 +118,8 @@ enum ClimateImpactInfo: Equatable {
return 2
case .totalInvested:
return 3
case .organisation:
return 4
}
}

Expand Down
18 changes: 12 additions & 6 deletions Client/Ecosia/UI/NTP/Impact/NTPImpactCellViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,32 @@ protocol NTPImpactCellDelegate: AnyObject {
final class NTPImpactCellViewModel {
weak var delegate: NTPImpactCellDelegate?
var infoItemSections: [[ClimateImpactInfo]] {
var firstSection: [ClimateImpactInfo] = [referralInfo]
if !Unleash.isEnabled(.incentiveRestrictedSearch) {
firstSection.insert(searchInfo,
at: 0)
}
let secondSection: [ClimateImpactInfo] = [totalTreesInfo, totalInvestedInfo]
let firstSection: [ClimateImpactInfo] = [referralInfo]

let orgOrInvestmentInfo = orgInfo ?? totalInvestedInfo
let secondSection: [ClimateImpactInfo] = [totalTreesInfo, orgOrInvestmentInfo]
return [firstSection, secondSection]
}
var searchInfo: ClimateImpactInfo {
.search(value: User.shared.searchImpact, searches: searchesCounter.state ?? User.shared.searchCount)
}

var referralInfo: ClimateImpactInfo {
.referral(value: User.shared.referrals.impact, invites: User.shared.referrals.count)
}

var totalTreesInfo: ClimateImpactInfo {
.totalTrees(value: TreesProjection.shared.treesAt(.init()))
}
var totalInvestedInfo: ClimateImpactInfo {
.totalInvested(value: InvestmentsProjection.shared.totalInvestedAt(.init()))
}

var orgInfo: ClimateImpactInfo? {
User.shared.company.map({
ClimateImpactInfo.organisation(value: $0.treesAt(.init()), name: $0.name)
})
}

private let searchesCounter = SearchesCounter()
private var cells = [Int:NTPImpactCell]()
Expand Down

0 comments on commit c92a985

Please sign in to comment.