Skip to content

Save addressNames from API during transaction sync (Android)#214

Open
DRadmir wants to merge 10 commits intomainfrom
10-save-addressnames-from-api-during-transaction-sync
Open

Save addressNames from API during transaction sync (Android)#214
DRadmir wants to merge 10 commits intomainfrom
10-save-addressnames-from-api-during-transaction-sync

Conversation

@DRadmir
Copy link
Copy Markdown
Contributor

@DRadmir DRadmir commented Apr 23, 2026

Mirrors iOS address-name handling on Android: persists names from the API,
surfaces them in the transaction list and details, and keeps them in sync
when a wallet is renamed.

Schema:

  • Add addresses table (PK chain+address; columns chain/address/wallet_id/
    name/type/status). The optional wallet_id lets us mark the user's own
    accounts as InternalWallet/Verified and rename them along with their
    wallet
  • Bump DB version 72 -> 73 (Migration_72_73) — creates the table and seeds
    existing accounts as internal addresses

Domain:

  • Add SaveAddressNames, GetAddressName, RenameWalletAddresses cases
    backed by a thin AddressesRepository
  • Register DAO, migration, and Hilt bindings

Sync:

  • Add addressNames to TransactionsResponse (defaults to empty for
    back-compat)
  • SyncTransactionsImpl calls saveAddressNames after saving transactions,
    matching iOS call order
  • WalletsRepositoryImpl.putWallet seeds the user's own accounts into
    addresses
  • Renaming a wallet propagates the new name to its address-book entries

Closes #10

Mirror iOS TransactionsService which calls addressStore.addAddressNames
after syncing transactions. Android was dropping response.addressNames
on the floor.

Schema:
- Add addresses table (PK chain+address, columns chain/address/name/
  type/status) matching iOS AddressRecord; no wallet_id — entries are
  external (validators, contacts)
- Bump DB version 70 -> 71 with Migration_70_71

Domain:
- Add SaveAddressNames case in gemcore
- Add thin AddressesRepository wrapping AddressesDao
- Register DAO, migration, and Hilt bindings

Wiring:
- Add addressNames to TransactionsResponse (defaults to emptyList for
  back-compat)
- Inject SaveAddressNames into SyncTransactionsImpl and call after
  saveTransactions, mirroring iOS call order

Closes #10
@DRadmir DRadmir self-assigned this Apr 23, 2026
DRadmir added 2 commits April 24, 2026 10:44
- Rename counterpartyAddress to participantAddressName for consistency with participantAddress
- Inline Account.toAddressRecord into Wallet.toAddressRecords (single-use helper)
- Remove outdated SyncTransactionsImplTest
@DRadmir DRadmir force-pushed the 10-save-addressnames-from-api-during-transaction-sync branch from 6f45a9f to 749c374 Compare April 24, 2026 09:24
@DRadmir DRadmir marked this pull request as ready for review April 24, 2026 09:27
@DRadmir DRadmir marked this pull request as draft April 28, 2026 09:15
@DRadmir DRadmir force-pushed the 10-save-addressnames-from-api-during-transaction-sync branch from e9673ae to b3dca91 Compare April 29, 2026 17:22
…dressnames-from-api-during-transaction-sync

