Skip to content

Commit

Permalink
Switch Ton and jetton send modules to new send
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed Sep 5, 2024
1 parent ae4e2b8 commit b1aeec8
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 634 deletions.
26 changes: 0 additions & 26 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,6 @@
11B35503B3E84FEFCDF1AFED /* ThemeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35E7E7A5DBB09A2A5197D /* ThemeView.swift */; };
11B3550424326606B055D7E5 /* AboutModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B353E80D544DAF20B12B56 /* AboutModule.swift */; };
11B35504619FDE878D865781 /* MultiSwapMainField.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35D0D43137223A01FC2DA /* MultiSwapMainField.swift */; };
11B35504EF11FA59D2A358BE /* SendTonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35F5835A746165C520333 /* SendTonViewController.swift */; };
11B3550548CB49D32EAC1DF5 /* WatchlistWidget.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35B0879F715C0777919AA /* WatchlistWidget.swift */; };
11B3550846F2DD60D3778FE5 /* EvmSendHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35B0F9BC5C4CDBC5B041D /* EvmSendHandler.swift */; };
11B35508E26446AC692EBAEF /* RecipientAndSlippageMultiSwapSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3599833F166185872A3AC /* RecipientAndSlippageMultiSwapSettingsView.swift */; };
Expand Down Expand Up @@ -549,7 +548,6 @@
11B356476D5E88F21C297B52 /* ManageAccountViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A38C734DF3157C84678 /* ManageAccountViewController.swift */; };
11B356485CB62582F79D4877 /* CheckboxCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35216E1F4300730E08C5D /* CheckboxCell.swift */; };
11B3564C551C6C76ECCE387D /* SendEvmViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35F6B511DA5E0C60ED156 /* SendEvmViewModel.swift */; };
11B3564E05702B4253453F23 /* SendTonFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35ECB140E2565C55165A0 /* SendTonFactory.swift */; };
11B3564FBC180A0E6D30BCFA /* TransactionsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35828C8D50D0A5B915B2A /* TransactionsModule.swift */; };
11B3565070D890657E004402 /* ManageWalletsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35CBBFEC11CAE6FDBCFFA /* ManageWalletsModule.swift */; };
11B356509E6083B971F37E0F /* Currency.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BE8A07A2ADE2F8D0012DE7F /* Currency.swift */; };
Expand Down Expand Up @@ -703,7 +701,6 @@
11B3581F4D975FC21B9A25F2 /* BtcBlockchainSettingsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3589893A8995F86F08B1C /* BtcBlockchainSettingsModule.swift */; };
11B3581F7CCCEE9F956266E8 /* InputStateWrapperView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35B18D0C02E331540538B /* InputStateWrapperView.swift */; };
11B35828C42630241AE8D0E0 /* BackupVerifyWordsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35FA70D9570CB2708E1CA /* BackupVerifyWordsService.swift */; };
11B3582C5AB8B2BF15962AE7 /* SendTonViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35F5835A746165C520333 /* SendTonViewController.swift */; };
11B3582D43032F1F2DAEE0E8 /* BalanceHiddenManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B352FBA1B29357E0120055 /* BalanceHiddenManager.swift */; };
11B35830E8C818E413DEAAFC /* RecipientAndSlippageMultiSwapSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3599833F166185872A3AC /* RecipientAndSlippageMultiSwapSettingsView.swift */; };
11B35831AF48B09CE3349E5C /* BalanceCoinIconHolder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3560C1FC3F73833FA4439 /* BalanceCoinIconHolder.swift */; };
Expand Down Expand Up @@ -758,7 +755,6 @@
11B358AA46441AF0A7DCAA89 /* NftActivityModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35252F90F25774BDD2CB3 /* NftActivityModule.swift */; };
11B358AE1CCD292DF2D2AC42 /* PrivateKeysViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A9DB4112F41D7FCAC12 /* PrivateKeysViewModel.swift */; };
11B358AE5241256C9AAFB588 /* SyncMode_v_0_24.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35CB98A27269A510F40EE /* SyncMode_v_0_24.swift */; };
11B358AFE8EC87CA1DEB4C22 /* SendTonService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A296A67CE158347A785 /* SendTonService.swift */; };
11B358B004B48988A1F6D888 /* AppUnlockViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35BC07CC9E523971ED20E /* AppUnlockViewModel.swift */; };
11B358B0576F63BE43947DD5 /* Account.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35614C6E244926AF48701 /* Account.swift */; };
11B358B0A260AC250BFE65DE /* CexDepositNetwork.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35799B0DCCF655F0766BF /* CexDepositNetwork.swift */; };
Expand Down Expand Up @@ -837,7 +833,6 @@
11B3597E4CCEF19A8E4D1222 /* BottomMultiSelectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B351AF16B02C80A859D535 /* BottomMultiSelectorViewController.swift */; };
11B3598300402F09E04EFCCE /* CoinAnalyticsIssuesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35466E6DC969B551B10D3 /* CoinAnalyticsIssuesView.swift */; };
11B35983B0C3D4EFC115043A /* MarkdownImageCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3563ED22080EE222848A5 /* MarkdownImageCell.swift */; };
11B35988DD7E3E4E2EEE4444 /* SendTonFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35ECB140E2565C55165A0 /* SendTonFactory.swift */; };
11B35989090E4AD4E3EB8D72 /* CoinAuditsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35ADF518A2F98FF673B4B /* CoinAuditsViewModel.swift */; };
11B3598A03285D980219B256 /* CheckboxCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35216E1F4300730E08C5D /* CheckboxCell.swift */; };
11B3598BE9C7A456A70B5DFD /* BackupVerifyWordsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B3576FCFC9394BA37975FC /* BackupVerifyWordsViewModel.swift */; };
Expand Down Expand Up @@ -1074,7 +1069,6 @@
11B35C3A0B6DE83A66371224 /* SetPasscodeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A10404D5E085E482CC7 /* SetPasscodeView.swift */; };
11B35C3AFFA5B40481AF15B9 /* AccountRecord_v_0_19.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B350F6C5F6ABC288511AF0 /* AccountRecord_v_0_19.swift */; };
11B35C43886D9A0F0C69EF33 /* EvmAccountRestoreStateStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35999E6C5518115365410 /* EvmAccountRestoreStateStorage.swift */; };
11B35C4797940E34E6361A83 /* SendTonService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35A296A67CE158347A785 /* SendTonService.swift */; };
11B35C47A06C0A4F7231C511 /* NftCollectionAssetsModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35100DD6E2DBF905FD19B /* NftCollectionAssetsModule.swift */; };
11B35C4A0250F05179488A91 /* CexWithdrawNetworkRaw.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B35EC03BB5316524050518 /* CexWithdrawNetworkRaw.swift */; };
11B35C4D4120D85CD32CAD0F /* TransactionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 11B350CCAA0C9F2F5279F680 /* TransactionsViewController.swift */; };
Expand Down Expand Up @@ -3626,7 +3620,6 @@
11B35A1AE56A94BEB52AC4D1 /* StorageMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StorageMigrator.swift; sourceTree = "<group>"; };
11B35A1C200EC15159154E3F /* ShortcutInputCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShortcutInputCell.swift; sourceTree = "<group>"; };
11B35A296048CDD27A26FE9E /* EvmAccountManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EvmAccountManager.swift; sourceTree = "<group>"; };
11B35A296A67CE158347A785 /* SendTonService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTonService.swift; sourceTree = "<group>"; };
11B35A2C34C3D62CCA5BFFB5 /* GuidesRepository.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GuidesRepository.swift; sourceTree = "<group>"; };
11B35A309C359456D7DF1A03 /* AppIconManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppIconManager.swift; sourceTree = "<group>"; };
11B35A36FFDA63E9668F1B24 /* CexWithdrawConfirmService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CexWithdrawConfirmService.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3832,7 +3825,6 @@
11B35EC03BB5316524050518 /* CexWithdrawNetworkRaw.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CexWithdrawNetworkRaw.swift; sourceTree = "<group>"; };
11B35EC5CADBD290DDD3DE1C /* GuideCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GuideCell.swift; sourceTree = "<group>"; };
11B35EC9E0E936067225C787 /* PoolSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PoolSource.swift; sourceTree = "<group>"; };
11B35ECB140E2565C55165A0 /* SendTonFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTonFactory.swift; sourceTree = "<group>"; };
11B35ECC6866F29A33129F06 /* NftHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NftHeaderView.swift; sourceTree = "<group>"; };
11B35ED0A8819AB7EA27D368 /* StatExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatExtensions.swift; sourceTree = "<group>"; };
11B35EDC73170179EA8F4CBE /* MultiSwapModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MultiSwapModule.swift; sourceTree = "<group>"; };
Expand All @@ -3853,7 +3845,6 @@
11B35F4A3C8D3D2C6579FD94 /* AlertPresenter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AlertPresenter.swift; sourceTree = "<group>"; };
11B35F4B9522FCCD91582AAF /* WalletElementServiceFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletElementServiceFactory.swift; sourceTree = "<group>"; };
11B35F57D462E2C9E9AEF67C /* LockManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LockManager.swift; sourceTree = "<group>"; };
11B35F5835A746165C520333 /* SendTonViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SendTonViewController.swift; sourceTree = "<group>"; };
11B35F5A3CC8C229C0849756 /* PublicKeysViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PublicKeysViewController.swift; sourceTree = "<group>"; };
11B35F5B696CF0677865FA2C /* DuressModeViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DuressModeViewModel.swift; sourceTree = "<group>"; };
11B35F60AFA103D0CD2369C3 /* BlockchainTokensView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BlockchainTokensView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5991,16 +5982,6 @@
path = ManageWallets;
sourceTree = "<group>";
};
11B35805423FC0A1C859B08E /* Ton */ = {
isa = PBXGroup;
children = (
11B35F5835A746165C520333 /* SendTonViewController.swift */,
11B35A296A67CE158347A785 /* SendTonService.swift */,
11B35ECB140E2565C55165A0 /* SendTonFactory.swift */,
);
path = Ton;
sourceTree = "<group>";
};
11B3580CFABA60F3840C093E /* DuressMode */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -8113,7 +8094,6 @@
ABC9A48552CF0C90E22686A9 /* SendBaseService.swift */,
ABC9AAF2ADD900F32D87C7BE /* SendViewModelOld.swift */,
ABC9ABE97578DC667CBDC11A /* BaseSendViewController.swift */,
11B35805423FC0A1C859B08E /* Ton */,
);
path = Platforms;
sourceTree = "<group>";
Expand Down Expand Up @@ -10528,9 +10508,6 @@
11B35927C89712EF8ED36981 /* InputRowModifier.swift in Sources */,
11B359926B194C0207B1C8E6 /* PreSendView.swift in Sources */,
11B35FA298822DABDB1CD109 /* PreSendViewModel.swift in Sources */,
11B35504EF11FA59D2A358BE /* SendTonViewController.swift in Sources */,
11B35C4797940E34E6361A83 /* SendTonService.swift in Sources */,
11B35988DD7E3E4E2EEE4444 /* SendTonFactory.swift in Sources */,
11B351581C801BF3A8415DBE /* TonAddressParserItem.swift in Sources */,
ABC9AA19453EBE2970EE6AE5 /* ReceiveAddressView.swift in Sources */,
ABC9A57D1DA5481E44DEE8C0 /* PrimaryCircleButtonStyle.swift in Sources */,
Expand Down Expand Up @@ -11988,9 +11965,6 @@
11B359D912BC5502A9FA0E57 /* InputRowModifier.swift in Sources */,
11B35283F8170DB664A77C2B /* PreSendView.swift in Sources */,
11B3598EE09251933E7FFD5D /* PreSendViewModel.swift in Sources */,
11B3582C5AB8B2BF15962AE7 /* SendTonViewController.swift in Sources */,
11B358AFE8EC87CA1DEB4C22 /* SendTonService.swift in Sources */,
11B3564E05702B4253453F23 /* SendTonFactory.swift in Sources */,
11B3556CAD6FE74AB654E8B2 /* TonAddressParserItem.swift in Sources */,
ABC9A8787536855069557477 /* ReceiveAddressView.swift in Sources */,
ABC9AD530352E51084B1B4B7 /* PrimaryCircleButtonStyle.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,44 +120,34 @@ extension JettonAdapter: IDepositAdapter {
}

extension JettonAdapter: ISendTonAdapter {
var availableBalance: Decimal {
balanceData.available
}

func validate(address: String) throws {
_ = try FriendlyAddress(string: address)
}

func estimateFee(recipient: String, amount: Decimal, comment: String?) async throws -> Decimal {
func estimateFee(recipient: FriendlyAddress, amount: TonAdapter.SendAmount, comment: String?) async throws -> Decimal {
guard let jettonBalance else {
throw EstimateError.noWalletAddress
}

let recipient = try FriendlyAddress(string: recipient)
let amount = Decimal(sign: .plus, exponent: jettonBalance.jetton.decimals, significand: amount).rounded(decimal: 0)

guard let kitAmount = BigUInt(amount.description) else {
throw AmountError.invalidAmount
}

let kitFee = try await tonKit.estimateFee(jettonWallet: jettonBalance.walletAddress, recipient: recipient, amount: kitAmount, comment: comment)

return Self.amount(kitAmount: kitFee, decimals: jettonBalance.jetton.decimals)
let kitFee = try await tonKit.estimateFee(jettonWallet: jettonBalance.walletAddress, recipient: recipient, amount: sendAmount(jettonBalance: jettonBalance, amount: amount), comment: comment)
return TonAdapter.amount(kitAmount: kitFee)
}

func send(recipient: String, amount: Decimal, comment: String?) async throws {
func send(recipient: FriendlyAddress, amount: TonAdapter.SendAmount, comment: String?) async throws {
guard let jettonBalance else {
throw EstimateError.noWalletAddress
}

let recipient = try FriendlyAddress(string: recipient)
let amount = Decimal(sign: .plus, exponent: jettonBalance.jetton.decimals, significand: amount).rounded(decimal: 0)
try await tonKit.send(jettonWallet: jettonBalance.walletAddress, recipient: recipient, amount: sendAmount(jettonBalance: jettonBalance, amount: amount), comment: comment)
}

private func sendAmount(jettonBalance: JettonBalance, amount: TonAdapter.SendAmount) throws -> BigUInt {
switch amount {
case let .amount(value):
guard let value = BigUInt(value.hs.roundedString(decimal: jettonBalance.jetton.decimals)) else {
throw AmountError.invalidAmount
}

guard let kitAmount = BigUInt(amount.description) else {
return value
case .max:
throw AmountError.invalidAmount
}

try await tonKit.send(jettonWallet: jettonBalance.walletAddress, recipient: recipient, amount: kitAmount, comment: comment)
}
}

Expand Down
Loading

0 comments on commit b1aeec8

Please sign in to comment.