Skip to content
Merged
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
156 changes: 98 additions & 58 deletions Maskbook.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions Maskbook/Extension/String+Contains.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ extension String {
func containsIgnoreCase(string: String) -> Bool {
lowercased().contains(string.lowercased())
}

public func replaceFirst(of pattern:String,
with replacement:String) -> String {
if let range = self.range(of: pattern){
return self.replacingCharacters(in: range, with: replacement)
}else{
return self
}
}
}
2 changes: 2 additions & 0 deletions Maskbook/Generated/Assets.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ internal enum Asset {
}
internal enum Cell {
internal static let cellCheck = ImageAsset(name: "Icon/Cell/cellCheck")
internal static let cellTwitterCheck = ImageAsset(name: "Icon/Cell/cellTwitterCheck")
internal static let cellUncheck = ImageAsset(name: "Icon/Cell/cellUncheck")
}
internal enum Logo {
Expand Down Expand Up @@ -347,6 +348,7 @@ internal enum Asset {
internal static let rename = ImageAsset(name: "Images/Scene/Personas/rename")
internal static let rotate = ImageAsset(name: "Images/Scene/Personas/rotate")
internal static let search = ImageAsset(name: "Images/Scene/Personas/search")
internal static let searchTwitter = ImageAsset(name: "Images/Scene/Personas/searchTwitter")
internal static let setAvatar = ImageAsset(name: "Images/Scene/Personas/setAvatar")
internal static let twitter = ImageAsset(name: "Images/Scene/Personas/twitter")
internal static let watermark = ImageAsset(name: "Images/Scene/Personas/watermark")
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Avatar.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "left-icon.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
6 changes: 5 additions & 1 deletion Maskbook/Scene/App/Labs/Controller/LabsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ final class LabsViewController: BaseViewController {
guard let self = self else { return }
switch plugin {
case .transaction: self.handleTransak()
case .luckyDrop: self.coordinator.present(scene: .luckyDrop, transition: .modal(animated: true))
case .luckyDrop:
self.coordinator.present(
scene: .luckyDrop(source: .lab, callback: nil),
transition: .modal(animated: true)
)
default: break
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@ import Foundation
import SwiftUI

class LuckyDropViewController: BaseViewController {
private lazy var viewModel = LuckyDropViewModel()
private let viewModel: LuckyDropViewModel
private(set) var cancelableStorage: Set<AnyCancellable> = []

@InjectedProvider(\.mainCoordinator)
private var coordinator


let luckyView: LuckyDropView

init(source: LuckyDropViewModel.Source, callback: (@MainActor (RedPacketPayload) -> Void)?) {
viewModel = LuckyDropViewModel(source: source, callback: callback)
luckyView = LuckyDropView(viewModel: viewModel)
super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = L10n.Plugins.Luckydrop.title
Expand All @@ -30,8 +43,7 @@ class LuckyDropViewController: BaseViewController {

override func buildContent() {
super.buildContent()
let luckyView = LuckyDropView().withResponderChainForCurrentWindow()
let controller = UIHostingController(rootView: luckyView)
let controller = UIHostingController(rootView: luckyView.withResponderChainForCurrentWindow())
self.addChild(controller)
self.view.addSubview(controller.view)
controller.view.snp.makeConstraints { $0.edges.equalToSuperview() }
Expand Down
9 changes: 9 additions & 0 deletions Maskbook/Scene/App/RedPacket/Model/FungibleToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,15 @@ extension RedPacket {
}
}

func encode(to encoder: Encoder) throws {
var contianer = encoder.singleValueContainer()
do {
try contianer.encode(token)
} catch {
log.error("\(error)")
}
}

var token: Token {
switch self {
case .erc20Token(let token):
Expand Down
1 change: 1 addition & 0 deletions Maskbook/Scene/App/RedPacket/Model/RedPacket.swift
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ extension RedPacket {

try container.encodeIfPresent(basic?.contractAddress, forKey: .contractAddress)
try container.encodeIfPresent(basic?.rpid, forKey: .rpid)
try container.encodeIfPresent(basic?.txid, forKey: .txid)
try container.encodeIfPresent(basic?.password, forKey: .password)
try container.encodeIfPresent(basic?.shares, forKey: .shares)
try container.encodeIfPresent(basic?.isRandom, forKey: .isRandom)
Expand Down
2 changes: 1 addition & 1 deletion Maskbook/Scene/App/RedPacket/View/LuckyDropTokens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,6 @@ extension LuckyDropTokens {

struct LuckyDropTokens_Previews: PreviewProvider {
static var previews: some View {
LuckyDropView(viewModel: LuckyDropViewModel())
LuckyDropView(viewModel: LuckyDropViewModel(source: .lab, callback: nil))
}
}
4 changes: 2 additions & 2 deletions Maskbook/Scene/App/RedPacket/View/LuckyDropView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import SwiftUI

struct LuckyDropView: View {
@EnvironmentObject var chain: ResponderChain
@ObservedObject var viewModel = LuckyDropViewModel()
@ObservedObject var viewModel: LuckyDropViewModel
@State var currentHeight: CGFloat = 0
@State var safeArea: EdgeInsets = EdgeInsets()
@InjectedProvider(\.mainCoordinator)
Expand Down Expand Up @@ -129,6 +129,6 @@ struct LuckyDropView: View {

struct LuckyDropView_Previews: PreviewProvider {
static var previews: some View {
LuckyDropView(viewModel: LuckyDropViewModel())
LuckyDropView(viewModel: LuckyDropViewModel(source: .lab, callback: nil))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ struct WalletBottomWidgetView: View {

struct WalletBottomWidgetView_Previews: PreviewProvider {
static var previews: some View {
WalletBottomWidgetView(viewModel: WalletBottomWidgetViewModel())
WalletBottomWidgetView(viewModel: WalletBottomWidgetViewModel(
source: .lab, callback: nil
))
}
}
24 changes: 19 additions & 5 deletions Maskbook/Scene/App/RedPacket/ViewModel/LuckyDropViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ final class LuckyDropViewModel: ObservableObject {
@Published var allowances = [String: BigUInt]()
@Published var selection = LuckDropKind.token

// TODO: It needs to init `profileNickName` if create red packet from Social Platform.
let profileNickName: String? = nil
let walletBottomViewModel = WalletBottomWidgetViewModel()
let walletBottomViewModel: WalletBottomWidgetViewModel

private var timer: Timer?
var gasFeeViewModel = GasFeeViewModel()
Expand Down Expand Up @@ -188,8 +186,15 @@ final class LuckyDropViewModel: ObservableObject {
@InjectedProvider(\.personaManager)
private var personaManager

let source: Source
let callback: (@MainActor (RedPacketPayload) -> Void)?

// MARK: - Public method
init() {
init(source: Source, callback: (@MainActor (RedPacketPayload) -> Void)?) {
self.source = source
self.callback = callback
walletBottomViewModel = WalletBottomWidgetViewModel(source: source, callback: callback)

Publishers.CombineLatest3(
settings.defaultAccountAddressPublisher.removeDuplicates(),
settings.networkPubisher.removeDuplicates(),
Expand Down Expand Up @@ -322,7 +327,9 @@ final class LuckyDropViewModel: ObservableObject {
return
}

let senderName = profileNickName ?? personaManager.currentPersona.value?.identifier ?? "Unknown User"
let senderName = personaManager.currentProfile.value?.nickname
?? personaManager.currentPersona.value?.identifier
?? "Unknown User"

let param = HappyRedPacketV4.CreateRedPacketInput(
publicKey: publicKeyETH,
Expand Down Expand Up @@ -703,6 +710,13 @@ extension LuckyDropViewModel: ChooseTokenBackDelegate {
}

extension LuckyDropViewModel {
enum Source {
// 1. need to check if has a persona
// 2. popup an alert to share
case lab
case composer
}

enum ConfirmButtonType: CaseIterable, Codable {
case noAccount
case noToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ class WalletBottomWidgetViewModel: ObservableObject {

private var address: String = ""

init() {
let source: LuckyDropViewModel.Source
let callback: (@MainActor (RedPacketPayload) -> Void)?

init(source: LuckyDropViewModel.Source, callback: (@MainActor (RedPacketPayload) -> Void)?) {
self.source = source
self.callback = callback

Publishers.CombineLatest3(
settings.defaultAccountAddressPublisher.removeDuplicates(),
settings.networkPubisher.removeDuplicates(),
Expand All @@ -109,20 +115,18 @@ class WalletBottomWidgetViewModel: ObservableObject {

PendTransactionManager.shared.pendingTxFinishEvents.asDriver().sink { _ in
} receiveValue: { [weak self] transcation, status in
guard let self = self else {
guard let self = self else { return }
guard self.address == transcation.address, transcation.txHash == self.txList[self.address]?.txHash,
var state = self.txList[self.address] else {
// If the transaction is not in the list of listeners, the local data needs to be updated as well.
Task {
if case .confirmed = status {
await self.updateRedPacketRecord(transcation: transcation)
}
}
return
}

Task {
await self.updateRedPacketRecord(transcation: transcation)
}

guard self.address == transcation.address, transcation.txHash == self.txList[self.address]?.txHash else {
return
}
guard var state = self.txList[self.address] else {
return
}
withAnimation {
state.status = status
self.txList[self.address] = state
Expand All @@ -137,7 +141,24 @@ class WalletBottomWidgetViewModel: ObservableObject {
}

if case .confirmed = status {
self.coordinator.present(scene: .luckyDropSuccessfully, transition: .modal())
if case .lab = source {
self.coordinator.present(scene: .luckyDropSuccessfully, transition: .modal())
}

Task {
await self.updateRedPacketRecord(transcation: transcation)

guard let chainId = transcation.transactionInfo?.token.chainId,
let networkId = transcation.transactionInfo?.token.networkId,
let network = BlockChainNetwork(chainId: Int(chainId), networkId: UInt64(networkId)),
let payload = PluginStorageRepository.queryRecord(
address: transcation.address,
chain: network,
tx: transcation.txHash) else {
return
}
await callback?(payload)
}
}
}
.store(in: &disposeBag)
Expand Down
16 changes: 14 additions & 2 deletions Maskbook/Scene/Compose/MessageComposeViewModel.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Alamofire
import BigInt
import Combine
import SwiftUI
import web3swift

final class MessageComposeViewModel: ObservableObject {
private var disposeBag = Set<AnyCancellable>()
Expand Down Expand Up @@ -51,7 +53,12 @@ final class MessageComposeViewModel: ObservableObject {
func pluginAddClicked(plugin: PluginType) {
switch plugin {
case .luckyDrop:
mainCoordinator.present(scene: .luckyDrop, transition: .modal(animated: true))
mainCoordinator.present(scene: .luckyDrop(source: .composer, callback: { @MainActor [weak self] payload in
let meta = PluginMeta.redPacket(key: PluginType.luckyDrop.postEncryptionKey, value: payload)
self?.pluginContents.append(meta)

self?.mainCoordinator.dismissTopViewController()
}), transition: .modal(animated: true))
default:
print("message compose \(plugin) add did clicked")
}
Expand All @@ -68,7 +75,12 @@ extension MessageComposeViewModel {

func encryptContent() {
// TODO: get authorID, authorKeyData and network
let encrtypedMessage = WalletCoreHelper.encryptPost(content: message, authorID: nil, authorKeyData: nil, network: nil, metas: pluginContents)
let encrtypedMessage = WalletCoreHelper.encryptPost(
content: message,
authorID: nil,
authorKeyData: nil,
network: nil,
metas: pluginContents)

// TODO: text trimming before post to twitter

Expand Down
Loading