Skip to content

Commit

Permalink
Merge pull request #657 from Outblock/feat/import-key-migration
Browse files Browse the repository at this point in the history
[HotFix] Missing profile after key migration
Close #512
  • Loading branch information
lmcmz authored Dec 11, 2024
2 parents d87a576 + b3bf0bc commit e2146eb
Show file tree
Hide file tree
Showing 10 changed files with 277 additions and 142 deletions.
13 changes: 10 additions & 3 deletions FRW/Foundation/Base/FlowLog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ class FlowLog {
// MARK: Lifecycle

private init() {
let console = ConsoleDestination()
console.format = "[Flow]$DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M - $X"

let url = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first
let logFileUrl = url?.appendingPathComponent("FlowWallet.log",isDirectory: false)

let console = ConsoleDestination()
console.format = "[Flow] $DHH:mm:ss.SSS$d $C$L$c $N.$F:$l - $M - $X"
console.logPrintWay = .logger(subsystem: "Main", category: "UI")

file = FileDestination(logFileURL: logFileUrl)
file.format = console.format

SwiftyBeaver.addDestination(console)
SwiftyBeaver.addDestination(file)

Expand All @@ -44,7 +51,7 @@ class FlowLog {

// MARK: Private

private let file = FileDestination()
private let file: FileDestination
}

extension NSPredicate {
Expand Down
4 changes: 2 additions & 2 deletions FRW/Modules/MultiBackup/View/MultiBackupVerifyPinView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct MultiBackupVerifyPinView: RouteableView {
var callback: MultiBackupVerifyPinViewModel.VerifyCallback?

var title: String {
" "
""
}

var body: some View {
Expand Down Expand Up @@ -76,7 +76,7 @@ struct MultiBackupVerifyPinView: RouteableView {
}

func backButtonAction() {
Router.dismiss()
Router.pop()
callback?(false, "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ extension RestoreMultiConnectViewModel {
return
}
self.storeItem(list: verifyList)
} else {
DispatchQueue.main.async {
self.enable = true
}
}
})
} else {
Expand Down
146 changes: 67 additions & 79 deletions FRW/Modules/Profile/DeveloperMode/DeveloperModeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,14 @@ struct DeveloperModeView: RouteableView {
if isDeveloperMode {
VStack {
Text("switch_network".localized)
.font(.LL.footnote)
.font(.inter())
.foregroundColor(.LL.Neutrals.neutrals3)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 8)
VStack(spacing: 0) {
Section {
let isMainnet = lud.flowNetwork == .mainnet
let isTestnet = lud.flowNetwork == .testnet
let isPreviewnet = lud.flowNetwork == .previewnet

Cell(
sysImageTuple: (
Expand Down Expand Up @@ -89,7 +88,7 @@ struct DeveloperModeView: RouteableView {
.cornerRadius(16)

Text("watch_address".localized)
.font(.LL.footnote)
.font(.inter())
.foregroundColor(.LL.Neutrals.neutrals3)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 8)
Expand Down Expand Up @@ -186,57 +185,6 @@ struct DeveloperModeView: RouteableView {
}
.cornerRadius(16)

Text("other".localized)
.font(.LL.footnote)
.foregroundColor(.LL.Neutrals.neutrals3)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 8)
VStack(spacing: 0) {
Section {
HStack {
Button {
UserManager.shared.tryToRestoreOldAccountOnFirstLaunch()
} label: {
Text("Reload Local Profile")
.font(.inter(size: 17, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
}
Spacer()
}
.frame(height: 64)
.padding(.horizontal, 16)

HStack {
Text("Script Version")
.font(.inter(size: 17, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Spacer()

Text("\(CadenceManager.shared.version)")
.font(.inter(size: 17))
.foregroundStyle(Color.Theme.Text.black8)
}
.frame(height: 64)
.padding(.horizontal, 16)

HStack {
Text("Cadence Version")
.font(.inter(size: 17, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Spacer()
Text(
"\(String(describing: CadenceManager.shared.current.version ?? ""))"
)
.font(.inter(size: 17))
.foregroundStyle(Color.Theme.Text.black8)
}
.frame(height: 64)
.padding(.horizontal, 16)
}
.background(.LL.bgForIcon)
}
.cornerRadius(16)

Section {
VStack {
HStack {
Expand Down Expand Up @@ -302,48 +250,94 @@ struct DeveloperModeView: RouteableView {
Router.route(to: RouteMap.Profile.keychain)
} label: {
Text("All Keys on Local")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
}
Spacer()
}
.frame(height: 64)
.padding(.horizontal, 16)

Divider()
HStack {
Button {
HUD.success(title: "done")
LocalUserDefaults.shared.migrationFinished = false
} label: {
Text("reset migration flag")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Text("Reset Migration Flag")
}
Spacer()
}
.frame(height: 64)
.padding(.horizontal, 16)

// Divider()
// HStack {
// Button {
// HUD.success(title: "done")
// let list = LocalUserDefaults.shared.userList
// log.debug("[User] \(list)")
//
// } label: {
// Text("Copy all user")
// }
// Spacer()
// }
// .frame(height: 64)
// .padding(.horizontal, 16)

}
.background(.LL.bgForIcon)
.cornerRadius(16)
} header: {
headView(title: "Tools")
}
.visibility(showTool ? .visible : .gone)


Text("other".localized.uppercasedFirstLetter())
.font(.inter())
.foregroundColor(.LL.Neutrals.neutrals3)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 8)
VStack(spacing: 0) {
Section {
HStack {
Button {
let list = LocalUserDefaults.shared.userList
log.debug("[User] \(list)")

UserManager.shared.tryToRestoreOldAccountOnFirstLaunch()
} label: {
Text("copy all user")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Text("Reload Local Profile")
}
Spacer()
}
.frame(height: 64)
.padding(.horizontal, 16)

Divider()
HStack {
Text("Script Version")
Spacer()

Text("\(CadenceManager.shared.version)")
}
.frame(height: 64)
.padding(.horizontal, 16)

Divider()
HStack {
Text("Cadence Version")

Spacer()
Text(
"\(String(describing: CadenceManager.shared.current.version ?? ""))"
)
.font(.inter(size: 17))
.foregroundStyle(Color.Theme.Text.black8)
}
.frame(height: 64)
.padding(.horizontal, 16)
}
.background(.LL.bgForIcon)
.cornerRadius(16)
} header: {
headView(title: "Tools")
}
.visibility(showTool ? .visible : .gone)
.cornerRadius(16)

if isDevModel {
Section {
Expand All @@ -353,8 +347,6 @@ struct DeveloperModeView: RouteableView {
Router.route(to: RouteMap.Profile.keychain)
} label: {
Text("KeyChain")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
}
Spacer()
}
Expand All @@ -365,8 +357,6 @@ struct DeveloperModeView: RouteableView {
Text(
"Reset the move asset configuration in the built-in browser"
)
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Spacer()
}
.frame(height: 64)
Expand All @@ -392,8 +382,6 @@ struct DeveloperModeView: RouteableView {

HStack {
Text("Remove What is Backup Deail (click)")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Spacer()
}
.frame(height: 64)
Expand All @@ -405,8 +393,6 @@ struct DeveloperModeView: RouteableView {

HStack {
Text("Remove Custom token (click)")
.font(.inter(size: 14, weight: .medium))
.foregroundStyle(Color.Theme.Text.black8)
Spacer()
}
.frame(height: 64)
Expand All @@ -426,6 +412,8 @@ struct DeveloperModeView: RouteableView {
.padding(.horizontal, 18)
}
}
.font(.inter())
.foregroundStyle(Color.Theme.Text.black8)
.background(
Color.LL.Neutrals.background.ignoresSafeArea()
)
Expand Down Expand Up @@ -457,10 +445,10 @@ struct DeveloperModeView: RouteableView {

private func headView(title: String) -> some View {
Text(title)
.font(.LL.footnote)
.font(.inter())
.foregroundColor(.LL.Neutrals.neutrals3)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 12)
.padding(.vertical, 8)
}
}

Expand Down
10 changes: 10 additions & 0 deletions FRW/Modules/Wallet/FlowWalletKit/KeyProtocol+Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ enum KeyProvider {
}
return result
}

static func getSuffix(with key: String) -> String {
guard key.contains(sTag) else {
return key
}
guard let suffix = key.components(separatedBy: sTag).last else {
return key
}
return suffix
}
}

extension KeyProtocol {
Expand Down
3 changes: 2 additions & 1 deletion FRW/Modules/Wallet/FlowWalletKit/SecureEnclaveKey+Add.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ extension SecureEnclaveKey {
let storage = FlowWalletKit.KeychainStorage(
service: service,
label: "SecureEnclaveKey",
synchronizable: false
synchronizable: false,
deviceOnly: true
)
return storage
}
Expand Down
Loading

0 comments on commit e2146eb

Please sign in to comment.