Skip to content

Commit cb11cb0

Browse files
committed
register new value for ai key in keychain
1 parent a3ac5bf commit cb11cb0

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

WooCommerce/Classes/Authentication/Keychain+Entries.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,11 @@ extension Keychain {
2626
get { self[WooConstants.siteCredentialPassword] }
2727
set { self[WooConstants.siteCredentialPassword] = newValue }
2828
}
29+
30+
/// AI key provided by the merchant
31+
///
32+
var merchantAIProviderKey: String? {
33+
get { self[WooConstants.merchantAIProviderKey] }
34+
set { self[WooConstants.merchantAIProviderKey] = newValue }
35+
}
2936
}

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ public enum WooConstants {
4545
///
4646
static let sharedUserDefaultsSuiteName = "group.com.automattic.woocommerce"
4747

48+
/// Keychain Access's Key for the AI key entered by the merchant in AI settings
49+
///
50+
static let merchantAIProviderKey = "merchantAIProviderKey"
51+
4852
/// Push Notifications ApplicationID
4953
///
5054
#if DEBUG

WooCommerce/Classes/ViewRelated/AI Settings/AISettingsView.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import SwiftUI
2+
import KeychainAccess
23

34
@Observable final class AISettingsViewModel {
5+
var keychain = Keychain(service: WooConstants.keychainServiceName)
6+
47
var usesJetpackAsDefaultAIProviderSource: Bool = false
58
var isEditingApiKey: Bool = false
69
var apiKey: String = ""
@@ -20,11 +23,12 @@ import SwiftUI
2023
}
2124

2225
func clearAPIKey() {
23-
// TODO
26+
apiKey = ""
27+
keychain.merchantAIProviderKey = nil
2428
}
2529

2630
private func saveSettings() {
27-
// TODO
31+
keychain.merchantAIProviderKey = apiKey
2832
}
2933
}
3034

0 commit comments

Comments
 (0)