Skip to content

Commit

Permalink
Merge pull request #973 from tari-project/master
Browse files Browse the repository at this point in the history
feat: dev update
  • Loading branch information
alexandrVakhtinTari authored Aug 31, 2023
2 parents 592c7b6 + 4becc10 commit 7e03ce7
Show file tree
Hide file tree
Showing 109 changed files with 3,351 additions and 3,039 deletions.
11 changes: 0 additions & 11 deletions .github/dependabot.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ import com.tari.android.wallet.application.deeplinks.DeeplinkHandler
import com.tari.android.wallet.data.sharedPrefs.network.NetworkRepository
import com.tari.android.wallet.data.sharedPrefs.network.TariNetwork
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNotNull
import org.junit.Assert.assertNull
import org.junit.Test

class DeepLinkTest {
Expand All @@ -47,41 +45,6 @@ class DeepLinkTest {
private val deeplinkHandler: DeeplinkHandler = DeeplinkHandler(networkRepository)
private val currentNetwork = Network.STAGENET

@Test
fun assertNetwork() {
val nullLink = "tari://mainnet/${DeepLink.Send.sendCommand}?${DeepLink.Send.tariAddressKey}=$PUBLIC_KEY"
val nullResult = deeplinkHandler.handle(nullLink) as? DeepLink.ContactlessPayment
assertNull(nullResult)

val notNullLink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.tariAddressKey}=$PUBLIC_KEY"
val notNullResult = deeplinkHandler.handle(notNullLink) as? DeepLink.ContactlessPayment
assertNotNull(notNullResult)
}

@Test
fun assertNode() {
val deeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.noteKey}=hey"
val result = deeplinkHandler.handle(deeplink) as? DeepLink.ContactlessPayment
assertEquals(result!!.note, "hey")

val cyrillicDeeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.noteKey}=привет"
val cyrillicResult = deeplinkHandler.handle(cyrillicDeeplink) as? DeepLink.ContactlessPayment
assertEquals(cyrillicResult!!.note, "привет")
}

@Test
fun assertPubkey() {
val deeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.tariAddressKey}=$PUBLIC_KEY"
val result = deeplinkHandler.handle(deeplink) as? DeepLink.ContactlessPayment
assertEquals(result!!.walletAddress, PUBLIC_KEY)
}

@Test
fun assertAmount() {
val deeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.amountKey}=12345678"
val result = deeplinkHandler.handle(deeplink) as? DeepLink.ContactlessPayment
assertEquals(result!!.amount!!.tariValue.toDouble(), 12.345678, 0.1)
}

@Test
fun assertBaseNodeName() {
Expand All @@ -97,21 +60,6 @@ class DeepLinkTest {
assertEquals(result!!.peer, PEER)
}

@Test
fun assertFullDataDeeplinks() {
val sendDeeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.Send.sendCommand}?${DeepLink.Send.amountKey}=12345678&${DeepLink.Send.noteKey}=hey&${DeepLink.Send.tariAddressKey}=$PUBLIC_KEY"
val result = deeplinkHandler.handle(sendDeeplink) as? DeepLink.ContactlessPayment
assertEquals(result!!.note, "hey")
assertEquals(result.walletAddress, PUBLIC_KEY)
assertEquals(result.amount!!.tariValue.toDouble(), 12.345678, 0.1)

val baseNodeDeeplink = "tari://${currentNetwork.uriComponent}/${DeepLink.AddBaseNode.addNodeCommand}?${DeepLink.AddBaseNode.peerKey}=${PEER}&${DeepLink.AddBaseNode.nameKey}=actual_name"
val baseNodeResult = deeplinkHandler.handle(baseNodeDeeplink) as? DeepLink.AddBaseNode
assertEquals(baseNodeResult!!.peer, PEER)
assertEquals(baseNodeResult.name, "actual_name")
}


