feat: 充值页面添加长按二维码10秒切换到真实钱包地址模式
- 长按二维码超过10秒可切换到显示真实KAVA钱包地址 - 切换后显示完整区块链地址和对应二维码 - 页面退出后自动恢复到充值ID模式 - 隐藏功能,不影响普通用户使用 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
54a225ebf2
commit
5b731498de
|
|
@ -28,6 +28,12 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
/// 钱包是否已就绪
|
||||
bool _isWalletReady = false;
|
||||
|
||||
/// 是否显示真实钱包地址(隐藏模式)
|
||||
bool _showRealAddress = false;
|
||||
|
||||
/// 真实钱包地址(KAVA)
|
||||
String? _realWalletAddress;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
|
@ -71,15 +77,20 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
_isWalletReady = false;
|
||||
}
|
||||
|
||||
// 如果钱包已就绪,查询余额
|
||||
// 如果钱包已就绪,查询余额和真实钱包地址
|
||||
if (_isWalletReady) {
|
||||
try {
|
||||
final walletService = ref.read(walletServiceProvider);
|
||||
final walletResponse = await walletService.getMyWallet();
|
||||
|
||||
// 获取真实钱包地址(用于隐藏模式)
|
||||
final walletAddresses = await accountService.getWalletAddresses();
|
||||
|
||||
// 显示 USDT 可用余额
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_balance = walletResponse.balances.usdt.available.toStringAsFixed(2);
|
||||
_realWalletAddress = walletAddresses?.kava;
|
||||
_isLoading = false;
|
||||
});
|
||||
}
|
||||
|
|
@ -111,19 +122,53 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
}
|
||||
}
|
||||
|
||||
/// 获取充值地址(用户ID)
|
||||
/// 获取充值地址(根据模式返回ID或真实地址)
|
||||
String get _depositAddress {
|
||||
if (_showRealAddress && _realWalletAddress != null) {
|
||||
return _realWalletAddress!;
|
||||
}
|
||||
return _accountSequence ?? '';
|
||||
}
|
||||
|
||||
/// 获取显示标题
|
||||
String get _addressTitle {
|
||||
return _showRealAddress ? '钱包地址 (KAVA)' : '充值ID';
|
||||
}
|
||||
|
||||
/// 复制地址到剪贴板
|
||||
void _copyAddress() {
|
||||
if (_depositAddress.isEmpty) return;
|
||||
|
||||
Clipboard.setData(ClipboardData(text: _depositAddress));
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(_showRealAddress ? '钱包地址已复制' : '充值ID已复制'),
|
||||
backgroundColor: const Color(0xFFD4AF37),
|
||||
duration: const Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/// 切换到真实地址模式
|
||||
void _switchToRealAddressMode() {
|
||||
if (_realWalletAddress == null) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('钱包地址暂不可用'),
|
||||
backgroundColor: Color(0xFF8B5A2B),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
setState(() {
|
||||
_showRealAddress = true;
|
||||
});
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('充值ID已复制'),
|
||||
content: Text('已切换到钱包地址模式'),
|
||||
backgroundColor: Color(0xFFD4AF37),
|
||||
duration: Duration(seconds: 2),
|
||||
),
|
||||
|
|
@ -340,8 +385,8 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// 二维码区域
|
||||
_buildQrCode(),
|
||||
// 二维码区域(长按10秒切换到真实地址模式)
|
||||
_buildQrCodeWithLongPress(),
|
||||
const SizedBox(height: 24),
|
||||
// 地址信息
|
||||
_buildAddressInfo(),
|
||||
|
|
@ -350,6 +395,36 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
);
|
||||
}
|
||||
|
||||
/// 长按计时器
|
||||
DateTime? _longPressStartTime;
|
||||
|
||||
/// 构建带长按检测的二维码
|
||||
Widget _buildQrCodeWithLongPress() {
|
||||
// 如果已经在显示真实地址,不需要长按检测
|
||||
if (_showRealAddress) {
|
||||
return _buildQrCode();
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onLongPressStart: (_) {
|
||||
_longPressStartTime = DateTime.now();
|
||||
},
|
||||
onLongPressEnd: (_) {
|
||||
if (_longPressStartTime != null) {
|
||||
final duration = DateTime.now().difference(_longPressStartTime!);
|
||||
if (duration.inSeconds >= 10) {
|
||||
_switchToRealAddressMode();
|
||||
}
|
||||
}
|
||||
_longPressStartTime = null;
|
||||
},
|
||||
onLongPressCancel: () {
|
||||
_longPressStartTime = null;
|
||||
},
|
||||
child: _buildQrCode(),
|
||||
);
|
||||
}
|
||||
|
||||
/// 构建二维码
|
||||
Widget _buildQrCode() {
|
||||
// 加载中
|
||||
|
|
@ -477,12 +552,16 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
|
||||
/// 构建地址信息
|
||||
Widget _buildAddressInfo() {
|
||||
// 根据模式调整字体大小(钱包地址较长,需要更小的字体)
|
||||
final addressFontSize = _showRealAddress ? 12.0 : 20.0;
|
||||
final addressLetterSpacing = _showRealAddress ? 0.5 : 1.5;
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// 充值ID标题
|
||||
const Text(
|
||||
'充值ID',
|
||||
style: TextStyle(
|
||||
// 标题(根据模式显示不同文字)
|
||||
Text(
|
||||
_addressTitle,
|
||||
style: const TextStyle(
|
||||
fontSize: 16,
|
||||
fontFamily: 'Inter',
|
||||
fontWeight: FontWeight.w700,
|
||||
|
|
@ -491,17 +570,17 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
// ID文本
|
||||
// 地址文本
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
child: Text(
|
||||
_isLoading ? '加载中...' : _depositAddress,
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontSize: addressFontSize,
|
||||
fontFamily: 'Inter',
|
||||
fontWeight: FontWeight.w600,
|
||||
height: 1.5,
|
||||
letterSpacing: 1.5,
|
||||
letterSpacing: addressLetterSpacing,
|
||||
color: const Color(0xFF5D4037).withValues(alpha: 0.9),
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
|
|
@ -521,7 +600,7 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Text(
|
||||
'复制ID',
|
||||
_showRealAddress ? '复制地址' : '复制ID',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
fontFamily: 'Inter',
|
||||
|
|
@ -550,10 +629,14 @@ class _DepositUsdtPageState extends ConsumerState<DepositUsdtPage> {
|
|||
|
||||
/// 构建警告文字
|
||||
Widget _buildWarningText() {
|
||||
final warningText = _showRealAddress
|
||||
? '请向此 KAVA 网络地址转入 USDT'
|
||||
: '请使用此充值ID进行充值';
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.fromLTRB(20, 16, 20, 48),
|
||||
child: Text(
|
||||
'请使用此充值ID进行充值',
|
||||
warningText,
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
fontFamily: 'Inter',
|
||||
|
|
|
|||
Loading…
Reference in New Issue