Skip to content

Commit

Permalink
keyservice: synchronize
Browse files Browse the repository at this point in the history
  • Loading branch information
reez authored Aug 22, 2023
1 parent 32fe95d commit 801fcd9
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 1 deletion.
8 changes: 8 additions & 0 deletions BDKSwiftExampleWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
AE0C30FD2A804BC1008F1EAE /* ReceiveViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0C30FC2A804BC1008F1EAE /* ReceiveViewModel.swift */; };
AE0C30FF2A804BDE008F1EAE /* SendViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE0C30FE2A804BDE008F1EAE /* SendViewModel.swift */; };
AE1390C72A7DB0AF0098127A /* KeyService.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE1390C62A7DB0AF0098127A /* KeyService.swift */; };
AE18E9382A9528200019D2A4 /* Bundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18E9372A9528200019D2A4 /* Bundle+Extensions.swift */; };
AE18E93A2A9532CB0019D2A4 /* BDKSwiftExampleWalletBundle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE18E9392A9532CB0019D2A4 /* BDKSwiftExampleWalletBundle+Extensions.swift */; };
AE1C34242A424456008F807A /* ReceiveView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE1C34232A424456008F807A /* ReceiveView.swift */; };
AE1C34262A4248A5008F807A /* SendView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE1C34252A4248A5008F807A /* SendView.swift */; };
AE3902A42A3B4CD900BEC318 /* TabHomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = AE3902A32A3B4CD900BEC318 /* TabHomeView.swift */; };
Expand Down Expand Up @@ -63,6 +65,8 @@
AE0C30FC2A804BC1008F1EAE /* ReceiveViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiveViewModel.swift; sourceTree = "<group>"; };
AE0C30FE2A804BDE008F1EAE /* SendViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendViewModel.swift; sourceTree = "<group>"; };
AE1390C62A7DB0AF0098127A /* KeyService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyService.swift; sourceTree = "<group>"; };
AE18E9372A9528200019D2A4 /* Bundle+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+Extensions.swift"; sourceTree = "<group>"; };
AE18E9392A9532CB0019D2A4 /* BDKSwiftExampleWalletBundle+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "BDKSwiftExampleWalletBundle+Extensions.swift"; sourceTree = "<group>"; };
AE1C34232A424456008F807A /* ReceiveView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiveView.swift; sourceTree = "<group>"; };
AE1C34252A4248A5008F807A /* SendView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SendView.swift; sourceTree = "<group>"; };
AE3902A32A3B4CD900BEC318 /* TabHomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabHomeView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -135,6 +139,7 @@
isa = PBXGroup;
children = (
AE7953912A2D5E3100CCB277 /* Date+Extensions.swift */,
AE18E9372A9528200019D2A4 /* Bundle+Extensions.swift */,
A73F7A352A3B778E00B87FC6 /* Int+Extensions.swift */,
AE7F67062A744CE200CED561 /* Double+Extensions.swift */,
);
Expand Down Expand Up @@ -232,6 +237,7 @@
AED4CC112A1D640800CE1831 /* BDKSwiftExampleWalletWalletViewModelTests.swift */,
AE7E68952A59A37300368D82 /* BDKSwiftExampleWalletInt+Extensions.swift */,
AE96F6612A424C400055623C /* BDKSwiftExampleWalletReceiveTests.swift */,
AE18E9392A9532CB0019D2A4 /* BDKSwiftExampleWalletBundle+Extensions.swift */,
);
path = BDKSwiftExampleWalletTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -391,6 +397,7 @@
AE7F670C2A7451D700CED561 /* CurrencyCode.swift in Sources */,
AE7F67052A7446B600CED561 /* PriceService.swift in Sources */,
AE7953902A2D5B4400CCB277 /* BDKSwiftExampleWalletError.swift in Sources */,
AE18E9382A9528200019D2A4 /* Bundle+Extensions.swift in Sources */,
AE79538E2A2D59F000CCB277 /* Constants.swift in Sources */,
AE1C34242A424456008F807A /* ReceiveView.swift in Sources */,
AEB130C92A44E4850087785B /* TransactionDetailsView.swift in Sources */,
Expand Down Expand Up @@ -420,6 +427,7 @@
AE7E68962A59A37300368D82 /* BDKSwiftExampleWalletInt+Extensions.swift in Sources */,
AE96F6622A424C400055623C /* BDKSwiftExampleWalletReceiveTests.swift in Sources */,
AED4CC122A1D640800CE1831 /* BDKSwiftExampleWalletWalletViewModelTests.swift in Sources */,
AE18E93A2A9532CB0019D2A4 /* BDKSwiftExampleWalletBundle+Extensions.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
14 changes: 14 additions & 0 deletions BDKSwiftExampleWallet/Extensions/Bundle+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Bundle+Extensions.swift
// BDKSwiftExampleWallet
//
// Created by Matthew Ramsden on 8/22/23.
//

import Foundation

extension Bundle {
var displayName: String {
return Bundle.main.infoDictionary?["CFBundleName"] as? String ?? Bundle.main.bundleIdentifier ?? "Unknown Bundle"
}
}
10 changes: 9 additions & 1 deletion BDKSwiftExampleWallet/Service/Key Service/KeyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ import Foundation
import KeychainAccess

struct KeyService {
private let keychain = Keychain(service: "com.matthewramsden.bdkswiftexamplewallet.testservice")
private let keychain: Keychain

init() {
let keychain = Keychain(service: "com.matthewramsden.bdkswiftexamplewallet.testservice") // TODO: use `Bundle.main.displayName` or something like com.bdk.swiftwalletexample
.label(Bundle.main.displayName)
.synchronizable(true)
.accessibility(.whenUnlocked)
self.keychain = keychain
}

enum BackupInfoError: Error {
case encodingError
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// BDKSwiftExampleWalletBundle+Extensions.swift
// BDKSwiftExampleWalletTests
//
// Created by Matthew Ramsden on 8/22/23.
//

import XCTest
@testable import BDKSwiftExampleWallet

final class BDKSwiftExampleWalletBundle_Extensions: XCTestCase {

func testDisplayName() {
let displayName = Bundle.main.displayName

// Check that the displayName is not empty
XCTAssertFalse(displayName.isEmpty)

// Check that the displayName is either the bundle name or the bundle identifier
if let bundleName = Bundle.main.infoDictionary?["CFBundleName"] as? String {
XCTAssertEqual(displayName, bundleName)
} else if let bundleIdentifier = Bundle.main.bundleIdentifier {
XCTAssertEqual(displayName, bundleIdentifier)
} else {
XCTAssertEqual(displayName, "Unknown Bundle")
}
}

}

0 comments on commit 801fcd9

Please sign in to comment.