-
Notifications
You must be signed in to change notification settings - Fork 3
refactor: use core hw activities #1044
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
Draft
ovitrif
wants to merge
19
commits into
master
Choose a base branch
from
refactor/core-hww-activities-1029
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,111
−848
Draft
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
a9c1444
feat: persist hardware activities to core
ovitrif 601dc73
test: add hardware activity tags journey
ovitrif 37a1e32
docs: add changelog fragment for hw activities
ovitrif e64cb03
test: cover hardware activity core integration
ovitrif e9e0507
fix: scope hardware wallet activities
ovitrif c496123
fix: update core activity integration
ovitrif 98abad8
fix: delegate wallet ids to core
ovitrif 372bca2
test: handle hw transfer intro
ovitrif cee04e9
fix: stabilize hw activities
ovitrif 3b8e6a1
refactor: extract hw wallet identity
ovitrif 566ba2d
refactor: trim stacked diff
ovitrif 08047b3
fix: resolve stacked rebase fallout
ovitrif baaccc9
fix: clean stacked lint fallout
ovitrif ad49690
refactor: trim activity noise
ovitrif 02cf951
refactor: rename hw activity helper
ovitrif a8e93bf
refactor: clean hw helpers
ovitrif 276b5de
chore: drop workflow noise
ovitrif 5ae816a
fix: finalize core hardware activities
ovitrif 15b80fa
fix: stabilize hardware activity sync
ovitrif File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,15 @@ | ||
| package to.bitkit.models | ||
|
|
||
| import java.util.Locale | ||
|
|
||
| enum class ActivityWalletType { | ||
| BITKIT, TREZOR; | ||
|
|
||
| fun id(): String = name.lowercase(Locale.US) | ||
|
|
||
| fun idPrefixed(value: String): String = "${prefix()}$value" | ||
|
|
||
| fun owns(walletId: String): Boolean = walletId == id() || walletId.startsWith(prefix()) | ||
|
|
||
| private fun prefix(): String = "${id()}:" | ||
| } | ||
This file contains hidden or 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 hidden or 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,33 @@ | ||
| package to.bitkit.models | ||
|
|
||
| val KnownDevice.identityKey: String | ||
| get() = identityKey(xpubs, id) | ||
|
|
||
| fun identityKey(xpubs: Map<String, String>, fallback: String): String = | ||
| xpubs.values.sorted().joinToString().ifEmpty { fallback } | ||
|
|
||
| fun List<KnownDevice>.findWalletId( | ||
| deviceId: String, | ||
| xpubs: Map<String, String>, | ||
| deriveWalletId: (Collection<String>) -> String, | ||
| ): String { | ||
| val targetIdentityKey = identityKey(xpubs, deviceId) | ||
| firstOrNull { it.identityKey == targetIdentityKey }?.walletId?.takeIf { it.isNotBlank() }?.let { return it } | ||
| if (xpubs.values.any { it.isNotBlank() }) return deriveWalletId(xpubs.values) | ||
|
|
||
| return firstOrNull { it.id == deviceId }?.walletId?.takeIf { it.isNotBlank() }.orEmpty() | ||
| } | ||
|
|
||
| fun List<KnownDevice>.withWalletIds( | ||
| deriveWalletId: (Collection<String>) -> String, | ||
| ): List<KnownDevice> { | ||
| val existingByIdentity = filter { it.walletId.isNotBlank() } | ||
| .associate { it.identityKey to it.walletId } | ||
| val generatedByIdentity = mutableMapOf<String, String>() | ||
|
|
||
| return map { | ||
| val walletId = existingByIdentity[it.identityKey] | ||
| ?: generatedByIdentity.getOrPut(it.identityKey) { deriveWalletId(it.xpubs.values) } | ||
| if (it.walletId == walletId) it else it.copy(walletId = walletId) | ||
| } | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
available in bitkit-core