mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-10-26 06:08:40 +01:00
* feat: Add network selector and compatible networks screen to send page for EVMs * feat: add redesigned payanything flow and handle cases for evms, solana and tron * feat: adding the swap part to the entire flow * refactor: update navigation and error handling in send and swap flows * adjust structuring and use the chain badge icons, also fix crypto and currency values not consistent on single network picker * fix: modify guard for non-evm chains and minor cleanup * use multipicker layout for receive section, streamline send to available balances and adjust colors as needed * handle btc case for picker, update style and images across * fix all pending issues with scanning qr and network handling for both evm and non evm, plus token and amount resolving * fix all pending issues with scanning qr and network handling for both evm and non evm, plus token and amount resolving * fix: expand fetch for tokens across networks and fix other issues regarding scanning from homepage * auto-reformat * fix conflict * handle evm qr scan from homepage and add guards for swap and switch flows * chore: Cleanup * chore: set estimated fee to 0 when switching wallet * fix merge conflicts * fix to review comments and reformatting for lints * fix: root cause for token bug reported * chore: cleanup * feat: add improved anypay swap screen which focuses on the receive amount fix: fiat input toggle erro (also present on prod) reformat: anypay related widgets * feat: add alert for unsupported networks in payment requests * fix: prevent rate and provider from showing until amount is calculated and loaded fix: remove send icon in rate widget and align to center fix: adjust network badge in swap confirm widget * feat: embed tokens for solana and tron in QR generated for swap from external * test: add unit tests for Tron, Solana, and ERC681 URI handling and detection * fix: review comments * fix: handle more edgecases * feat: enhance ERC681URI to support raw token amounts and decimals * refactor: streamline EVM chain ID retrieval in send page and recipient network row * fix: minor review comments --------- Co-authored-by: Robert Malikowski <malikowskirobert@gmail.com>
114 lines
4.6 KiB
Dart
114 lines
4.6 KiB
Dart
import "package:cake_wallet/utils/payment_request.dart";
|
|
import "package:cw_core/erc20_token.dart";
|
|
import "package:flutter_test/flutter_test.dart";
|
|
|
|
void main() {
|
|
group("PaymentRequest", () {
|
|
group("Ethereum URIs", () {
|
|
test("extract address and raw token amount from EIP681 Uri with contract", () {
|
|
final uri = Uri.parse(
|
|
"ethereum:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41&uint256=2000000000000000000");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
expect(paymentRequest.amount, "");
|
|
expect(paymentRequest.rawTokenAmount, "2000000000000000000");
|
|
});
|
|
|
|
test("extract address and amount from EIP681 Uri", () {
|
|
final uri = Uri.parse(
|
|
"ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41@1?value=2000000000000000000");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
expect(paymentRequest.amount, "2");
|
|
});
|
|
|
|
test("extract address and amount from Cake Style Uri", () {
|
|
final uri = Uri.parse("ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41@1?amount=2.00");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
expect(paymentRequest.amount, "2.00");
|
|
});
|
|
|
|
test("extract address from EIP681 Uri with contract", () {
|
|
final uri = Uri.parse(
|
|
"ethereum:0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
expect(paymentRequest.amount, "");
|
|
});
|
|
|
|
test("extract address and raw token amount from EIP681 Uri with contract and no chainId", () {
|
|
final uri = Uri.parse(
|
|
"ethereum:0x1234567890abcdef1234567890abcdef12345678/transfer?address=0xabcdef1234567890abcdef1234567890abcdef12&uint256=1000000000000000000");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xabcdef1234567890abcdef1234567890abcdef12");
|
|
expect(paymentRequest.amount, "");
|
|
expect(paymentRequest.rawTokenAmount, "1000000000000000000");
|
|
});
|
|
|
|
test("extract address from minimal EIP681 Uri", () {
|
|
final uri = Uri.parse("ethereum:0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.address, "0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41");
|
|
expect(paymentRequest.amount, "");
|
|
});
|
|
});
|
|
|
|
group("resolveTokenAmount", () {
|
|
final usdt = Erc20Token(
|
|
name: "Tether",
|
|
symbol: "USDT",
|
|
contractAddress: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
decimal: 6,
|
|
);
|
|
final dai = Erc20Token(
|
|
name: "Dai",
|
|
symbol: "DAI",
|
|
contractAddress: "0x6B175474E89094C44Da98b954EedeAC495271d0F",
|
|
decimal: 18,
|
|
);
|
|
|
|
test("converts the raw uint256 using the token decimals", () {
|
|
final uri = Uri.parse(
|
|
"ethereum:0xdAC17F958D2ee523a2206206994597C13D831ec7@1/transfer?address=0xCfc1650da7C961FD82998e7e30ca5f699D0aBf41&uint256=1000000");
|
|
final paymentRequest = PaymentRequest.fromUri(uri);
|
|
|
|
expect(paymentRequest.resolveTokenAmount(usdt), "1");
|
|
});
|
|
|
|
test("converts an 18 decimal raw amount unchanged", () {
|
|
final paymentRequest =
|
|
PaymentRequest("addr", "", "", "ethereum", null, rawTokenAmount: "1500000000000000000");
|
|
|
|
expect(paymentRequest.resolveTokenAmount(dai), "1.5");
|
|
});
|
|
|
|
test("falls back to the legacy 18 decimal reading for implausibly large amounts", () {
|
|
final paymentRequest = PaymentRequest("addr", "", "", "ethereum", null,
|
|
rawTokenAmount: "50000000000000000000");
|
|
|
|
expect(paymentRequest.resolveTokenAmount(usdt), "50");
|
|
});
|
|
|
|
test("prefers the decimal amount over the raw token amount", () {
|
|
final paymentRequest =
|
|
PaymentRequest("addr", "2.5", "", "ethereum", null, rawTokenAmount: "1000000");
|
|
|
|
expect(paymentRequest.resolveTokenAmount(usdt), "2.5");
|
|
});
|
|
|
|
test("returns null when there is no amount at all", () {
|
|
final paymentRequest = PaymentRequest("addr", "", "", "ethereum", null);
|
|
|
|
expect(paymentRequest.resolveTokenAmount(usdt), null);
|
|
});
|
|
});
|
|
});
|
|
}
|