-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Token added functionality,balance and price of all tokens (#118)
* Token added functionality,balance and price of all tokens * files added * Image Of tokens and Changes as requested * tweaks --------- Co-authored-by: Sajal Bansal <[email protected]> Co-authored-by: Thomas Butler <[email protected]> Co-authored-by: Thomas <[email protected]>
- Loading branch information
1 parent
a01781c
commit d393991
Showing
21 changed files
with
541 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
wallet_app/app/src/main/java/com/example/walletapp/WalletAppApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.walletapp | ||
|
||
import android.app.Application | ||
import com.example.walletapp.db.TokenDatabase | ||
|
||
|
||
class WalletAppApplication : Application() { | ||
|
||
// Lazy initialization of the database | ||
val database: TokenDatabase by lazy { TokenDatabase.getDatabase(this) } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
wallet_app/app/src/main/java/com/example/walletapp/db/TokenDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.walletapp.db | ||
|
||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.OnConflictStrategy | ||
import com.example.walletapp.model.Token | ||
import kotlinx.coroutines.flow.Flow | ||
import androidx.room.Query | ||
|
||
@Dao | ||
interface TokenDao { | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insert(token: Token) | ||
|
||
@Query("SELECT * FROM token_table") | ||
fun getAllTokens(): Flow<List<Token>> | ||
} |
59 changes: 59 additions & 0 deletions
59
wallet_app/app/src/main/java/com/example/walletapp/db/TokenDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.example.walletapp.db | ||
|
||
import android.content.Context | ||
import androidx.room.Database | ||
import androidx.room.Room | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import androidx.sqlite.db.SupportSQLiteDatabase | ||
import com.example.walletapp.model.Token | ||
import com.example.walletapp.utils.Converters | ||
import com.swmansion.starknet.data.types.Felt | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
@Database(entities = [Token::class], version = 2, exportSchema = false) | ||
@TypeConverters(Converters::class) | ||
abstract class TokenDatabase : RoomDatabase() { | ||
|
||
abstract fun tokenDao(): TokenDao | ||
|
||
companion object { | ||
@Volatile | ||
private var INSTANCE: TokenDatabase? = null | ||
|
||
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 | ||
.build() | ||
INSTANCE = instance | ||
instance | ||
} | ||
} | ||
} | ||
|
||
private class DatabaseCallback : RoomDatabase.Callback() { | ||
override fun onCreate(db: SupportSQLiteDatabase) { | ||
super.onCreate(db) | ||
INSTANCE?.let { database -> | ||
CoroutineScope(Dispatchers.IO).launch { | ||
populateDatabase(database.tokenDao()) | ||
} | ||
} | ||
} | ||
|
||
suspend fun populateDatabase(tokenDao: TokenDao) { | ||
// Add default tokens | ||
val token1 = Token(contactAddress = Felt.fromHex("0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"), name = "ethereum", symbol = "eth", decimals = 18,tokenId="ethereum") | ||
val token2 = Token(contactAddress = Felt.fromHex("0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"), name = "starknet", symbol = "strk", decimals = 18,tokenId="starknet") | ||
tokenDao.insert(token1) | ||
tokenDao.insert(token2) | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
wallet_app/app/src/main/java/com/example/walletapp/model/CoinData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.example.walletapp.model | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class CoinData( | ||
@SerializedName("id") val id: String, | ||
@SerializedName("symbol") val symbol: String, | ||
@SerializedName("name") val name: String, | ||
@SerializedName("web_slug") val webSlug: String, | ||
@SerializedName("asset_platform_id") val assetPlatformId: String, | ||
@SerializedName("image") val image: ImageData, | ||
@SerializedName("contract_address") val contractAddress: String | ||
) | ||
|
||
data class ImageData( | ||
@SerializedName("thumb") val thumb: String, | ||
@SerializedName("small") val small: String, | ||
@SerializedName("large") val large: String | ||
) |
14 changes: 11 additions & 3 deletions
14
wallet_app/app/src/main/java/com/example/walletapp/model/Token.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
package com.example.walletapp.model | ||
|
||
class Token ( | ||
val address: String, | ||
import androidx.room.Entity | ||
import androidx.room.PrimaryKey | ||
import com.swmansion.starknet.data.types.Felt | ||
|
||
@Entity(tableName = "token_table") | ||
data class Token( | ||
@PrimaryKey(autoGenerate = true) val id: Int = 0, | ||
val contactAddress: Felt, | ||
val name: String, | ||
val symbol: String, | ||
val name: String | ||
val decimals: Int, | ||
val tokenId:String | ||
) |
3 changes: 3 additions & 0 deletions
3
wallet_app/app/src/main/java/com/example/walletapp/model/TokenIdsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
package com.example.walletapp.model | ||
|
||
class TokenIdsResponse : ArrayList<TokenIdsResponseItem>() |
7 changes: 7 additions & 0 deletions
7
wallet_app/app/src/main/java/com/example/walletapp/model/TokenIdsResponseItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.walletapp.model | ||
|
||
data class TokenIdsResponseItem( | ||
val id: String, | ||
val name: String, | ||
val symbol: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.