Skip to content

Commit

Permalink
Merge pull request #486 from Outblock/release/2.2.10
Browse files Browse the repository at this point in the history
Release/2.2.10
  • Loading branch information
lmcmz authored Nov 5, 2024
2 parents 8200495 + 48b9430 commit a2cd4ac
Show file tree
Hide file tree
Showing 72 changed files with 2,946 additions and 772 deletions.
151 changes: 148 additions & 3 deletions FRW.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion FRW/App/Env/Prod/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>2.2.6</string>
<string>2.2.10</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
Expand Down
10 changes: 9 additions & 1 deletion FRW/App/Env/ServiceConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ class ServiceConfig {

static func configure() {
ServiceConfig.shared.setupInstabug()
ServiceConfig.shared.setupMixPanel()
}
}

// MARK: instabug config

extension ServiceConfig {
func setupInstabug() {
private func setupInstabug() {
guard let token = dict["instabug-key"] else {
fatalError("fatalError ===> Can't find instabug key at ServiceConfig.plist")
}

InstabugConfig.start(token: token)
}

private func setupMixPanel() {
guard let token = dict["MixPanelToken"] else {
fatalError("fatalError ===> Can't find MixPanel Token at ServiceConfig.plist")
}
EventTrack.start(token: token)
}
}
2 changes: 1 addition & 1 deletion FRW/Foundation/Model/AddressBookInfoModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ extension Contact {
// MARK: - AddressBook

struct Contact: Codable, Identifiable {
enum WalletType: Codable {
enum WalletType: String,Codable {
case flow
case evm
case link
Expand Down
2 changes: 2 additions & 0 deletions FRW/Foundation/Model/WalletModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Flow
import Foundation
import BigInt

// MARK: - Coin

Expand Down Expand Up @@ -86,6 +87,7 @@ struct TokenModel: Codable, Identifiable, Mockable {
let website: URL?
let evmAddress: String?
var flowIdentifier: String?
var balance: BigUInt?

var listedToken: ListedToken? {
ListedToken(rawValue: symbol ?? "")
Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Browser/BrowserViewController+JS.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private func generateFCLExtensionInject() -> String {
provider: {
address: "0x33f75ff0b830dcec",
name: "Flow Wallet",
icon: "https://lilico.app/frw-logo.png",
icon: "https://lilico.app/logo_mobile.png",
description: "Digital wallet created for everyone.",
},
};
Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Browser/Handler/JSMessageHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ extension JSMessageHandler {
guard let self = self else {
return
}

if result {
self.didConfirmAuthn(response: authnResponse)
} else {
Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Browser/Model/FCLScripts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class FCLScripts {
"color": "#41CC5D",
"supportEmail": "[email protected]",
"website": "https://frw-link.lilico.app/wc",
"icon": "https://lilico.app/frw-logo.png"
"icon": "https://lilico.app/logo_mobile.png"
}
},
$PRE_AUTHZ_REPLACEMENT
Expand Down
2 changes: 1 addition & 1 deletion FRW/Modules/Browser/View/BrowserAuthnView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ struct BrowserAuthnView_Previews: PreviewProvider {
static let vm = BrowserAuthnViewModel(
title: "This is title",
url: "https://core.flow.com",
logo: "https://lilico.app/frw-logo.png",
logo: "https://lilico.app/logo_mobile.png",
walletAddress: "sadasdssadasdasda",
network: .testnet
) { _ in
Expand Down
5 changes: 2 additions & 3 deletions FRW/Modules/EVM/ViewModel/EVMModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct EVMTransactionReceive: Codable {
let defaultValue = "0"
guard let balance = value else { return defaultValue }
guard let value = BigUInt(from: balance) else { return defaultValue }
return Utilities.formatToPrecision(value)
return Utilities.formatToPrecision(value, formattingDecimals: 64)
}

var gasValue: UInt64 {
Expand All @@ -44,8 +44,7 @@ struct EVMTransactionReceive: Codable {

var dataValue: Data? {
guard let dataStr = data else { return nil }
guard let value = BigUInt(from: dataStr) else { return nil }
return Data(from: value.hexString)
return Data(hex: dataStr)
}

var toAddress: String? {
Expand Down
4 changes: 3 additions & 1 deletion FRW/Modules/MultiBackup/ViewModel/BackupListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ class BackupListViewModel: ObservableObject {
if res {
try await MultiBackupManager.shared.removeItem(with: type)
await fetchMultiBackup()
showRemoveTipView = false
DispatchQueue.main.async {
self.showRemoveTipView = false
}
}

HUD.dismissLoading()
Expand Down
31 changes: 15 additions & 16 deletions FRW/Modules/MultiBackup/ViewModel/BackupUploadViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ class BackupUploadViewModel: ObservableObject {
case .idle:
Task {
do {
buttonState = .loading
DispatchQueue.main.async {
self.buttonState = .loading
self.mnemonicBlur = true
}
try await MultiBackupManager.shared.preLogin(with: currentType)
Expand All @@ -162,7 +162,10 @@ class BackupUploadViewModel: ObservableObject {
case .upload:
Task {
do {
buttonState = .loading
DispatchQueue.main.async {
self.buttonState = .loading
}

try await MultiBackupManager.shared.backupKey(on: currentType)
toggleProcess(process: .regist)
onClickButton()
Expand All @@ -175,14 +178,18 @@ class BackupUploadViewModel: ObservableObject {
case .regist:
Task {
do {
buttonState = .loading
DispatchQueue.main.async {
self.buttonState = .loading
}

try await MultiBackupManager.shared.syncKeyToServer(on: currentType)
DispatchQueue.main.async {
self.mnemonicBlur = false
self.buttonState = .enabled
}
toggleProcess(process: .finish)
// onClickButton()
buttonState = .enabled

} catch {
buttonState = .enabled
HUD.dismissLoading()
Expand All @@ -204,17 +211,9 @@ class BackupUploadViewModel: ObservableObject {
}

func toggleProcess(process: BackupProcess) {
hasError = false
self.process = process
// switch self.process {
// case .idle:
// <#code#>
// case .upload:
// <#code#>
// case .regist:
// <#code#>
// case .finish:
// <#code#>
// }
DispatchQueue.main.async {
self.hasError = false
self.process = process
}
}
}
11 changes: 8 additions & 3 deletions FRW/Modules/NFT/NFTCatalogCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,16 @@ class NFTCatalogCache {
await NFTCollectionStateManager.share.fetch()
collectionList.removeAll { _ in true }
collectionList = NFTCollectionConfig.share.config.filter { col in
!col.address.isEmpty
if let address = col.address {
return !address.isEmpty
}
return false
}
.map { it in
var status = NFTCollectionItem.ItemStatus.idle
if NFTCollectionStateManager.share.isTokenAdded(it.address) {
if let address = it.address, NFTCollectionStateManager.share.isTokenAdded(
address
) {
status = .own
}
return NFTCollectionItem(collection: it, status: status)
Expand Down Expand Up @@ -81,7 +86,7 @@ class NFTCatalogCache {

func find(by collectionName: String) -> NFTCollectionItem? {
let result = collectionList.first { item in
item.collection.contractName.contains(collectionName)
item.collection.contractName?.contains(collectionName) ?? false
}
return result
}
Expand Down
4 changes: 3 additions & 1 deletion FRW/Modules/NFT/NFTDetailPage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,9 @@ struct NFTDetailPage: RouteableView {
.halfSheet(showSheet: $vm.isPresentMove) {
MoveSingleNFTView(nft: vm.nft, fromChildAccount: fromChildAccount) {
withAnimation {
vm.isPresentMove = false
DispatchQueue.main.async {
vm.isPresentMove = false
}
}

Router.pop()
Expand Down
6 changes: 4 additions & 2 deletions FRW/Modules/NFT/NFTModel/NFTCollectionModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ final class NFTCollectionConfig {
if config.isEmpty {
await fetchData()
}
return config.first { $0.address.lowercased() == address.lowercased() }
return config.first { $0.address?.lowercased() == address.lowercased() }
}
}

extension NFTCollectionConfig {
private func fetchData() async {
do {
var list: [NFTCollectionInfo] = try await Network.request(FRWAPI.NFT.collections)
let list: [NFTCollectionInfo] = try await Network.request(
FRWAPI.NFT.collections
)
config = list
} catch {
log.error("NFTCollectionConfig -> fetchData failed: \(error)")
Expand Down
14 changes: 8 additions & 6 deletions FRW/Modules/NFT/NFTModel/NFTCollectionStateManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ final class NFTCollectionStateManager {
do {
let result: [String: Bool] = try await FlowNetwork.checkCollectionEnable(address: Flow.Address(hex: address))

for (index, collection) in list.enumerated() {
let key = "A." + collection.address.stripHexPrefix() + "." + collection.contractName
let isEnable = result[key] ?? false
if let oldIndex = tokenStateList.firstIndex(where: { $0.address.lowercased() == collection.address.lowercased() && $0.name == collection.contractName }) {
tokenStateList.remove(at: oldIndex)
for (_, collection) in list.enumerated() {
if let contractName = collection.contractName, let address = collection.address {
let key = "A." + address.stripHexPrefix() + "." + contractName
let isEnable = result[key] ?? false
if let oldIndex = tokenStateList.firstIndex(where: { $0.address.lowercased() == address.lowercased() && $0.name == collection.contractName }) {
tokenStateList.remove(at: oldIndex)
}
tokenStateList.append(NftCollectionState(name: contractName, address: address, isAdded: isEnable))
}
tokenStateList.append(NftCollectionState(name: collection.contractName, address: collection.address, isAdded: isEnable))
}
} catch {
debugPrint("NFTCollectionStateManager: \(error)")
Expand Down
22 changes: 15 additions & 7 deletions FRW/Modules/NFT/NFTModel/NFTModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ struct EVMNFTCollectionResponse: Codable {

struct NFTCollectionInfo: Codable, Hashable, Mockable {
let id: String
let name: String
let contractName: String
let address: String
let name: String?
let contractName: String?
let address: String?

let logo: String?
let banner: String?
Expand Down Expand Up @@ -93,6 +93,14 @@ struct ContractPath: Codable, Hashable, Mockable {
static func mock() -> ContractPath {
return ContractPath(storagePath: randomString(), publicPath: randomString(), privatePath: "", publicCollectionName: randomString(), publicType: randomString(), privateType: randomString())
}

func storagePathId() -> String {
let list = storagePath.components(separatedBy: "/")
if list.count > 0 {
return list.last ?? storagePath
}
return storagePath
}
}

struct NFTModel: Codable, Hashable, Identifiable {
Expand All @@ -119,7 +127,7 @@ struct NFTModel: Codable, Hashable, Identifiable {
}

var isNBA: Bool {
collection?.contractName.trim() == "TopShot"
collection?.contractName?.trim() == "TopShot"
}

init(_ response: NFTResponse, in collection: NFTCollectionInfo?, from _: FlowModel.CollectionInfo? = nil) {
Expand Down Expand Up @@ -260,7 +268,7 @@ class CollectionItem: Identifiable, ObservableObject {
}
}

func load() {
func load(address: String? = nil) {
if isRequesting || isEnd {
return
}
Expand Down Expand Up @@ -314,8 +322,8 @@ class CollectionItem: Identifiable, ObservableObject {
}
}

private func requestCollectionListDetail(offset: Int, limit: Int = 24) async throws -> NFTListResponse {
let addr = WalletManager.shared.selectedAccountAddress
private func requestCollectionListDetail(offset: Int, limit: Int = 24, fromAddress: String? = nil) async throws -> NFTListResponse {
let addr = fromAddress ?? WalletManager.shared.selectedAccountAddress
let request = NFTCollectionDetailListRequest(address: addr, collectionIdentifier: collection?.id ?? "", offset: offset, limit: limit)
let from: FRWAPI.From = EVMAccountManager.shared.selectedAccount == nil ? .main : .evm
let response: NFTListResponse = try await Network.request(FRWAPI.NFT.collectionDetailList(request, from))
Expand Down
30 changes: 28 additions & 2 deletions FRW/Modules/NFT/NFTTransferView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,16 @@ class NFTTransferViewModel: ObservableObject {
let nftId = nft.response.id
guard let nftAddress = self.nft.collection?.address,
let identifier = nft.collection?.flowIdentifier ?? nft.response.flowIdentifier,
let evmContractAddress = await NFTCollectionConfig.share.get(from: nftAddress)?.evmAddress?.stripHexPrefix()
let toAddress = targetContact.address?.stripHexPrefix()
else {
throw NFTError.sendInvalidAddress
}
tid = try await FlowNetwork.bridgeNFTToAnyEVM(identifier: identifier, id: nftId, contractEVMAddress: evmContractAddress)
tid = try await FlowNetwork
.bridgeNFTToAnyEVM(
identifier: identifier,
id: nftId,
toAddress: toAddress
)

case (.coa, .flow):
let nftId = nft.response.id
Expand Down Expand Up @@ -204,6 +209,27 @@ class NFTTransferViewModel: ObservableObject {
let identifier = nft.publicIdentifier
let childAddr = fromChildAccount?.addr ?? currentAddress
tid = try await FlowNetwork.sendChildNFTToChild(nftId: nftId, childAddress: childAddr, toAddress: toAddress, identifier: identifier, collection: collection)
case (.linked, .coa):
guard let nftIdentifier = nft.response.flowIdentifier,let nftId = UInt64(nft.response.id) else {
return
}
let childAddr = fromChildAccount?.addr ?? currentAddress
tid = try await FlowNetwork
.bridgeChildNFTToEvm(
nft: nftIdentifier,
id: nftId,
child: childAddr)
case (.coa, .linked):
guard let nftIdentifier = nft.response.flowIdentifier,
let nftId = UInt64(nft.response.id) else {
return
}
let childAddr = fromChildAccount?.addr ?? toAddress
tid = try await FlowNetwork
.bridgeChildNFTFromEvm(
nft: nftIdentifier,
id: nftId,
child: childAddr)
default:
failedBlock()
return
Expand Down
Loading

0 comments on commit a2cd4ac

Please sign in to comment.