-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
469 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
UnstoppableWallet/UnstoppableWallet/Modules/SendNew/FeeData.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
UnstoppableWallet/UnstoppableWallet/Modules/SendNew/TronPresendHandler.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import BigInt | ||
import Combine | ||
import Foundation | ||
import MarketKit | ||
import RxSwift | ||
import TronKit | ||
|
||
class TronPreSendHandler { | ||
private let token: Token | ||
private let adapter: ISendTronAdapter & IBalanceAdapter | ||
|
||
private let stateSubject = PassthroughSubject<AdapterState, Never>() | ||
private let balanceSubject = PassthroughSubject<Decimal, Never>() | ||
|
||
private let disposeBag = DisposeBag() | ||
|
||
init(token: Token, adapter: ISendTronAdapter & IBalanceAdapter) { | ||
self.token = token | ||
self.adapter = adapter | ||
|
||
adapter.balanceStateUpdatedObservable | ||
.observeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated)) | ||
.subscribe { [weak self] state in | ||
self?.stateSubject.send(state) | ||
} | ||
.disposed(by: disposeBag) | ||
|
||
adapter.balanceDataUpdatedObservable | ||
.observeOn(ConcurrentDispatchQueueScheduler(qos: .userInitiated)) | ||
.subscribe { [weak self] balanceData in | ||
self?.balanceSubject.send(balanceData.available) | ||
} | ||
.disposed(by: disposeBag) | ||
} | ||
} | ||
|
||
extension TronPreSendHandler: IPreSendHandler { | ||
var state: AdapterState { | ||
adapter.balanceState | ||
} | ||
|
||
var statePublisher: AnyPublisher<AdapterState, Never> { | ||
stateSubject.eraseToAnyPublisher() | ||
} | ||
|
||
var balance: Decimal { | ||
adapter.balanceData.available | ||
} | ||
|
||
var balancePublisher: AnyPublisher<Decimal, Never> { | ||
balanceSubject.eraseToAnyPublisher() | ||
} | ||
|
||
func sendData(amount: Decimal, address: String, memo: String?) -> SendDataResult { | ||
guard let amountBigUInt = BigUInt(amount.hs.roundedString(decimal: token.decimals)) else { | ||
return .invalid(cautions: []) | ||
} | ||
|
||
guard let tronAddress = try? TronKit.Address(address: address) else { | ||
return .invalid(cautions: []) | ||
} | ||
|
||
guard tronAddress != adapter.tronKitWrapper.tronKit.receiveAddress else { | ||
return .invalid(cautions: [CautionNew(text: "send.address_error.own_address".localized, type: .error)]) | ||
} | ||
|
||
let contract = adapter.contract(amount: amountBigUInt, address: tronAddress, memo: memo) | ||
|
||
return .valid(sendData: .tron(token: token, contract: contract)) | ||
} | ||
} |
Oops, something went wrong.