diff --git a/blockchain-demo/.gitignore b/blockchain-demo/.gitignore deleted file mode 100644 index 796b96d1c4..0000000000 --- a/blockchain-demo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/build diff --git a/blockchain-demo/build.gradle b/blockchain-demo/build.gradle deleted file mode 100644 index 934f45b26c..0000000000 --- a/blockchain-demo/build.gradle +++ /dev/null @@ -1,64 +0,0 @@ -apply plugin: 'com.android.application' -apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' -apply plugin: 'kotlin-kapt' - -android { - compileSdkVersion 29 - buildToolsVersion "29.0.2" - - - defaultConfig { - applicationId "com.example.blockchain_demo" - minSdkVersion 21 - targetSdkVersion 29 - versionCode 1 - versionName "1.0" - - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' - } - } - - compileOptions { - sourceCompatibility JavaVersion.VERSION_1_8 - targetCompatibility JavaVersion.VERSION_1_8 - } - kotlinOptions { - jvmTarget = '1.8' - } - - packagingOptions { - exclude 'lib/x86_64/darwin/libscrypt.dylib' - exclude 'lib/x86_64/freebsd/libscrypt.so' - exclude 'lib/x86_64/linux/libscrypt.so' - } - - viewBinding { - enabled = true - } -} - -dependencies { - implementation project(':blockchain') - - implementation 'com.tangem:core:0.10.4' - implementation 'com.tangem:sdk:0.10.4' - - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$versions.kotlin" - implementation 'androidx.appcompat:appcompat:1.1.0' - implementation 'androidx.core:core-ktx:1.2.0' - implementation 'androidx.constraintlayout:constraintlayout:1.1.3' - implementation 'com.google.android.material:material:1.1.0' - implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.3' - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-jdk8:1.3.3" - implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.3" - testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test.ext:junit:1.1.1' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' -} diff --git a/blockchain-demo/proguard-rules.pro b/blockchain-demo/proguard-rules.pro deleted file mode 100644 index f1b424510d..0000000000 --- a/blockchain-demo/proguard-rules.pro +++ /dev/null @@ -1,21 +0,0 @@ -# Add project specific ProGuard rules here. -# You can control the set of applied configuration files using the -# proguardFiles setting in build.gradle. -# -# For more details, see -# http://developer.android.com/guide/developing/tools/proguard.html - -# If your project uses WebView with JS, uncomment the following -# and specify the fully qualified class name to the JavaScript interface -# class: -#-keepclassmembers class fqcn.of.javascript.interface.for.webview { -# public *; -#} - -# Uncomment this to preserve the line number information for -# debugging stack traces. -#-keepattributes SourceFile,LineNumberTable - -# If you keep the line number information, uncomment this to -# hide the original source file name. -#-renamesourcefileattribute SourceFile diff --git a/blockchain-demo/src/androidTest/java/com/tangem/blockchain_demo/ExampleInstrumentedTest.kt b/blockchain-demo/src/androidTest/java/com/tangem/blockchain_demo/ExampleInstrumentedTest.kt deleted file mode 100644 index 2a03ebc11f..0000000000 --- a/blockchain-demo/src/androidTest/java/com/tangem/blockchain_demo/ExampleInstrumentedTest.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.tangem.blockchain_demo - -import androidx.test.ext.junit.runners.AndroidJUnit4 -import androidx.test.platform.app.InstrumentationRegistry -import org.junit.Assert.assertEquals -import org.junit.Test -import org.junit.runner.RunWith - -/** - * Instrumented test, which will execute on an Android device. - * - * See [testing documentation](http://d.android.com/tools/testing). - */ -@RunWith(AndroidJUnit4::class) -class ExampleInstrumentedTest { - @Test - fun useAppContext() { - // Context of the app under test. - val appContext = InstrumentationRegistry.getInstrumentation().targetContext - assertEquals("com.example.blockchain_demo", appContext.packageName) - } -} \ No newline at end of file diff --git a/blockchain-demo/src/main/AndroidManifest.xml b/blockchain-demo/src/main/AndroidManifest.xml deleted file mode 100644 index 9d092d68db..0000000000 --- a/blockchain-demo/src/main/AndroidManifest.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/blockchain-demo/src/main/java/com/tangem/blockchain_demo/BlockchainDemoActivity.kt b/blockchain-demo/src/main/java/com/tangem/blockchain_demo/BlockchainDemoActivity.kt deleted file mode 100644 index 038c0ea66c..0000000000 --- a/blockchain-demo/src/main/java/com/tangem/blockchain_demo/BlockchainDemoActivity.kt +++ /dev/null @@ -1,183 +0,0 @@ -package com.tangem.blockchain_demo - -import android.os.Bundle -import android.text.Editable -import android.widget.Toast -import androidx.appcompat.app.AppCompatActivity -import com.tangem.TangemSdk -import com.tangem.TangemSdkError -import com.tangem.blockchain.common.* -import com.tangem.blockchain.extensions.Result -import com.tangem.blockchain.extensions.Signer -import com.tangem.blockchain.extensions.SimpleResult -import com.tangem.blockchain_demo.databinding.ActivityBlockchainDemoBinding -import com.tangem.commands.Card -import com.tangem.common.CompletionResult -import com.tangem.tangem_sdk_new.extensions.init -import kotlinx.coroutines.* -import java.math.BigDecimal -import kotlin.coroutines.CoroutineContext - -class BlockchainDemoActivity : AppCompatActivity() { - - private lateinit var tangemSdk: TangemSdk - private lateinit var signer: TransactionSigner - private lateinit var card: Card - private lateinit var walletManager: WalletManager - private var issuerDataCounter: Int = 1 - - private lateinit var fee: BigDecimal - - private lateinit var binding: ActivityBlockchainDemoBinding - - private val parentJob = Job() - private val exceptionHandler = CoroutineExceptionHandler { _, throwable -> - handleError(throwable.localizedMessage) - } - private val coroutineContext: CoroutineContext - get() = parentJob + Dispatchers.IO + exceptionHandler - private val scope = CoroutineScope(coroutineContext) - - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - - binding = ActivityBlockchainDemoBinding.inflate(layoutInflater) - val view = binding.root - setContentView(view) - - tangemSdk = TangemSdk.init(this) - signer = Signer(tangemSdk) - - binding.btnScan.setOnClickListener { scan() } - - binding.btnCheckFee.setOnClickListener { requestFee() } - - binding.btnSend.setOnClickListener { send() } - } - - - private fun scan() { - tangemSdk.scanCard { result -> - when (result) { - is CompletionResult.Success -> { - walletManager = WalletManagerFactory.makeWalletManager(result.data)!! - getInfo() - } - is CompletionResult.Failure -> { - if (result.error !is TangemSdkError.UserCancelled) { - handleError(result.error.toString()) - } - } - } - } - } - - private fun getInfo() { - scope.launch { - walletManager.update() - withContext(Dispatchers.Main) { - binding.tvBalance.text = - "${walletManager.wallet.amounts[AmountType.Coin]?.value?.toPlainString() - ?: "error"} ${walletManager.wallet.blockchain.currency}" - val token = walletManager.wallet.amounts[AmountType.Token] - if (token != null) { - binding.tvBalance.text = token.value?.toPlainString() + " " + token.currencySymbol - binding.etSumToSend.text = Editable.Factory.getInstance().newEditable( - token.value?.toPlainString() ?: "" - ) - } else { - binding.etSumToSend.text = - Editable.Factory.getInstance().newEditable( - walletManager.wallet.amounts[AmountType.Coin]?.value?.toPlainString() - ) - } - binding.btnCheckFee.isEnabled = true - } - } - } - - private fun requestFee() { - if (binding.etReceiverAddress.text.isBlank()) { - Toast.makeText(this, "Please enter receiver address", Toast.LENGTH_LONG).show() - return - } else if (binding.etSumToSend.text.isBlank()) { - Toast.makeText(this, "Choose sum to send", Toast.LENGTH_LONG).show() - return - } - - scope.launch { - val feeResult = (walletManager as TransactionSender).getFee( - walletManager.wallet.amounts[AmountType.Token] - ?: walletManager.wallet.amounts[AmountType.Coin]!!, - binding.etReceiverAddress.text.toString()) - withContext(Dispatchers.Main) { - when (feeResult) { - is Result.Failure -> { - handleError(feeResult.error?.localizedMessage ?: "Error") - } - is Result.Success -> { - binding.btnSend.isEnabled = true - val fees = feeResult.data - if (fees.size == 1) { - binding.tvFee.text = fees[0].value.toString() - fee = fees[0].value ?: BigDecimal(0) - } else { - binding.tvFee.text = fees[0].value.toString() + "\n" + - fees[1].value.toString() + "\n" + - fees[2].value.toString() - fee = fees[1].value ?: BigDecimal(0) - - } - } - } - } - } - } - - private fun send() { - scope.launch { - val result = (walletManager as TransactionSender).send( - formTransactionData(), - signer) - withContext(Dispatchers.Main) { - when (result) { - is SimpleResult.Failure -> { - handleError(result.error?.localizedMessage ?: "Error") - } - is SimpleResult.Success -> { - binding.tvFee.text = "Success" - } - } - } - } - } - - private fun formTransactionData(): TransactionData { - val amount = if (walletManager.wallet.amounts[AmountType.Token] != null) { - walletManager.wallet.amounts[AmountType.Token]!!.copy( - value = binding.etSumToSend.text.toString().toBigDecimal() - ) - } else { - walletManager.wallet.amounts[AmountType.Coin]!!.copy( - value = binding.etSumToSend.text.toString().toBigDecimal() - fee - ) - } - return TransactionData( - amount, - walletManager.wallet.amounts[AmountType.Coin]!!.copy(value = fee), - walletManager.wallet.amounts[AmountType.Coin]!!.address!!, - binding.etReceiverAddress.text.toString(), - contractAddress = walletManager.wallet.amounts[AmountType.Token]?.address - ) - } - - private fun handleError(error: String?) { - Toast.makeText(this, error, Toast.LENGTH_LONG).show() - } - - override fun onDestroy() { - super.onDestroy() - scope.cancel() - } -} \ No newline at end of file diff --git a/blockchain-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml b/blockchain-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml deleted file mode 100644 index 1f6bb29060..0000000000 --- a/blockchain-demo/src/main/res/drawable-v24/ic_launcher_foreground.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - - - - diff --git a/blockchain-demo/src/main/res/drawable/ic_launcher_background.xml b/blockchain-demo/src/main/res/drawable/ic_launcher_background.xml deleted file mode 100644 index 0d025f9bf6..0000000000 --- a/blockchain-demo/src/main/res/drawable/ic_launcher_background.xml +++ /dev/null @@ -1,170 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/blockchain-demo/src/main/res/layout/activity_blockchain_demo.xml b/blockchain-demo/src/main/res/layout/activity_blockchain_demo.xml deleted file mode 100644 index faa8ad1d9e..0000000000 --- a/blockchain-demo/src/main/res/layout/activity_blockchain_demo.xml +++ /dev/null @@ -1,96 +0,0 @@ - - - - - - - - - - - - - -