mirror of
https://github.com/cypherstack/stack_wallet.git
synced 2025-01-31 06:35:53 +00:00
filter unrecognized from extra URI parameters IAW BIP21
Closes #567 https://github.com/cypherstack/stack_wallet/issues/567 TODO refer to BIP21 to see if any other params are required
This commit is contained in:
parent
c5a14815ec
commit
3a9e7d700b
1 changed files with 13 additions and 4 deletions
|
@ -14,6 +14,8 @@ import 'logger.dart';
|
|||
import '../wallets/crypto_currency/crypto_currency.dart';
|
||||
|
||||
class AddressUtils {
|
||||
static final Set<String> recognizedParams = {'amount', 'label', 'message'};
|
||||
|
||||
static String condenseAddress(String address) {
|
||||
return '${address.substring(0, 5)}...${address.substring(address.length - 5)}';
|
||||
}
|
||||
|
@ -170,8 +172,13 @@ class AddressUtils {
|
|||
// // }
|
||||
// }
|
||||
|
||||
/// parse an address uri
|
||||
/// returns an empty map if the input string does not begin with "firo:"
|
||||
/// Return only recognized parameters.
|
||||
static Map<String, String> filterParams(Map<String, String> params) {
|
||||
return Map.fromEntries(params.entries
|
||||
.where((entry) => recognizedParams.contains(entry.key.toLowerCase())));
|
||||
}
|
||||
|
||||
/// Parses a URI string.
|
||||
static Map<String, String> parseUri(String uri) {
|
||||
final Map<String, String> result = {};
|
||||
try {
|
||||
|
@ -202,9 +209,11 @@ class AddressUtils {
|
|||
sanitizedAddress = address.replaceFirst(prefix, "");
|
||||
}
|
||||
}
|
||||
// Filter unrecognized parameters.
|
||||
final filteredParams = filterParams(params);
|
||||
String uriString = "${coin.uriScheme}:$sanitizedAddress";
|
||||
if (params.isNotEmpty) {
|
||||
uriString += Uri(queryParameters: params).toString();
|
||||
if (filteredParams.isNotEmpty) {
|
||||
uriString += Uri(queryParameters: filteredParams).toString();
|
||||
}
|
||||
return uriString;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue