mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Refactor wallet-related modules
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import UIKit
|
||||
import Display
|
||||
import TelegramPresentationData
|
||||
import WalletUI
|
||||
import SwiftSignalKit
|
||||
import BuildConfig
|
||||
import WalletUI
|
||||
import WalletCore
|
||||
|
||||
private func encodeText(_ string: String, _ key: Int) -> String {
|
||||
var result = ""
|
||||
@@ -119,10 +120,166 @@ private class ApplicationStatusBarHost: StatusBarHost {
|
||||
}
|
||||
}
|
||||
|
||||
private let records = Atomic<[WalletStateRecord]>(value: [])
|
||||
|
||||
private final class WalletStorageInterfaceImpl: WalletStorageInterface {
|
||||
func watchWalletRecords() -> Signal<[WalletStateRecord], NoError> {
|
||||
return .single(records.with { $0 })
|
||||
}
|
||||
|
||||
func getWalletRecords() -> Signal<[WalletStateRecord], NoError> {
|
||||
return .single(records.with { $0 })
|
||||
}
|
||||
|
||||
func updateWalletRecords(_ f: @escaping ([WalletStateRecord]) -> [WalletStateRecord]) -> Signal<[WalletStateRecord], NoError> {
|
||||
return .single(records.modify(f))
|
||||
}
|
||||
}
|
||||
|
||||
private final class WalletContextImpl: WalletContext {
|
||||
let storage: WalletStorageInterface
|
||||
let tonInstance: TonInstance
|
||||
let keychain: TonKeychain
|
||||
let presentationData: WalletPresentationData
|
||||
|
||||
var inForeground: Signal<Bool, NoError> {
|
||||
return .single(true)
|
||||
}
|
||||
|
||||
func getServerSalt() -> Signal<Data, WalletContextGetServerSaltError> {
|
||||
return .single(Data())
|
||||
}
|
||||
|
||||
func presentNativeController(_ controller: UIViewController) {
|
||||
|
||||
}
|
||||
|
||||
func idleTimerExtension() -> Disposable {
|
||||
return EmptyDisposable
|
||||
}
|
||||
|
||||
func openUrl(_ url: String) {
|
||||
|
||||
}
|
||||
|
||||
func shareUrl(_ url: String) {
|
||||
|
||||
}
|
||||
|
||||
func openPlatformSettings() {
|
||||
|
||||
}
|
||||
|
||||
func authorizeAccessToCamera(completion: @escaping () -> Void) {
|
||||
completion()
|
||||
}
|
||||
|
||||
func pickImage(completion: @escaping (UIImage) -> Void) {
|
||||
}
|
||||
|
||||
init(basePath: String, config: String, blockchainName: String, navigationBarTheme: NavigationBarTheme) {
|
||||
self.storage = WalletStorageInterfaceImpl()
|
||||
self.tonInstance = TonInstance(
|
||||
basePath: basePath,
|
||||
config: config,
|
||||
blockchainName: blockchainName,
|
||||
proxy: nil
|
||||
)
|
||||
self.keychain = TonKeychain(encryptionPublicKey: {
|
||||
return .single(Data())
|
||||
}, encrypt: { data in
|
||||
return .single(TonKeychainEncryptedData(publicKey: Data(), data: data))
|
||||
}, decrypt: { data in
|
||||
return .single(data.data)
|
||||
})
|
||||
let accentColor = UIColor(rgb: 0x007ee5)
|
||||
self.presentationData = WalletPresentationData(
|
||||
theme: WalletTheme(
|
||||
info: WalletInfoTheme(
|
||||
incomingFundsTitleColor: UIColor(rgb: 0x00b12c),
|
||||
outgoingFundsTitleColor: UIColor(rgb: 0xff3b30)
|
||||
), setup: WalletSetupTheme(
|
||||
buttonFillColor: accentColor,
|
||||
buttonForegroundColor: .white,
|
||||
inputBackgroundColor: UIColor(rgb: 0xe9e9e9),
|
||||
inputPlaceholderColor: UIColor(rgb: 0x818086),
|
||||
inputTextColor: .black,
|
||||
inputClearButtonColor: UIColor(rgb: 0x7b7b81).withAlphaComponent(0.8)
|
||||
),
|
||||
list: WalletListTheme(
|
||||
itemPrimaryTextColor: .black,
|
||||
itemSecondaryTextColor: UIColor(rgb: 0x8e8e93),
|
||||
itemPlaceholderTextColor: UIColor(rgb: 0xc8c8ce),
|
||||
itemDestructiveColor: UIColor(rgb: 0xff3b30),
|
||||
itemAccentColor: accentColor,
|
||||
itemDisabledTextColor: UIColor(rgb: 0x8e8e93),
|
||||
plainBackgroundColor: .white,
|
||||
blocksBackgroundColor: UIColor(rgb: 0xefeff4),
|
||||
itemPlainSeparatorColor: UIColor(rgb: 0xc8c7cc),
|
||||
itemBlocksBackgroundColor: .white,
|
||||
itemBlocksSeparatorColor: UIColor(rgb: 0xc8c7cc),
|
||||
itemHighlightedBackgroundColor: UIColor(rgb: 0xe5e5ea),
|
||||
sectionHeaderTextColor: UIColor(rgb: 0x6d6d72),
|
||||
freeTextColor: UIColor(rgb: 0x6d6d72),
|
||||
freeTextErrorColor: UIColor(rgb: 0xcf3030),
|
||||
inputClearButtonColor: UIColor(rgb: 0xcccccc)
|
||||
),
|
||||
statusBarStyle: .Black,
|
||||
navigationBar: navigationBarTheme,
|
||||
keyboardAppearance: .light,
|
||||
alert: AlertControllerTheme(
|
||||
backgroundType: .light,
|
||||
backgroundColor: .white,
|
||||
separatorColor: UIColor(white: 0.9, alpha: 1.0),
|
||||
highlightedItemColor: UIColor(rgb: 0xe5e5ea),
|
||||
primaryColor: .black,
|
||||
secondaryColor: UIColor(rgb: 0x5e5e5e),
|
||||
accentColor: accentColor,
|
||||
destructiveColor: UIColor(rgb: 0xff3b30),
|
||||
disabledColor: UIColor(rgb: 0xd0d0d0)
|
||||
),
|
||||
actionSheet: ActionSheetControllerTheme(
|
||||
dimColor: UIColor(white: 0.0, alpha: 0.4),
|
||||
backgroundType: .light,
|
||||
itemBackgroundColor: .white,
|
||||
itemHighlightedBackgroundColor: UIColor(white: 0.9, alpha: 1.0),
|
||||
standardActionTextColor: accentColor,
|
||||
destructiveActionTextColor: UIColor(rgb: 0xff3b30),
|
||||
disabledActionTextColor: UIColor(rgb: 0xb3b3b3),
|
||||
primaryTextColor: .black,
|
||||
secondaryTextColor: UIColor(rgb: 0x5e5e5e),
|
||||
controlAccentColor: accentColor,
|
||||
controlColor: UIColor(rgb: 0x7e8791),
|
||||
switchFrameColor: UIColor(rgb: 0xe0e0e0),
|
||||
switchContentColor: UIColor(rgb: 0x77d572),
|
||||
switchHandleColor: UIColor(rgb: 0xffffff)
|
||||
)
|
||||
), strings: WalletStrings(
|
||||
primaryComponent: WalletStringsComponent(
|
||||
languageCode: "en",
|
||||
localizedName: "English",
|
||||
pluralizationRulesCode: "en",
|
||||
dict: [:]
|
||||
),
|
||||
secondaryComponent: nil,
|
||||
groupingSeparator: " "
|
||||
), dateTimeFormat: WalletPresentationDateTimeFormat(
|
||||
timeFormat: .regular,
|
||||
dateFormat: .dayFirst,
|
||||
dateSeparator: ".",
|
||||
decimalSeparator: ".",
|
||||
groupingSeparator: " "
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@objc(AppDelegate)
|
||||
final class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
var window: UIWindow?
|
||||
var mainWindow: Window1?
|
||||
|
||||
private var mainWindow: Window1?
|
||||
private var walletContext: WalletContextImpl?
|
||||
|
||||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
let statusBarHost = ApplicationStatusBarHost()
|
||||
@@ -131,11 +288,61 @@ final class AppDelegate: NSObject, UIApplicationDelegate {
|
||||
hostView.containerView.backgroundColor = UIColor.white
|
||||
self.window = window
|
||||
|
||||
let navigationController = NavigationController(mode: .single, theme: NavigationControllerTheme(presentationTheme: defaultPresentationTheme), backgroundDetailsMode: nil)
|
||||
navigationController.setViewControllers([], animated: false)
|
||||
let navigationBarTheme = NavigationBarTheme(
|
||||
buttonColor: .blue,
|
||||
disabledButtonColor: .gray,
|
||||
primaryTextColor: .black,
|
||||
backgroundColor: .lightGray,
|
||||
separatorColor: .black,
|
||||
badgeBackgroundColor: .red,
|
||||
badgeStrokeColor: .red,
|
||||
badgeTextColor: .white
|
||||
)
|
||||
|
||||
let navigationController = NavigationController(
|
||||
mode: .single,
|
||||
theme: NavigationControllerTheme(
|
||||
statusBar: .black,
|
||||
navigationBar: navigationBarTheme,
|
||||
emptyAreaColor: .white
|
||||
), backgroundDetailsMode: nil
|
||||
)
|
||||
|
||||
let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
|
||||
|
||||
let config =
|
||||
"""
|
||||
{
|
||||
"liteservers": [
|
||||
{
|
||||
"ip": 1137658550,
|
||||
"port": 4924,
|
||||
"id": {
|
||||
"@type": "pub.ed25519",
|
||||
"key": "peJTw/arlRfssgTuf9BMypJzqOi7SXEqSPSWiEw2U1M="
|
||||
}
|
||||
}
|
||||
],
|
||||
"validator": {
|
||||
"@type": "validator.config.global",
|
||||
"zero_state": {
|
||||
"workchain": -1,
|
||||
"shard": -9223372036854775808,
|
||||
"seqno": 0,
|
||||
"root_hash": "VCSXxDHhTALFxReyTZRd8E4Ya3ySOmpOWAS4rBX9XBY=",
|
||||
"file_hash": "eh9yveSz1qMdJ7mOsO+I+H77jkLr9NpAuEkoJuseXBo="
|
||||
}
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let walletContext = WalletContextImpl(basePath: documentsPath, config: config, blockchainName: "testnet", navigationBarTheme: navigationBarTheme)
|
||||
self.walletContext = walletContext
|
||||
|
||||
let splashScreen = WalletSplashScreen(context: walletContext, mode: .intro, walletCreatedPreloadState: nil)
|
||||
|
||||
navigationController.setViewControllers([splashScreen], animated: false)
|
||||
self.mainWindow?.viewController = navigationController
|
||||
navigationController.presentOverlay(controller: standardTextAlertController(theme: AlertControllerTheme(presentationTheme: defaultPresentationTheme), title: "Test", text: "Text", actions: [TextAlertAction(type: .defaultAction, title: "OK", action: {
|
||||
})]), inGlobal: false)
|
||||
|
||||
self.window?.makeKeyAndVisible()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user