companion object {
private const val PUBLIC_KEY = "2e93c460DF49D8CFBBF7A06DD9004C25A84F92584F7D0AC5E30BD8E0BEEE9A43"
private const val PEER =
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/cpp/jniOutputFeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ Java_com_tari_android_wallet_ffi_FFIOutputFeatures_jniCreate(

TariOutputFeatures *pOutputFeatures = output_features_create_from_bytes(
version,
//todo
0,
maturity,
pMetadata,
0,
errorPointer);

SetPointerField(jEnv, jThis, reinterpret_cast<jlong>(pOutputFeatures));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import javax.inject.Singleton
@Singleton
class MigrationManager @Inject constructor(private val manager: WalletManager) {

private val minValidVersion = DefaultArtifactVersion("0.49.0-rc.2")
private val minValidVersion = DefaultArtifactVersion("0.50.0-hotfix.1")
private val simpleViewModel = SimpleViewModel()

fun validateVersion(onValid: () -> Unit, onError: () -> Unit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class BaseNodes(
* Select a base node randomly from the list of base nodes in base_nodes.tx, and sets
* the wallet and stored the values in shared prefs.
*/
@Synchronized
fun setNextBaseNode() {
if (!this::baseNodeIterator.isInitialized || !baseNodeIterator.hasNext()) {
baseNodeIterator = baseNodeList.iterator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.tari.android.wallet.application.deeplinks
import android.net.Uri
import com.tari.android.wallet.data.sharedPrefs.network.NetworkRepository
import java.net.URLDecoder
import javax.inject.Inject
import javax.inject.Singleton

class DeeplinkFormatter(private val networkRepository: NetworkRepository) {
@Singleton
class DeeplinkFormatter @Inject constructor(private val networkRepository: NetworkRepository) {
fun parse(deepLink: String): DeepLink? {
val uri = Uri.parse(URLDecoder.decode(deepLink, "UTF-8"))

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.tari.android.wallet.application.deeplinks

import android.content.Context
import com.tari.android.wallet.R
import com.tari.android.wallet.application.baseNodes.BaseNodes
import com.tari.android.wallet.data.sharedPrefs.baseNode.BaseNodeDto
Expand All @@ -11,7 +10,6 @@ import com.tari.android.wallet.model.TariWalletAddress
import com.tari.android.wallet.ui.common.CommonViewModel
import com.tari.android.wallet.ui.dialog.confirm.ConfirmDialogArgs
import com.tari.android.wallet.ui.dialog.modular.DialogArgs
import com.tari.android.wallet.ui.dialog.modular.ModularDialog
import com.tari.android.wallet.ui.dialog.modular.ModularDialogArgs
import com.tari.android.wallet.ui.dialog.modular.modules.body.BodyModule
import com.tari.android.wallet.ui.dialog.modular.modules.button.ButtonModule
Expand Down Expand Up @@ -41,47 +39,56 @@ class DeeplinkViewModel : CommonViewModel() {
component.inject(this)
}

fun tryToHandle(context:Context, qrData: String) {
deeplinkHandler.handle(qrData)?.let { execute(context, it) }
fun tryToHandle(qrData: String) {
deeplinkHandler.handle(qrData)?.let { execute(it) }
}

fun execute(context: Context, deeplink: DeepLink) {
fun execute(deeplink: DeepLink) {
when (deeplink) {
is DeepLink.AddBaseNode -> addBaseNode(context, deeplink)
is DeepLink.Contacts -> addContacts(deeplink.contacts)
is DeepLink.Send -> send(deeplink)
is DeepLink.UserProfile -> addContacts(listOf(DeepLink.Contacts.DeeplinkContact(deeplink.alias, deeplink.tariAddressHex)))
is DeepLink.AddBaseNode -> addBaseNode(deeplink)
is DeepLink.Contacts -> addContacts(deeplink)
is DeepLink.Send -> sendAction(deeplink)
is DeepLink.UserProfile -> addUserProfile(deeplink)
}
}

fun addBaseNode(context: Context, deeplink: DeepLink.AddBaseNode) {
val baseNode = BaseNodeDto.fromDeeplink(deeplink)
fun addBaseNode(deeplink: DeepLink.AddBaseNode) {
val baseNode = getData(deeplink)
val args = ConfirmDialogArgs(
resourceManager.getString(R.string.home_custom_base_node_title),
resourceManager.getString(R.string.home_custom_base_node_description),
resourceManager.getString(R.string.home_custom_base_node_no_button),
resourceManager.getString(R.string.common_lets_do_it),
onConfirm = { addBaseNode(baseNode) }
onConfirm = {
dismissDialog.postValue(Unit)
addBaseNodeAction(baseNode)
}
).getModular(baseNode, resourceManager)
ModularDialog(context, args).show()
modularDialog.postValue(args)
}

fun addContacts(contacts: List<DeepLink.Contacts.DeeplinkContact>) {
val contactDtos = contacts.mapNotNull {
runCatching {
val ffiWalletAddress = FFITariWalletAddress(HexString(it.hex))
val tariWalletAddress = TariWalletAddress(ffiWalletAddress.toString(), ffiWalletAddress.getEmojiId())
ContactDto(FFIContactDto(tariWalletAddress, it.alias))
}.getOrNull()
}
fun addUserProfile(deeplink: DeepLink.UserProfile) {
val contact = DeepLink.Contacts(
listOf(
DeepLink.Contacts.DeeplinkContact(
deeplink.alias,
deeplink.tariAddressHex
)
)
)
addContacts(contact)
}

fun addContacts(contacts: DeepLink.Contacts) {
val contactDtos = getData(contacts)
if (contactDtos.isEmpty()) return
val names = contactDtos.joinToString(", ") { it.contact.getAlias().trim() }
val args = ModularDialogArgs(
DialogArgs(), listOf(
HeadModule(resourceManager.getString(R.string.contact_deeplink_title)),
BodyModule(resourceManager.getString(R.string.contact_deeplink_message, contactDtos.size.toString()) + ". " + names),
ButtonModule(resourceManager.getString(R.string.common_confirm), ButtonStyle.Normal) {
contactDtos.forEach { contactRepository.addContact(it) }
addContactsAction(contactDtos)
dismissDialog.postValue(Unit)
},
ButtonModule(resourceManager.getString(R.string.common_cancel), ButtonStyle.Close)
Expand All @@ -90,17 +97,47 @@ class DeeplinkViewModel : CommonViewModel() {
modularDialog.postValue(args)
}

fun send(deeplink: DeepLink.Send) {
val contactDto = runCatching {
val ffiWalletAddress = FFITariWalletAddress(HexString(deeplink.walletAddressHex))
fun executeRawDeeplink(deeplink: DeepLink) {
when (deeplink) {
is DeepLink.AddBaseNode -> addBaseNode(deeplink)
is DeepLink.Contacts -> addContactsAction(getData(deeplink))
is DeepLink.Send -> sendAction(deeplink)
is DeepLink.UserProfile -> addContactsAction(getData(deeplink)?.let { listOf(it) } ?: listOf())
}
}

private fun getData(deeplink: DeepLink.AddBaseNode): BaseNodeDto = BaseNodeDto.fromDeeplink(deeplink)

private fun getData(deeplink: DeepLink.Contacts): List<ContactDto> = deeplink.contacts.mapNotNull {
runCatching {
val ffiWalletAddress = FFITariWalletAddress(HexString(it.hex))
val tariWalletAddress = TariWalletAddress(ffiWalletAddress.toString(), ffiWalletAddress.getEmojiId())
ContactDto(FFIContactDto(tariWalletAddress, ""))
}.getOrNull() ?: return
ContactDto(FFIContactDto(tariWalletAddress, it.alias))
}.getOrNull()
}

private fun getData(deeplink: DeepLink.Send): ContactDto? = runCatching {
val ffiWalletAddress = FFITariWalletAddress(HexString(deeplink.walletAddressHex))
val tariWalletAddress = TariWalletAddress(ffiWalletAddress.toString(), ffiWalletAddress.getEmojiId())
ContactDto(FFIContactDto(tariWalletAddress, ""))
}.getOrNull()

private fun getData(userProfile: DeepLink.UserProfile): ContactDto? = runCatching {
val ffiWalletAddress = FFITariWalletAddress(HexString(userProfile.tariAddressHex))
val tariWalletAddress = TariWalletAddress(ffiWalletAddress.toString(), ffiWalletAddress.getEmojiId())
ContactDto(FFIContactDto(tariWalletAddress, userProfile.alias))
}.getOrNull()

private fun addContactsAction(contacts: List<ContactDto>) {
_backPressed.postValue(Unit)
contacts.forEach { contactRepository.addContact(it) }
}

navigation.postValue(Navigation.TxListNavigation.ToSendTariToUser(contactDto))
private fun sendAction(deeplink: DeepLink.Send) {
navigation.postValue(Navigation.TxListNavigation.ToSendWithDeeplink(deeplink))
}

private fun addBaseNode(baseNodeDto: BaseNodeDto) {
private fun addBaseNodeAction(baseNodeDto: BaseNodeDto) {
baseNodeRepository.addUserBaseNode(baseNodeDto)
baseNodes.setBaseNode(baseNodeDto)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class SharedPrefsRepository @Inject constructor(
const val surname = "tari_wallet_surname_"
const val onboardingStarted = "tari_wallet_onboarding_started"
const val onboardingAuthSetupCompleted = "tari_wallet_onboarding_auth_setup_completed"
const val actionMenuSide = "tari_wallet_action_menu_side"
const val onboardingAuthSetupStarted = "tari_wallet_onboarding_auth_setup_started"
const val onboardingCompleted = "tari_wallet_onboarding_completed"
const val onboardingDisplayedAtHome = "tari_wallet_onboarding_displayed_at_home"
Expand Down Expand Up @@ -107,6 +108,8 @@ class SharedPrefsRepository @Inject constructor(

var onboardingAuthSetupCompleted: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.onboardingAuthSetupCompleted))

var actionMenuSide: Boolean by SharedPrefBooleanDelegate(sharedPrefs, this, formatKey(Key.actionMenuSide))

val onboardingAuthWasInterrupted: Boolean
get() = onboardingAuthSetupStarted && !onboardingAuthSetupCompleted

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,18 @@ import com.tari.android.wallet.ui.fragment.contact_book.details.ContactDetailsVi
import com.tari.android.wallet.ui.fragment.contact_book.link.ContactLinkViewModel
import com.tari.android.wallet.ui.fragment.contact_book.root.ContactBookViewModel
import com.tari.android.wallet.ui.fragment.contact_book.root.ShareViewModel
import com.tari.android.wallet.ui.fragment.contact_book.root.action_menu.ContactBookActionMenuViewModel
import com.tari.android.wallet.ui.fragment.contact_book.transactionHistory.TransactionHistoryViewModel
import com.tari.android.wallet.ui.fragment.home.HomeActivity
import com.tari.android.wallet.ui.fragment.home.HomeViewModel
import com.tari.android.wallet.ui.fragment.home.homeTransactionHistory.HomeTransactionHistoryViewModel
import com.tari.android.wallet.ui.fragment.onboarding.activity.OnboardingFlowActivity
import com.tari.android.wallet.ui.fragment.onboarding.createWallet.CreateWalletViewModel
import com.tari.android.wallet.ui.fragment.onboarding.inroduction.IntroductionViewModel
import com.tari.android.wallet.ui.fragment.onboarding.localAuth.LocalAuthViewModel
import com.tari.android.wallet.ui.fragment.profile.WalletInfoViewModel
import com.tari.android.wallet.ui.fragment.qr.QRScannerActivity
import com.tari.android.wallet.ui.fragment.qr.QRScannerViewModel
import com.tari.android.wallet.ui.fragment.restore.activity.WalletRestoreActivity
import com.tari.android.wallet.ui.fragment.restore.chooseRestoreOption.ChooseRestoreOptionViewModel
import com.tari.android.wallet.ui.fragment.restore.enterRestorationPassword.EnterRestorationPasswordViewModel
Expand All @@ -69,6 +72,7 @@ import com.tari.android.wallet.ui.fragment.send.addNote.gif.ChooseGIFDialogFragm
import com.tari.android.wallet.ui.fragment.send.addNote.gif.ThumbnailGIFsViewModel
import com.tari.android.wallet.ui.fragment.send.finalize.FinalizeSendTxViewModel
import com.tari.android.wallet.ui.fragment.send.requestTari.RequestTariViewModel
import com.tari.android.wallet.ui.fragment.send.transfer.TransferFragment
import com.tari.android.wallet.ui.fragment.settings.allSettings.AllSettingsViewModel
import com.tari.android.wallet.ui.fragment.settings.allSettings.about.TariAboutViewModel
import com.tari.android.wallet.ui.fragment.settings.backgroundService.BackgroundServiceSettingsViewModel
Expand All @@ -93,8 +97,8 @@ import com.tari.android.wallet.ui.fragment.settings.torBridges.TorBridgesSelecti
import com.tari.android.wallet.ui.fragment.settings.torBridges.customBridges.CustomTorBridgesViewModel
import com.tari.android.wallet.ui.fragment.settings.userAutorization.BiometricAuthenticationViewModel
import com.tari.android.wallet.ui.fragment.splash.SplashActivity
import com.tari.android.wallet.ui.fragment.tx.HomeFragmentViewModel
import com.tari.android.wallet.ui.fragment.tx.TransactionRepository
import com.tari.android.wallet.ui.fragment.tx.TxListViewModel
import com.tari.android.wallet.ui.fragment.tx.details.TxDetailsViewModel
import com.tari.android.wallet.ui.fragment.tx.details.gif.GIFViewModel
import com.tari.android.wallet.ui.fragment.utxos.list.UtxosListViewModel
Expand Down Expand Up @@ -146,7 +150,6 @@ interface ApplicationComponent {
fun inject(viewModel: VerifySeedPhraseViewModel)
fun inject(viewModel: BackupSettingsViewModel)
fun inject(viewModel: BiometricAuthenticationViewModel)
fun inject(viewModel: TxListViewModel)
fun inject(viewModel: ChangeBaseNodeViewModel)
fun inject(viewModel: AddCustomBaseNodeViewModel)
fun inject(viewModel: NetworkSelectionViewModel)
Expand All @@ -172,6 +175,8 @@ interface ApplicationComponent {
fun inject(viewModel: ThemeSelectorViewModel)
fun inject(viewModel: DeleteWalletViewModel)
fun inject(viewModel: HomeViewModel)
fun inject(viewModel: HomeFragmentViewModel)
fun inject(viewModel: HomeTransactionHistoryViewModel)
fun inject(viewModel: EnterCurrentPasswordViewModel)
fun inject(viewModel: ChangeSecurePasswordViewModel)
fun inject(viewModel: AddNoteViewModel)
Expand All @@ -189,6 +194,9 @@ interface ApplicationComponent {
fun inject(viewModel: TransactionHistoryViewModel)
fun inject(viewModel: BluetoothSettingsViewModel)
fun inject(viewModel: WalletAddressViewModel)
fun inject(viewModel: QRScannerViewModel)
fun inject(viewModel: TransferFragment)
fun inject(viewModel: ContactBookActionMenuViewModel)

fun getClipboardManager(): ClipboardManager
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,16 @@ package com.tari.android.wallet.extension

import android.content.Context
import android.graphics.Typeface
import android.text.*
import android.text.style.*
import com.tari.android.wallet.ui.component.tari.*
import android.text.Layout
import android.text.SpannableString
import android.text.Spanned
import android.text.style.AlignmentSpan
import android.text.style.ForegroundColorSpan
import android.text.style.RelativeSizeSpan
import android.text.style.URLSpan
import com.tari.android.wallet.ui.component.tari.TariFont
import com.tari.android.wallet.ui.component.tari.TariLetterSpacingSpan
import com.tari.android.wallet.ui.component.tari.TariTypefaceSpan

/**
* Process the URLs in the given spannable string.
Expand Down Expand Up @@ -97,7 +104,7 @@ fun String.applyColorStyle(defaultColor: Int, search: List<String>, styleColor:
fun SpannableString.applyColorStyle(search: String, color: Int, applyToOnlyFirstOccurrence: Boolean = false) {
var index = this.indexOf(search)
while (index >= 0) {
setSpan(ForegroundColorSpan(color), index, index + search.length, Spanned.SPAN_INTERMEDIATE)
setSpan(ForegroundColorSpan(color), index, index + search.length, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
if (applyToOnlyFirstOccurrence) {
break
}
Expand Down
Loading

0 comments on commit 7e03ce7

Please sign in to comment.