2020-07-06 20:09:03 +00:00
|
|
|
import 'package:flutter/foundation.dart';
|
|
|
|
import 'package:cake_wallet/generated/i18n.dart';
|
|
|
|
import 'package:cake_wallet/core/validator.dart';
|
2021-12-24 12:37:24 +00:00
|
|
|
import 'package:cw_core/crypto_currency.dart';
|
2020-07-06 20:09:03 +00:00
|
|
|
|
|
|
|
class AddressValidator extends TextValidator {
|
|
|
|
AddressValidator({@required CryptoCurrency type})
|
|
|
|
: super(
|
|
|
|
errorMessage: S.current.error_text_address,
|
|
|
|
pattern: getPattern(type),
|
|
|
|
length: getLength(type));
|
|
|
|
|
|
|
|
static String getPattern(CryptoCurrency type) {
|
|
|
|
switch (type) {
|
|
|
|
case CryptoCurrency.xmr:
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
return '^4[0-9a-zA-Z]{94}\$|^8[0-9a-zA-Z]{94}\$|^[0-9a-zA-Z]{106}\$';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.ada:
|
2021-02-23 18:38:36 +00:00
|
|
|
return '^[0-9a-zA-Z]{59}\$|^[0-9a-zA-Z]{92}\$|^[0-9a-zA-Z]{104}\$'
|
|
|
|
'|^[0-9a-zA-Z]{105}\$|^addr1[0-9a-zA-Z]{98}\$';
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.ape:
|
|
|
|
return '0x[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.avaxc:
|
|
|
|
return '0x[0-9a-zA-Z]';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.bch:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.bnb:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.btc:
|
2021-03-26 12:45:46 +00:00
|
|
|
return '^1[0-9a-zA-Z]{32}\$|^1[0-9a-zA-Z]{33}\$|^3[0-9a-zA-Z]{32}\$'
|
|
|
|
'|^3[0-9a-zA-Z]{33}\$|^bc1[0-9a-zA-Z]{39}\$|^bc1[0-9a-zA-Z]{59}\$';
|
2020-09-24 18:58:07 +00:00
|
|
|
case CryptoCurrency.dai:
|
|
|
|
return '[0-9a-zA-Z]';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.dash:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.eos:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.eth:
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
return '0x[0-9a-zA-Z]';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.ltc:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.nano:
|
|
|
|
return '[0-9a-zA-Z_]';
|
|
|
|
case CryptoCurrency.trx:
|
|
|
|
return '[0-9a-zA-Z]';
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.usdc:
|
|
|
|
return '0x[0-9a-zA-Z]';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.usdt:
|
|
|
|
return '[0-9a-zA-Z]';
|
2020-09-25 13:30:39 +00:00
|
|
|
case CryptoCurrency.usdterc20:
|
|
|
|
return '[0-9a-zA-Z]';
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.xlm:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
case CryptoCurrency.xrp:
|
2021-01-13 17:26:02 +00:00
|
|
|
return '^[0-9a-zA-Z]{34}\$|^X[0-9a-zA-Z]{46}\$';
|
2022-03-30 15:57:04 +00:00
|
|
|
case CryptoCurrency.xhv:
|
2022-06-01 11:12:09 +00:00
|
|
|
return '^hvx|hvi|hvs[0-9a-zA-Z]';
|
2022-03-30 15:57:04 +00:00
|
|
|
case CryptoCurrency.xag:
|
|
|
|
case CryptoCurrency.xau:
|
|
|
|
case CryptoCurrency.xaud:
|
|
|
|
case CryptoCurrency.xbtc:
|
|
|
|
case CryptoCurrency.xcad:
|
|
|
|
case CryptoCurrency.xchf:
|
|
|
|
case CryptoCurrency.xcny:
|
|
|
|
case CryptoCurrency.xeur:
|
|
|
|
case CryptoCurrency.xgbp:
|
|
|
|
case CryptoCurrency.xjpy:
|
|
|
|
case CryptoCurrency.xnok:
|
|
|
|
case CryptoCurrency.xnzd:
|
|
|
|
case CryptoCurrency.xusd:
|
|
|
|
return '[0-9a-zA-Z]';
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.hbar:
|
|
|
|
return '[0-9a-zA-Z.]';
|
|
|
|
case CryptoCurrency.zaddr:
|
2022-09-14 19:46:14 +00:00
|
|
|
return '^zs[0-9a-zA-Z]{75}';
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.zec:
|
|
|
|
return '^t1[0-9a-zA-Z]{33}\$|^t3[0-9a-zA-Z]{33}\$';
|
2020-07-06 20:09:03 +00:00
|
|
|
default:
|
|
|
|
return '[0-9a-zA-Z]';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static List<int> getLength(CryptoCurrency type) {
|
|
|
|
switch (type) {
|
|
|
|
case CryptoCurrency.xmr:
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
return null;
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.ada:
|
2021-02-23 18:38:36 +00:00
|
|
|
return null;
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.ape:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.avaxc:
|
|
|
|
return [42];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.bch:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.bnb:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.btc:
|
2021-03-26 12:45:46 +00:00
|
|
|
return null;
|
2020-09-24 18:58:07 +00:00
|
|
|
case CryptoCurrency.dai:
|
|
|
|
return [42];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.dash:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.eos:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.eth:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.ltc:
|
2021-05-07 07:36:38 +00:00
|
|
|
return [34, 43];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.nano:
|
|
|
|
return [64, 65];
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.sc:
|
|
|
|
return [76];
|
|
|
|
case CryptoCurrency.sol:
|
|
|
|
return [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.trx:
|
|
|
|
return [34];
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.usdc:
|
|
|
|
return [42];
|
|
|
|
case CryptoCurrency.usdcsol:
|
|
|
|
return [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.usdt:
|
2022-02-08 08:57:02 +00:00
|
|
|
return [34];
|
2020-09-25 13:30:39 +00:00
|
|
|
case CryptoCurrency.usdterc20:
|
|
|
|
return [42];
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.usdttrc20:
|
|
|
|
return [34];
|
2020-07-06 20:09:03 +00:00
|
|
|
case CryptoCurrency.xlm:
|
|
|
|
return [56];
|
|
|
|
case CryptoCurrency.xrp:
|
2021-01-13 17:26:02 +00:00
|
|
|
return null;
|
2022-03-30 15:57:04 +00:00
|
|
|
case CryptoCurrency.xhv:
|
|
|
|
case CryptoCurrency.xag:
|
|
|
|
case CryptoCurrency.xau:
|
|
|
|
case CryptoCurrency.xaud:
|
|
|
|
case CryptoCurrency.xbtc:
|
|
|
|
case CryptoCurrency.xcad:
|
|
|
|
case CryptoCurrency.xchf:
|
|
|
|
case CryptoCurrency.xcny:
|
|
|
|
case CryptoCurrency.xeur:
|
|
|
|
case CryptoCurrency.xgbp:
|
|
|
|
case CryptoCurrency.xjpy:
|
|
|
|
case CryptoCurrency.xnok:
|
|
|
|
case CryptoCurrency.xnzd:
|
|
|
|
case CryptoCurrency.xusd:
|
|
|
|
return [98, 99, 106];
|
Cw 126 check validation for new currencies (#501)
* update address validation
xmr, ape, avaxc, eth, usdc, hbar, sc, sol, usdcsoul, usdttrc20, btt, bttsc, doge,firo, xvg, zen, tzec, zzec
* fix formating
2022-09-07 12:53:33 +00:00
|
|
|
case CryptoCurrency.btt:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.bttbsc:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.doge:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.firo:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.hbar:
|
|
|
|
return [4, 5, 6, 7, 8, 9, 10, 11];
|
|
|
|
case CryptoCurrency.xvg:
|
|
|
|
return [34];
|
|
|
|
case CryptoCurrency.zen:
|
|
|
|
return [35];
|
|
|
|
case CryptoCurrency.zaddr:
|
|
|
|
return null;
|
|
|
|
case CryptoCurrency.zec:
|
|
|
|
return null;
|
2020-07-06 20:09:03 +00:00
|
|
|
default:
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|