-
Notifications
You must be signed in to change notification settings - Fork 18
Allow sending to .near account #867
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
15 changes: 15 additions & 0 deletions
15
...src/main/kotlin/com/gemwallet/android/features/recipient/viewmodel/RecipientValidation.kt
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 com.gemwallet.android.features.recipient.viewmodel | ||
|
|
||
| import com.gemwallet.android.blockchain.operators.ValidateAddressOperator | ||
| import com.gemwallet.android.ext.matchesRecipient | ||
| import com.gemwallet.android.model.DestinationAddress | ||
| import com.wallet.core.primitives.Chain | ||
| import com.wallet.core.primitives.NameRecord | ||
|
|
||
| internal fun DestinationAddress.isValidRecipient( | ||
| inputAddress: String, | ||
| chain: Chain, | ||
| nameRecord: NameRecord?, | ||
| validateAddress: ValidateAddressOperator, | ||
| ): Boolean = validateAddress(address, chain).getOrNull() == true && | ||
| (nameRecord == null || nameRecord.matchesRecipient(inputAddress, address, chain)) |
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
55 changes: 55 additions & 0 deletions
55
...test/kotlin/com/gemwallet/android/features/recipient/viewmodel/RecipientValidationTest.kt
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,55 @@ | ||
| package com.gemwallet.android.features.recipient.viewmodel | ||
|
|
||
| import com.gemwallet.android.blockchain.operators.ValidateAddressOperator | ||
| import com.gemwallet.android.model.DestinationAddress | ||
| import com.gemwallet.android.testkit.mockNameRecord | ||
| import com.wallet.core.primitives.Chain | ||
| import com.wallet.core.primitives.NameProvider | ||
| import org.junit.Assert.assertFalse | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| class RecipientValidationTest { | ||
|
|
||
| @Test | ||
| fun validRecipientRequiresValidAddressAndMatchingRecord() { | ||
| val accountId = "wrap.near" | ||
| val otherAccountId = "other.near" | ||
| val chain = Chain.Near | ||
| val destination = DestinationAddress(address = accountId, name = accountId) | ||
| val record = mockNameRecord(name = accountId, chain = chain, address = accountId, provider = NameProvider.Near) | ||
| val validAddress = addressValidator(true) | ||
| val invalidAddress = addressValidator(false) | ||
|
|
||
| assertTrue(destination.isValidRecipient(accountId, chain, record, validAddress)) | ||
| assertFalse(destination.isValidRecipient(otherAccountId, chain, record, validAddress)) | ||
| assertFalse(destination.isValidRecipient(accountId, Chain.Ethereum, record, validAddress)) | ||
| assertFalse(destination.isValidRecipient(accountId, chain, record, invalidAddress)) | ||
| assertFalse(destination.isValidRecipient(accountId, chain, null, invalidAddress)) | ||
| assertTrue(destination.isValidRecipient(accountId, chain, null, validAddress)) | ||
|
|
||
| val ethereumName = "example.eth" | ||
| val ethereumAddress = "0x5615E8AB93b9d695b6d4d6545f7792aA59e1069a" | ||
| val ethereumDestination = DestinationAddress(address = ethereumAddress, name = ethereumName) | ||
| val ethereumRecord = mockNameRecord( | ||
| name = ethereumName, | ||
| address = ethereumAddress, | ||
| ) | ||
| val unresolvedEthereumRecord = ethereumRecord.copy(address = ethereumName) | ||
| val unresolvedEthereumDestination = DestinationAddress(address = ethereumName, name = ethereumName) | ||
|
|
||
| assertTrue(ethereumDestination.isValidRecipient(ethereumName, Chain.Ethereum, ethereumRecord, validAddress)) | ||
| assertFalse( | ||
| unresolvedEthereumDestination.isValidRecipient( | ||
| ethereumName, | ||
| Chain.Ethereum, | ||
| unresolvedEthereumRecord, | ||
| invalidAddress, | ||
| ), | ||
| ) | ||
| } | ||
|
|
||
| private fun addressValidator(result: Boolean) = object : ValidateAddressOperator { | ||
| override fun invoke(address: String, chain: Chain): Result<Boolean> = Result.success(result) | ||
| } | ||
| } |
7 changes: 7 additions & 0 deletions
7
android/gemcore/src/main/kotlin/com/gemwallet/android/ext/NameRecord.kt
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,7 @@ | ||
| package com.gemwallet.android.ext | ||
|
|
||
| import com.wallet.core.primitives.Chain | ||
| import com.wallet.core.primitives.NameRecord | ||
|
|
||
| fun NameRecord.matchesRecipient(name: String, address: String, chain: Chain): Boolean = | ||
| this.name == name && this.address == address && this.chain == chain | ||
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
17 changes: 17 additions & 0 deletions
17
android/gemcore/src/testFixtures/kotlin/com/gemwallet/android/testkit/NameRecordMock.kt
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,17 @@ | ||
| package com.gemwallet.android.testkit | ||
|
|
||
| import com.wallet.core.primitives.Chain | ||
| import com.wallet.core.primitives.NameProvider | ||
| import com.wallet.core.primitives.NameRecord | ||
|
|
||
| fun mockNameRecord( | ||
| name: String = "example.eth", | ||
| chain: Chain = Chain.Ethereum, | ||
| address: String = "0x5615E8AB93b9d695b6d4d6545f7792aA59e1069a", | ||
| provider: NameProvider = NameProvider.Ens, | ||
| ) = NameRecord( | ||
| name = name, | ||
| chain = chain, | ||
| address = address, | ||
| provider = provider, | ||
| ) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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,42 @@ | ||
| use std::error::Error; | ||
|
|
||
| use async_trait::async_trait; | ||
| use gem_client::ReqwestClient; | ||
| use gem_jsonrpc::client::JsonRpcClient; | ||
| use gem_near::rpc::NearClient; | ||
| use primitives::{Chain, NameProvider}; | ||
|
|
||
| use crate::client::NameClient; | ||
| use crate::model::NameQuery; | ||
|
|
||
| pub struct NearNameClient { | ||
| client: NearClient<ReqwestClient>, | ||
| } | ||
|
|
||
| impl NearNameClient { | ||
| pub fn new(url: String) -> Self { | ||
| Self { | ||
| client: NearClient::new(JsonRpcClient::new_reqwest(url)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
| impl NameClient for NearNameClient { | ||
| async fn resolve(&self, query: &NameQuery, _chain: Chain) -> Result<String, Box<dyn Error + Send + Sync>> { | ||
| self.client.get_account(&query.domain).await?; | ||
| Ok(query.domain.clone()) | ||
| } | ||
|
|
||
| fn provider(&self) -> NameProvider { | ||
| NameProvider::Near | ||
| } | ||
|
|
||
| fn domains(&self) -> Vec<&'static str> { | ||
| vec!["near"] | ||
| } | ||
|
|
||
| fn chains(&self) -> Vec<Chain> { | ||
| vec![Chain::Near] | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -33,4 +33,5 @@ pub enum NameProvider { | |
| Basenames, | ||
| Hyperliquid, | ||
| AllDomains, | ||
| Near, | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.