Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Maskbook.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,7 @@
6F022CD428A4CE3900B74297 /* SearchSingleNFTViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F022CD328A4CE3900B74297 /* SearchSingleNFTViewController.swift */; };
6F022CD628A4CF9B00B74297 /* SearchSingleNFTViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F022CD528A4CF9B00B74297 /* SearchSingleNFTViewModel.swift */; };
6F022CD828A4CFBD00B74297 /* SearchSingleNFTCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F022CD728A4CFBD00B74297 /* SearchSingleNFTCollectionViewCell.swift */; };
6F022CDA28A93B1800B74297 /* UnlockNFTViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F022CD928A93B1800B74297 /* UnlockNFTViewController.swift */; };
6F07ABE1279022B80039D69D /* NFTCollectionStatusModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F07ABE0279022B80039D69D /* NFTCollectionStatusModel.swift */; };
6F07ABE3279027E70039D69D /* NFTAssetPriceModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F07ABE2279027E70039D69D /* NFTAssetPriceModel.swift */; };
6F07ABE5279697450039D69D /* NFTCollectionDetailTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6F07ABE4279697450039D69D /* NFTCollectionDetailTableViewCell.swift */; };
Expand Down Expand Up @@ -1655,6 +1656,7 @@
6F022CD328A4CE3900B74297 /* SearchSingleNFTViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSingleNFTViewController.swift; sourceTree = "<group>"; };
6F022CD528A4CF9B00B74297 /* SearchSingleNFTViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSingleNFTViewModel.swift; sourceTree = "<group>"; };
6F022CD728A4CFBD00B74297 /* SearchSingleNFTCollectionViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchSingleNFTCollectionViewCell.swift; sourceTree = "<group>"; };
6F022CD928A93B1800B74297 /* UnlockNFTViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UnlockNFTViewController.swift; sourceTree = "<group>"; };
6F07ABE0279022B80039D69D /* NFTCollectionStatusModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NFTCollectionStatusModel.swift; sourceTree = "<group>"; };
6F07ABE2279027E70039D69D /* NFTAssetPriceModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTAssetPriceModel.swift; sourceTree = "<group>"; };
6F07ABE4279697450039D69D /* NFTCollectionDetailTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NFTCollectionDetailTableViewCell.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2061,6 +2063,7 @@
1F57023927A27E4900C96909 /* RedPacketShareSheet.swift */,
1F44794B288A5D8F0098BAE9 /* NftRedPacketShareViewController.swift */,
1F3B23BB28A50B510015949E /* NFTLuckyDropCreationFlow.swift */,
6F022CD928A93B1800B74297 /* UnlockNFTViewController.swift */,
);
path = Controller;
sourceTree = "<group>";
Expand Down Expand Up @@ -4891,6 +4894,7 @@
2A6ABBB82720053B00CC3AED /* RemoteBackupActionsViewController.swift in Sources */,
2AD856002812875A0064DDA5 /* MaskWrapper.swift in Sources */,
2DA3FAB4273CDFBA0013A784 /* ChainInfo.swift in Sources */,
6F022CDA28A93B1800B74297 /* UnlockNFTViewController.swift in Sources */,
2D6677FA27688FBE00528F4D /* WCRequestsHandler.swift in Sources */,
5DC018422859BE84004973CA /* ArweaveHttpClient.swift in Sources */,
0F2051B3265E3B2F00602A0C /* DerivationPath.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LuckyDropViewController: BaseViewController {

case let .addCollectibles(groupName, contractAddress, selectedIdentifiers):
self.coordinator.present(
scene: .luckydropSearchNFT(delegate: self.viewModel.nftViewModel, contractAddress: contractAddress),
scene: .luckydropSearchNFT(delegate: self.viewModel.nftViewModel, contractAddress: contractAddress, selectedIdentifiers: selectedIdentifiers),
transition: .detail()
)

Expand All @@ -83,8 +83,11 @@ class LuckyDropViewController: BaseViewController {

case .unlockWallet: self.unlockWallet()

case let .unlockNFT(contractAddress, gasItem):
// TODO: unlock nft permission
case let .unlockNFT(groupInfo, gasItem, gasFeeViewModel):
self.coordinator.present(scene: .unlockNFT(gasFeeViewModel: gasFeeViewModel, gasFeeItem: gasItem, groupInfo: groupInfo, completion: { hash, error in

}), transition: .popup)

break
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// UnlockNFTViewController.swift
// Maskbook
//
// Created by caiyu on 2022/8/14.
// Copyright © 2022 dimension. All rights reserved.
//

import Combine
import CoreDataStack
import SwiftUI
import UIKit
import web3swift

final class UnlockNFTViewController: SheetViewController {
private(set) var disposeBag: Set<AnyCancellable> = []

@InjectedProvider(\.mainCoordinator)
private var mainCoordinator

private var viewModel: UnlockNFTViewModel

init(
gasFeeViewModel: GasFeeViewModel,
gasFeeItem: GasFeeCellItem,
groupInfo: CollectiableGroup,
completion: ((String?, Error?) -> Void)?
) {
viewModel = UnlockNFTViewModel(gasFeeViewModel: gasFeeViewModel, gasFeeItem: gasFeeItem, collectibleGroup: groupInfo, completion: completion)

super.init(presenter: SheetPresenter(
presentStyle: .translucent,
transition: KeyboardSheetTransition()
)
)
dismissAction = { [weak self] in
self?.viewModel.completion?(nil, UnlockNFTError.cancel)
}
}

override func buildContent() {
super.buildContent()

UnlockNFTView(viewModel: viewModel).asSheetContent(in: self)
}

override func buildEvent() {
super.buildEvent()

viewModel
.$buttonState
.map { state in
state != .sending
}
.assign(to: \.dissmissOnTap, on: self)
.store(in: &disposeBag)
}
}

extension UnlockNFTViewController {
enum UnlockNFTError: Error {
case cancel
}
}
36 changes: 19 additions & 17 deletions Maskbook/Scene/App/RedPacket/View/UnlockNFTView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ import SwiftUI
struct UnlockNFTView: View {
@ObservedObject var viewModel: UnlockNFTViewModel
@InjectedProvider(\.mainCoordinator) private var mainCoordinator

var tipsView: some View {
HStack(spacing: 10) {
Asset.Images.Scene.Social.connectHintBannerIcon.asImage()
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 24)

Text(L10n.Plugins.Luckydrop.Confirm.tips)
.font(FontStyles.rh6.font)
.foregroundColor(Asset.Colors.Public.info.asColor())
Expand All @@ -29,23 +29,25 @@ struct UnlockNFTView: View {
.background(Asset.Colors.Public.infoBg.asColor())
.cornerRadius(12)
}

var body: some View {
VStack(spacing: 20) {
Text(L10n.Scene.WalletUnlock.button + viewModel.tokenName)
.font(FontStyles.bh4.font)
.foregroundColor(Asset.Colors.Text.dark.asColor())

VStack(spacing: 8){


VStack(spacing: 8) {
if let ensName = viewModel.ensName {
Text(ensName)
.font(FontStyles.bh5.font)
.foregroundColor(Asset.Colors.Text.dark.asColor())
HStack(spacing: 4) {
Text(viewModel.address)
.truncationMode(.middle)
.font(FontStyles.rh7.font)
.foregroundColor(Asset.Colors.Text.dark.asColor())
.frame(maxWidth: 118)
.fixedSize()
Asset.Plugins.LuckyDrop.share.asImage()
.frame(width: 20, height: 20)
}
Expand All @@ -59,14 +61,16 @@ struct UnlockNFTView: View {
}
}
}

VStack(spacing: 16) {
buildRow(
title: L10n.Plugins.Luckydrop.Confirm.walletAccount,
value: .address(viewModel.address)
)
buildRow(title: L10n.Plugins.Luckydrop.Confirm.walletAccount,
value: .address(viewModel.contractAddress))
buildRow(
title: L10n.Plugins.Luckydrop.Confirm.walletAccount,
value: .address(viewModel.contractAddress)
)
buildRow(
title: L10n.Plugins.Luckydrop.transactionFee,
value: .gas(viewModel.gasFeeInfo)
Expand All @@ -75,7 +79,6 @@ struct UnlockNFTView: View {
title: L10n.Plugins.Luckydrop.Confirm.totalAmount,
value: .plain("\(viewModel.totalAmount)")
)
buildRow(title: L10n.Plugins.Luckydrop.Confirm.transactionFee, value: .gas(viewModel.gasFeeInfo))
tipsView
}
PrimaryButton(
Expand All @@ -88,22 +91,22 @@ struct UnlockNFTView: View {
}
.padding(.horizontal)
}

@ViewBuilder
func buildRow(title: String, value: ValueType) -> some View {
HStack {
Text(title)
.font(FontStyles.rh6.font)
.foregroundColor(Asset.Colors.Text.dark.asColor())
Spacer()
if case .plain(let title) = value {
if case let .plain(title) = value {
Text(title)
.truncationMode(.middle)
.font(FontStyles.bh6.font)
.foregroundColor(Asset.Colors.Text.dark.asColor())
.frame(maxWidth: 118)
.fixedSize()
} else if case .address(let value) = value {
} else if case let .address(value) = value {
Button {
mainCoordinator.present(scene: .safariView(url: viewModel.operatorUrl), transition: .modal(animated: true))
} label: {
Expand All @@ -118,7 +121,7 @@ struct UnlockNFTView: View {
.frame(width: 20, height: 20)
}
}
} else if case .gas(let value) = value {
} else if case let .gas(value) = value {
Button {
mainCoordinator.present(
scene: .gasFee(
Expand Down Expand Up @@ -150,9 +153,8 @@ extension UnlockNFTView {
}
}


//struct UnlockNFTView_Previews: PreviewProvider {
// struct UnlockNFTView_Previews: PreviewProvider {
// static var previews: some View {
// UnlockNFTView()
// }
//}
// }
35 changes: 22 additions & 13 deletions Maskbook/Scene/App/RedPacket/ViewModel/NftLuckyDropViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ extension NftLuckyDropViewModel {
return false
}

return WalletSendHelper.isApprovedForAll(contractAddress: contractAddress, fromAddress: walletAddress)
return false
}

private func checkState() -> TransactionState {
Expand Down Expand Up @@ -222,7 +222,7 @@ extension NftLuckyDropViewModel {
return
}
let name = groupName ?? ""
let identifiers = collectibles.map { $0.id ?? "" }
let identifiers = collectibles.map { $0.identifier ?? "" }
action(
.addCollectibles(
groupName: name,
Expand Down Expand Up @@ -281,14 +281,15 @@ extension NftLuckyDropViewModel {
case .unlockWallet: action(.unlockWallet)
case .confirmRisk: action(.confirmRisk)
case .unlockNFT:
guard let contractAddress = collectibleGroup?.address, let item = gasFeeItem else {
guard let groupInfo = collectibleGroup, let item = gasFeeItem else {
return
}

action(
.unlockNFT(
contractAddress: contractAddress,
gasItem: item
collectibleGroup: groupInfo,
gasItem: item,
gasFeeViewModel: gasFeeViewModel
)
)

Expand All @@ -315,7 +316,7 @@ extension NftLuckyDropViewModel {
case createNFTLuckyDrop(draft: NftRecpacketDraft, gasFeeViewModel: GasFeeViewModel)
case selectCollectibleGroup
case unlockWallet
case unlockNFT(contractAddress: String, gasItem: GasFeeCellItem)
case unlockNFT(collectibleGroup: CollectiableGroup, gasItem: GasFeeCellItem, gasFeeViewModel: GasFeeViewModel)
}

enum CollectibleItem: Identifiable {
Expand All @@ -326,8 +327,8 @@ extension NftLuckyDropViewModel {
var id: String {
switch self {
case .add: return "add"
case let .normal(item): return item.id ?? ""
case let .all(item): return item.id ?? ""
case let .normal(item): return item.identifier ?? ""
case let .all(item): return item.identifier ?? ""
}
}
}
Expand Down Expand Up @@ -369,18 +370,26 @@ extension NftLuckyDropViewModel {
}

extension NftLuckyDropViewModel: ChooseCollectionBackDelegate {
func chooseNFTCollectionAction(token: Collectible) {
func chooseNFTCollectionAction(token: [Collectible]) {

guard let asset = token.first else {
return
}

selectCollectible(
groupName: token.name ?? "",
contractAddress: token.address ?? "",
groupIconURL: URL(string: token.collectionImage ?? ""),
totalCount: 0
groupName: asset.collectionName ?? "",
contractAddress: asset.address ?? "",
groupIconURL: URL(string: asset.collectionImage ?? ""),
totalCount: token.count
)
actionState = self.checkState()
}
}

extension NftLuckyDropViewModel: SearchSingleNFTDelegate {
func returnSelectedNFT(collectible: [Collectible]?) {
addCollectibles(collectible ?? [])
actionState = self.checkState()

}
}
Loading