Skip to content

Commit

Permalink
retrieving an account balance
Browse files Browse the repository at this point in the history
  • Loading branch information
sajalbnl committed Sep 7, 2024
1 parent d93dc5e commit 3fc6214
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 106 deletions.
12 changes: 12 additions & 0 deletions wallet_app/android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
id("com.google.dagger.hilt.android")
id("kotlin-kapt")
}

android {
Expand Down Expand Up @@ -93,6 +95,16 @@ dependencies {

implementation(libs.androidx.navigation.compose)

implementation (libs.retrofit)
implementation(libs.converter.gson)
implementation (libs.kotlinx.coroutines.core)
implementation (libs.kotlinx.coroutines.android)

implementation("com.google.dagger:hilt-android:2.50")
kapt("com.google.dagger:hilt-android-compiler:2.50")
kapt("androidx.hilt:hilt-compiler:1.0.0")
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
implementation("androidx.hilt:hilt-navigation-compose:1.0.0-alpha03")

implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
Expand Down
5 changes: 4 additions & 1 deletion wallet_app/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />


<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
Expand Down Expand Up @@ -33,7 +36,7 @@
android:exported="true"
android:theme="@style/Theme.Walletapp"/>

<activity android:name=".AccountBalanceActivity"
<activity android:name=".ui.activity.AccountBalanceActivity"
android:exported="true"
android:theme="@style/Theme.Walletapp"/>

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import androidx.core.view.WindowCompat
import com.example.walletapp.ui.theme.WalletappTheme
import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.HiltAndroidApp


class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -127,6 +130,25 @@ fun CreateAccount( modifier: Modifier) {
fontSize = 17.sp
)
}
Spacer(modifier = Modifier.height(10.dp))


Button(
onClick = { val i = Intent(context, WalletActivity::class.java)
context.startActivity(i) },
colors = ButtonDefaults.buttonColors(backgroundColor = Color("#EC796B".toColorInt())),
shape = RoundedCornerShape(10.dp),
modifier = Modifier
.fillMaxWidth()
.height(49.dp)
) {
Text(
text = "My Starknet Wallet",
fontFamily = FontFamily(Font(R.font.inter_regular)),
color = Color.White,
fontSize = 17.sp
)
}
}

Spacer(modifier = Modifier.height(15.dp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.core.graphics.toColorInt
import androidx.core.view.WindowCompat
import com.example.walletapp.ui.activity.AccountBalanceActivity
import com.example.walletapp.ui.theme.WalletappTheme

class WalletActivity : ComponentActivity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.example.walletapp.data.datasource

import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitInstance {
// Replace this with the actual StarkNet RPC URL
private const val BASE_URL = "https://starknet-mainnet.g.alchemy.com/starknet/version/rpc/v0_7/"

val api: StarknetApiService by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
.create(StarknetApiService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.example.walletapp.data.datasource

import com.example.walletapp.data.model.StarknetResponse
import com.example.walletapp.data.repository.StarknetCallRequest
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.POST

interface StarknetApiService {


@POST("rFAP8fkTAz9TmYw8_V5Fyzxi-WSoQdhk") // rpc end point
fun getBalance( @Body request: StarknetCallRequest): Call<StarknetResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.walletapp.data.model

data class StarknetResponse(
val jsonrpc: String,
val id: Int,
val result: List<String>
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.walletapp.data.repository

data class StarknetCallRequest(
val id: Int = 1,
val jsonrpc: String = "2.0",
val method: String = "starknet_call",
val params: List<Any>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.walletapp.data.repository

import android.util.Log
import com.example.walletapp.data.datasource.RetrofitInstance
import com.example.walletapp.data.model.StarknetResponse
import retrofit2.Call

class StarknetRepository() {
fun getAccountBalance(
contractAddress: String,
accountAddress: String
): Call<StarknetResponse> {
val calldata = listOf(accountAddress)
val params = listOf(
mapOf(
"contract_address" to "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
"calldata" to listOf("0x02dc260794e4c2eeae87b1403a88385a72c18a5844d220b88117b2965a8cf3a5"),
"entry_point_selector" to "0x2e4263afad30923c891518314c3c95dbe830a16874e8abc5777a9a20b54c76e"
),
"latest"
)
val request = StarknetCallRequest(params = params)

return RetrofitInstance.api.getBalance(request)
}
}
Loading

0 comments on commit 3fc6214

Please sign in to comment.