Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy address and back button fixes #133

Merged
merged 5 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,8 +106,8 @@ fun WalletApp(tokenViewModel: TokenViewModel) {
composable<AddToken> {
AddTokenScreen(
tokenViewModel=tokenViewModel,
navController: navController,
onConfirm = { navController.navigateUp() }
onConfirm = { navController.navigateUp() },
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,7 +2,7 @@ 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
Expand Down Expand Up @@ -45,12 +45,13 @@ 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.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 @@ -175,18 +178,33 @@ fun Wallet(modifier: Modifier, onNewTokenPress: () -> Unit, onReceivePress: () -
text = formatter.format(totalBalance),
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 24.sp,
fontSize = 26.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)
)
Row(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
can you center this with the text please

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also can you make the receive screen look and behave the same way?

image

modifier = Modifier.align(Alignment.CenterHorizontally)) {
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.walletapp.ui.transfer

import android.content.ClipData
import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand All @@ -21,17 +22,21 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ClipEntry
import androidx.compose.ui.platform.ClipboardManager
import androidx.compose.ui.platform.LocalClipboardManager
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.Font
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import com.example.walletapp.BuildConfig
import com.example.walletapp.R

@Composable
fun ReceiveScreen(modifier: Modifier) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a back button here as well.

val clipboard: ClipboardManager = LocalClipboardManager.current
val context= LocalContext.current
val address= BuildConfig.ACCOUNT_ADDRESS

Surface(modifier = Modifier.fillMaxSize()) {
Column(
Expand Down Expand Up @@ -59,7 +64,7 @@ fun ReceiveScreen(modifier: Modifier) {

// Wallet Address
Text(
text = "0xfoo...123", // Replace with actual wallet address
text = address.take(8) + "....",
fontFamily = FontFamily(Font(R.font.publicsans_bold)),
color = Color.White,
fontSize = 40.sp
Expand All @@ -74,8 +79,9 @@ fun ReceiveScreen(modifier: Modifier) {
color = Color.White,
fontSize = 15.sp,
modifier = Modifier.clickable {
val clip = ClipEntry(ClipData.newPlainText("Wallet Address", "0xfoo...123")) // TODO: Replace with actual wallet address
val clip = ClipEntry(ClipData.newPlainText("Wallet Address", address))
clipboard.setClip(clip)
Toast.makeText(context, "Address Copied", Toast.LENGTH_LONG).show()
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import com.example.walletapp.R
import com.example.walletapp.ui.account.WalletViewModel
import android.widget.Toast
import androidx.compose.foundation.layout.Box
import androidx.compose.material.DropdownMenuItem
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.remember
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a back button to this screen as well

Expand Down Expand Up @@ -306,27 +306,33 @@ fun TokenDropdown(
DropdownMenuItem(onClick = {
onTokenSelected("ethereum")
expanded = false
}) {
Image(
painter = painterResource(id = R.drawable.ic_ethereum),
contentDescription = null,
modifier = Modifier.size(24.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text("ETH", color = Color.White)
}
},
leadingIcon = {
Image(
painter = painterResource(id = R.drawable.ic_ethereum),
contentDescription = null,
modifier = Modifier.size(24.dp)
)

},
text={
Text("ETH", color = Color.White)
})
DropdownMenuItem(onClick = {
onTokenSelected("starknet")
expanded = false
}) {
Image(
painter = painterResource(id = R.drawable.starknet_icon),
contentDescription = null,
modifier = Modifier.size(24.dp)
)
Spacer(modifier = Modifier.width(8.dp))
Text("STRK", color = Color.White)
}
},
leadingIcon = {
Image(
painter = painterResource(id = R.drawable.starknet_icon),
contentDescription = null,
modifier = Modifier.size(24.dp)
)

},
text={
Text("STRK", color = Color.White)
})
}
}
}
Expand Down
Binary file modified wallet_app/app/src/main/res/drawable/copy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading