diff --git a/wallet_app/android/app/build.gradle.kts b/wallet_app/android/app/build.gradle.kts index 9848bcf6..c955a0f3 100644 --- a/wallet_app/android/app/build.gradle.kts +++ b/wallet_app/android/app/build.gradle.kts @@ -25,15 +25,13 @@ android { targetSdk = 34 versionCode = 1 versionName = "1.0" - testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" - buildConfigField("String", "DEMO_RPC_URL", "\"https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/${properties.getProperty("KEY_NAME")}\"") - buildConfigField("String", "DEMO_ACCOUNT_ADDRESS", "\"0x02dc260794e4c2eeae87b1403a88385a72c18a5844d220b88117b2965a8cf3a5\"") - buildConfigField("String", "DEMO_PRIVATE_KEY", "\"rFAP8fkTAz9TmYw8_V5Fyzxi-WSoQdhk\"") - buildConfigField("String", "DEMO_RECIPIENT_ACCOUNT_ADDRESS", "\"0xc1c7db92d22ef773de96f8bde8e56c85\"") + buildConfigField("String", "RPC_URL", "\"${properties.getProperty("RPC_URL")}\"") + buildConfigField("String", "ACCOUNT_ADDRESS", "\"${properties.getProperty("ACCOUNT_ADDRESS")}\"") + buildConfigField("String", "PRIVATE_KEY", "\"${properties.getProperty("KEY_NAME")}\"") } buildTypes { @@ -98,6 +96,7 @@ dependencies { implementation(libs.androidx.hilt.navigation.fragment) implementation (libs.androidx.hilt.navigation.compose.v100alpha03) + implementation(libs.androidx.ui.tooling.preview) debugImplementation(libs.androidx.ui.tooling) diff --git a/wallet_app/android/app/src/main/java/com/example/walletapp/MainActivity.kt b/wallet_app/android/app/src/main/java/com/example/walletapp/MainActivity.kt index 7c5c499d..15ce801d 100644 --- a/wallet_app/android/app/src/main/java/com/example/walletapp/MainActivity.kt +++ b/wallet_app/android/app/src/main/java/com/example/walletapp/MainActivity.kt @@ -71,7 +71,7 @@ fun StarknetLogo (modifier: Modifier = Modifier) { fun CreateAccount( modifier: Modifier) { val context = (LocalContext.current as Activity) val scope = rememberCoroutineScope() - val starknetClient = StarknetClient(BuildConfig.DEMO_RPC_URL) + val starknetClient = StarknetClient(BuildConfig.RPC_URL) Column( modifier = Modifier diff --git a/wallet_app/android/app/src/main/java/com/example/walletapp/StarknetClient.kt b/wallet_app/android/app/src/main/java/com/example/walletapp/StarknetClient.kt index 0cbf35aa..efe38aea 100644 --- a/wallet_app/android/app/src/main/java/com/example/walletapp/StarknetClient.kt +++ b/wallet_app/android/app/src/main/java/com/example/walletapp/StarknetClient.kt @@ -1,3 +1,4 @@ +import com.example.walletapp.BuildConfig import com.swmansion.starknet.account.StandardAccount import com.swmansion.starknet.data.types.Call import com.swmansion.starknet.data.types.Felt @@ -12,12 +13,15 @@ const val ETH_ERC20_ADDRESS = "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741 class StarknetClient(private val rpcUrl: String) { private val provider = JsonRpcProvider(rpcUrl) + private val privateKey=BuildConfig.PRIVATE_KEY + private val accountAddress=BuildConfig.ACCOUNT_ADDRESS suspend fun deployAccount() { + // Predefined values for account creation - val privateKey = Felt.fromHex("0x2bbf4f9fd0bbb2e60b0316c1fe0b76cf7a4d0198bd493ced9b8df2a3a24d68a") // TODO(#80): Load from local.properties - val accountAddress = Felt.fromHex("0xb3ff441a68610b30fd5e2abbf3a1548eb6ba6f3559f2862bf2dc757e5828ca") // TODO(#80): Load from local.properties + val privateKey = Felt.fromHex(privateKey) + val accountAddress = Felt.fromHex(accountAddress) val signer = StarkCurveSigner(privateKey) val chainId = provider.getChainId().sendAsync().await() diff --git a/wallet_app/android/app/src/main/java/com/example/walletapp/WalletActivity.kt b/wallet_app/android/app/src/main/java/com/example/walletapp/WalletActivity.kt index d1807170..74d6621c 100644 --- a/wallet_app/android/app/src/main/java/com/example/walletapp/WalletActivity.kt +++ b/wallet_app/android/app/src/main/java/com/example/walletapp/WalletActivity.kt @@ -1,8 +1,10 @@ package com.example.walletapp +import StarknetClient import android.app.Activity import android.content.Intent import android.os.Bundle +import android.widget.Toast import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.compose.foundation.Image @@ -54,6 +56,12 @@ import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.window.Popup import androidx.compose.ui.window.PopupProperties +import com.swmansion.starknet.data.types.Felt +import com.swmansion.starknet.provider.exceptions.RpcRequestFailedException +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext +import java.math.BigDecimal +import java.text.DecimalFormat class WalletActivity : ComponentActivity() { @@ -80,6 +88,24 @@ class WalletActivity : ComponentActivity() { val networkList = listOf("Starknet Mainnet", "Test Networks") var selectedNetworkIndex by remember { mutableStateOf(0) } val context = (LocalContext.current as Activity) + val address=BuildConfig.ACCOUNT_ADDRESS + val accountAddress = Felt.fromHex(address) + val starknetClient = StarknetClient(BuildConfig.RPC_URL) + var balance by remember { mutableStateOf("") } + + LaunchedEffect (Unit){ + try { + // Get the balance of the account + val getBalance = starknetClient.getEthBalance(accountAddress) + withContext(Dispatchers.Main) { + balance = starknetClient.weiToEther(getBalance).toDoubleWithTwoDecimal() + } + } catch (e: RpcRequestFailedException) { + withContext(Dispatchers.Main) { Toast.makeText(context, "${e.code}: ${e.message}", Toast.LENGTH_LONG).show() } + } catch (e: Exception) { + withContext(Dispatchers.Main) { Toast.makeText(context, e.message, Toast.LENGTH_LONG).show() } + } + } Column( modifier = Modifier @@ -104,29 +130,29 @@ class WalletActivity : ComponentActivity() { Text( - text = "$11,625.48", // TODO(#82): load actual balance - fontFamily = FontFamily(Font(R.font.inter_regular)), + text ="$11,625.48", + fontFamily = FontFamily(Font(R.font.publicsans_bold)), color = Color.White, - fontSize = 28.sp, + fontSize = 24.sp, modifier = Modifier .align(Alignment.CenterHorizontally) .padding(top = 70.dp) ) Text( - text = "0xfoo...123", // TODO(#82): load actual address + text = address.take(10) + ".....", fontFamily = FontFamily(Font(R.font.inter_regular)), color = Color.White, - fontSize = 16.sp, + fontSize = 14.sp, modifier = Modifier.align(Alignment.CenterHorizontally) ) Spacer(modifier = Modifier.height(32.dp)) - // TODO(#82): load actual balance + WalletCard( icon = painterResource(id = R.drawable.ic_ethereum), amount = "$11,625.7", - exchange = 4.44, + exchange = balance, type = "ETH" ) @@ -134,7 +160,7 @@ class WalletActivity : ComponentActivity() { WalletCard( icon = painterResource(id = R.drawable.token2), amount = "$1.78", - exchange = 4.44, + exchange ="4.44", type = "STRK" ) @@ -194,9 +220,14 @@ class WalletActivity : ComponentActivity() { Spacer(modifier = Modifier.height(15.dp)) } } +// Function to format BigDecimal to Double with 2 decimal places +fun BigDecimal.toDoubleWithTwoDecimal(): String { + val decimalFormat = DecimalFormat("#.00") + return decimalFormat.format(this.toDouble()) +} @Composable - fun WalletCard(icon: Painter, amount: String, exchange: Double, type: String) { + fun WalletCard(icon: Painter, amount: String, exchange: String, type: String) { Card( backgroundColor = Color(0xFF1E1E96), modifier = Modifier @@ -223,16 +254,17 @@ class WalletActivity : ComponentActivity() { ) Row { Text( - text = exchange.toString(), - fontFamily = FontFamily(Font(R.font.inter_regular)), + text = exchange, + fontFamily = FontFamily(Font(R.font.publicsans_bold)), color = Color.White, - fontSize = 10.sp + fontSize = 14.sp ) + Spacer(modifier=Modifier.width(2.dp)) Text( text = type, fontFamily = FontFamily(Font(R.font.publicsans_bold)), color = Color.White, - fontSize = 10.sp + fontSize = 12.sp ) } diff --git a/wallet_app/android/app/src/main/java/com/example/walletapp/ui/activity/AccountBalanceActivity.kt b/wallet_app/android/app/src/main/java/com/example/walletapp/ui/activity/AccountBalanceActivity.kt index a60050a0..dc960f1e 100644 --- a/wallet_app/android/app/src/main/java/com/example/walletapp/ui/activity/AccountBalanceActivity.kt +++ b/wallet_app/android/app/src/main/java/com/example/walletapp/ui/activity/AccountBalanceActivity.kt @@ -81,7 +81,7 @@ class AccountBalanceActivity : ComponentActivity() { val scope = CoroutineScope(Dispatchers.IO) - val starknetClient = StarknetClient(BuildConfig.DEMO_RPC_URL) + val starknetClient = StarknetClient(BuildConfig.RPC_URL) Column(modifier = Modifier