Skip to content

Commit

Permalink
copy address and back button fixes (#133)
Browse files Browse the repository at this point in the history
* copy address and back button fixes

* Some minor changes

* Remove local.properties from repository
  • Loading branch information
sajalbnl authored Dec 15, 2024
1 parent 060cd20 commit ec30d92
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 149 deletions.
3 changes: 2 additions & 1 deletion wallet_app/app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
android/app/build
build
build
local.properties
2 changes: 2 additions & 0 deletions wallet_app/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ dependencies {
// Material Design 3
implementation(libs.androidx.material3)

implementation("com.google.android.material:material:1.11.0")

// Retrofit for network requests
implementation(libs.retrofit)
implementation(libs.converter.gson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import androidx.room.migration.Migration
import androidx.sqlite.db.SupportSQLiteDatabase
import com.example.walletapp.model.Token
import com.example.walletapp.utils.Converters
Expand All @@ -19,25 +20,45 @@ abstract class TokenDatabase : RoomDatabase() {

abstract fun tokenDao(): TokenDao



companion object {
@Volatile
private var INSTANCE: TokenDatabase? = null

val MIGRATION_1_2 = object : Migration(1, 2) {
override fun migrate(database: SupportSQLiteDatabase) {
// Create the Token table if it is new
database.execSQL(
"""
CREATE TABLE IF NOT EXISTS Token (
contactAddress TEXT NOT NULL PRIMARY KEY,
name TEXT NOT NULL,
symbol TEXT NOT NULL,
decimals INTEGER NOT NULL,
tokenId TEXT NOT NULL
)
""".trimIndent()
)
}
}
fun getDatabase(context: Context): TokenDatabase {
return INSTANCE ?: synchronized(this) {
val instance = Room.databaseBuilder(
context.applicationContext,
TokenDatabase::class.java,
"token_database"
)
.addCallback(DatabaseCallback()) // Add callback here
.addCallback(DatabaseCallback())
.addMigrations(MIGRATION_1_2)
.build()
INSTANCE = instance
instance
}
}
}


private class DatabaseCallback : RoomDatabase.Callback() {
override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,16 +106,16 @@ fun WalletApp(tokenViewModel: TokenViewModel) {
composable<AddToken> {
AddTokenScreen(
tokenViewModel=tokenViewModel,
navController: navController,
onConfirm = { navController.navigateUp() }
onConfirm = { navController.navigateUp() },
navController
)
}

composable<Send> {
SendScreen(walletViewModel)
SendScreen(walletViewModel,navController)
}
composable<Receive> {
ReceiveScreen(modifier = Modifier)
ReceiveScreen(modifier = Modifier,navController)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,12 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextField
import androidx.compose.material.TextFieldDefaults
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material3.Button
import androidx.compose.material3.ButtonDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.OutlinedTextFieldDefaults
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package com.example.walletapp.ui.account

import android.annotation.SuppressLint
import android.app.Activity
import android.util.Log
import androidx.compose.ui.platform.ClipboardManager
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
Expand All @@ -27,7 +26,6 @@ import androidx.compose.material3.Card
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
Expand All @@ -45,12 +43,15 @@ import androidx.compose.runtime.*
import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.toLowerCase
import android.content.ClipData
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.ui.Alignment
import androidx.compose.ui.text.toUpperCase
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties
Expand Down Expand Up @@ -108,6 +109,8 @@ fun Wallet(modifier: Modifier, onNewTokenPress: () -> Unit, onReceivePress: () -
val address= BuildConfig.ACCOUNT_ADDRESS
val accountAddress = Felt.fromHex(address)


val clipboard: ClipboardManager = LocalClipboardManager.current
var tokenImages by rememberSaveable { mutableStateOf<HashMap<String, String>>(hashMapOf()) }
val balances by walletViewModel.balances.collectAsState()
val coinsPrices by rememberSaveable { mutableStateOf<HashMap<String, Double>>(hashMapOf()) }
Expand Down Expand Up @@ -171,22 +174,40 @@ fun Wallet(modifier: Modifier, onNewTokenPress: () -> Unit, onReceivePress: () -

}.sum()
val formatter = NumberFormat.getCurrencyInstance(Locale.US)
Text(
text = formatter.format(totalBalance),
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 24.sp,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(top = 70.dp)
)
Text(
text = address.take(10) + ".....",
fontFamily = FontFamily(Font(R.font.inter_regular)),
color = Color.White,
fontSize = 14.sp,
modifier = Modifier.align(Alignment.CenterHorizontally)
)
Column(verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally, modifier = Modifier.fillMaxWidth()) {
Text(
text = formatter.format(totalBalance),
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 26.sp,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(top = 70.dp)
)
Row(
modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.Center
) {
Text(
text = address.take(8) + "...",
fontFamily = FontFamily(Font(R.font.inter_regular)),
color = Color.White,
fontSize = 12.sp,
)
Icon(
painter = painterResource(R.drawable.copy),// replace with your Ethereum icon
contentDescription = null,
tint = Color.White,
modifier = Modifier.padding(start = 5.dp)
.size(15.dp).clickable {
val clip = ClipEntry(ClipData.newPlainText("Wallet Address", address))
clipboard.setClip(clip)
Toast.makeText(context, "Address Copied", Toast.LENGTH_LONG).show()
}
)

}
}

Spacer(modifier = Modifier.height(32.dp))
val configuration = LocalConfiguration.current
val screenHeight = configuration.screenHeightDp.dp/2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@ fun CreateAccountScreen(
var progress by remember { mutableStateOf(0.5f) }
Scaffold(
topBar = {
TopAppBar(
backgroundColor = Color("#0C0C4F".toColorInt()),
contentColor = Color.White,
elevation = 4.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -97,22 +92,8 @@ fun CreateAccountScreen(

}

}

}
title = { Text("Create Account", color = Color.White, fontSize = 20.sp) },
navigationIcon = {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Backward Arrow",
modifier = Modifier.padding(start = 8.dp),
tint = Color.White
)
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color("#0C0C4F".toColorInt()),
titleContentColor = Color.White
)
)
}
) { paddingValues ->
Column(
Expand Down Expand Up @@ -386,4 +367,3 @@ fun GeneratekeySheet(


}

Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ fun FinalizeAccountCreationScreen(
) {
Scaffold(
topBar = {
TopAppBar(
backgroundColor = Color("#0C0C4F".toColorInt()),
contentColor = Color.White,
elevation = 4.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -76,21 +71,6 @@ fun FinalizeAccountCreationScreen(

}
}
title = { Text("Create Account", color = Color.White, fontSize = 20.sp) },
navigationIcon = {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Backward Arrow",
modifier = Modifier.padding(start = 8.dp),
tint = Color.White
)
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color("#0C0C4F".toColorInt()),
titleContentColor = Color.White
)
)
}
) { paddingValues ->
Column(
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,9 @@ fun ImportAccountScreen(
onFinishAccountImport: () -> Unit,
onBackButtonPressed: () -> Unit
) {
fun ImportAccountScreen(onFinishAccountImport: () -> Unit) {
var progress by remember { mutableStateOf(0.5f) }
Scaffold(
topBar = {
TopAppBar(
backgroundColor = Color("#0C0C4F".toColorInt()),
contentColor = Color.White,
elevation = 4.dp
) {
Row(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -99,21 +93,6 @@ fun ImportAccountScreen(onFinishAccountImport: () -> Unit) {

}
}
title = { Text("Import existing wallet", color = Color.White, fontSize = 20.sp) },
navigationIcon = {
Icon(
imageVector = Icons.Filled.ArrowBack,
contentDescription = "Backward Arrow",
modifier = Modifier.padding(start = 8.dp),
tint = Color.White
)
},
colors = TopAppBarDefaults.topAppBarColors(
containerColor = Color("#0C0C4F".toColorInt()),
titleContentColor = Color.White
)
)
}
) { paddingValues ->
Column(
modifier = Modifier
Expand Down
Loading

0 comments on commit ec30d92

Please sign in to comment.