# Conflicts:
#	android/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositories/di/WalletsModule.kt
#	android/data/repositories/src/main/kotlin/com/gemwallet/android/data/repositories/wallets/WalletsRepositoryImpl.kt
#	android/data/services/store/schemas/com.gemwallet.android.data.service.store.database.GemDatabase/71.json
#	android/data/services/store/src/main/kotlin/com/gemwallet/android/data/service/store/database/GemDatabase.kt
#	android/data/services/store/src/main/kotlin/com/gemwallet/android/data/service/store/database/di/DatabaseModule.kt
#	android/data/services/store/src/main/kotlin/com/gemwallet/android/data/service/store/database/di/Migration_70_71.kt
#	android/data/services/store/src/main/kotlin/com/gemwallet/android/data/service/store/database/entities/DbTransactionExtended.kt
@DRadmir DRadmir force-pushed the 10-save-addressnames-from-api-during-transaction-sync branch from b3dca91 to e3bcb70 Compare April 29, 2026 17:38
@DRadmir DRadmir marked this pull request as ready for review April 29, 2026 18:04
@DRadmir DRadmir requested a review from gemcoder21 April 29, 2026 18:04
db.execSQL(
"""
CREATE TABLE IF NOT EXISTS `addresses` (
`chain` TEXT NOT NULL,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

add fk link to assets

`status` TEXT NOT NULL,
PRIMARY KEY(`chain`, `address`),
FOREIGN KEY(`wallet_id`) REFERENCES `wallets`(`id`)
ON UPDATE CASCADE ON DELETE CASCADE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

one liner, remove trimIndent

LEFT JOIN tx_swap_metadata as swap ON tx.id = swap.tx_id
LEFT JOIN asset as from_asset ON swap.from_asset_id = from_asset.id
LEFT JOIN asset as to_asset ON swap.to_asset_id = to_asset.id
LEFT JOIN addresses as from_addr ON from_addr.chain = asset.chain AND from_addr.address = tx.owner
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
LEFT JOIN addresses as from_addr ON from_addr.chain = asset.chain AND from_addr.address = tx.owner
LEFT JOIN addresses as from_addr ON from_addr.chain = asset.chain AND from_addr.address = transaction.owner

DRadmir added 4 commits May 5, 2026 12:14
…dressnames-from-api-during-transaction-sync

# Conflicts:
#	android/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinators/transaction/GetTransactionsImpl.kt
Mirrors the iOS AddressRecord FK and aligns with how master's
Migration_71_72 wires accounts.chain to asset(id). Adds an index on
chain so the FK doesn't trigger full-table scans.
…dressnames-from-api-during-transaction-sync

# Conflicts:
#	android/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinators/transaction/SyncTransactionsImpl.kt
#	android/data/services/store/src/main/kotlin/com/gemwallet/android/data/service/store/database/TransactionsDao.kt
#	android/gemcore/src/main/kotlin/com/gemwallet/android/model/Transaction.kt
- Drop seeding from Migration_72_73; addresses populate via SaveAddressNames sync and putWallet
- Rename DbAddressNameProjection to DbAddressProjection to match DbAssetProjection naming
- Drop redundant open/override val on Destination sealed subclasses
`status` TEXT NOT NULL,
PRIMARY KEY(`chain`, `address`),
FOREIGN KEY(`chain`) REFERENCES `asset`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(`wallet_id`) REFERENCES `wallets`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
FOREIGN KEY(`wallet_id`) REFERENCES `wallets`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
FOREIGN KEY(`walletId`) REFERENCES `wallets`(`id`) ON UPDATE CASCADE ON DELETE CASCADE

data class DbAddress(
val chain: Chain,
val address: String,
@ColumnInfo(name = "wallet_id") val walletId: String?,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
@ColumnInfo(name = "wallet_id") val walletId: String?,
val walletId: String?,

val address: String,
@ColumnInfo(name = "wallet_id") val walletId: String?,
val name: String,
val type: AddressType?,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
val type: AddressType?,
val type: AddressType,

)

data class DbAddressProjection(
val chain: Chain?,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

should not be optional?

package com.gemwallet.android.cases.addresses

interface RenameWalletAddresses {
suspend fun renameWalletAddresses(walletId: String, name: String)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
suspend fun renameWalletAddresses(walletId: String, name: String)
suspend fun rename(walletId: WalletId, name: String)

val address: String
val addressName: String?
get() = null
val addressType: AddressType?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

address: (name, type) ? maybe new struct?

`address` TEXT NOT NULL,
`wallet_id` TEXT,
`name` TEXT NOT NULL,
`type` TEXT,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
`type` TEXT,
`type` TEXT NOT NULL,

DRadmir added 2 commits May 8, 2026 11:01
…dressnames-from-api-during-transaction-sync

# Conflicts:
#	android/data/coordinators/src/main/kotlin/com/gemwallet/android/data/coordinators/transaction/SyncTransactionsImpl.kt
- Bump core: AddressName.address_type is now AddressType (non-optional)
- Regenerate AddressName bindings on Android and iOS
- Android: DbAddress.type, DbAddressProjection.type, addresses.type column become non-null; bump 73.json schema
- iOS: AddressRecord.type non-null with .notNull schema; add Backfill type migration so legacy NULL rows decode
- Drop unused TransactionDataAggregate.addressType (no consumer reads it)
- Rename RenameWalletAddresses.renameWalletAddresses(walletId: String, ...) to rename(walletId: WalletId, ...) per review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Save addressNames from API during transaction sync

2 participants