completed migrating data scope from user to workspace
This commit is contained in:
@@ -23,7 +23,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
late AccountProvider _accountProvider;
|
||||
|
||||
bool _isLoggedIn = false;
|
||||
String? _phoneNumber;
|
||||
String? _workspaceId;
|
||||
|
||||
AccountModel? _usdAccount;
|
||||
AccountModel? _zwgAccount;
|
||||
@@ -31,6 +31,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
bool _isLoadingZwG = false;
|
||||
String? _usdError;
|
||||
String? _zwgError;
|
||||
bool _showAccountError = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -55,9 +56,9 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
_phoneNumber = prefs.getString('phone');
|
||||
_workspaceId = prefs.getString('workspaceId');
|
||||
|
||||
if (_phoneNumber == null || _phoneNumber!.isEmpty) {
|
||||
if (_workspaceId == null || _workspaceId!.isEmpty) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -67,9 +68,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
});
|
||||
|
||||
// Fetch USD balance
|
||||
final usdResult = await _accountProvider.fetchAccount(
|
||||
'USD$_phoneNumber',
|
||||
);
|
||||
final usdResult = await _accountProvider.fetchAccount(_workspaceId, 'USD');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoadingUsd = false;
|
||||
@@ -83,9 +82,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
}
|
||||
|
||||
// Fetch ZWG balance
|
||||
final zwgResult = await _accountProvider.fetchAccount(
|
||||
'ZWG$_phoneNumber',
|
||||
);
|
||||
final zwgResult = await _accountProvider.fetchAccount(_workspaceId, 'ZWG');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoadingZwG = false;
|
||||
@@ -104,25 +101,23 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
!zwgResult.isSuccess &&
|
||||
_isLoggedIn) {
|
||||
setState(() {
|
||||
_isLoggedIn = false;
|
||||
_showAccountError = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _refreshBalances() async {
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
_phoneNumber = prefs.getString('phone');
|
||||
_workspaceId = prefs.getString('workspaceId');
|
||||
|
||||
if (_phoneNumber == null || _phoneNumber!.isEmpty) return;
|
||||
if (_workspaceId == null || _workspaceId!.isEmpty) return;
|
||||
|
||||
setState(() {
|
||||
_isLoadingUsd = true;
|
||||
_isLoadingZwG = true;
|
||||
});
|
||||
|
||||
final usdResult = await _accountProvider.fetchAccount(
|
||||
'USD$_phoneNumber',
|
||||
);
|
||||
final usdResult = await _accountProvider.fetchAccount(_workspaceId, 'USD');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoadingUsd = false;
|
||||
@@ -135,9 +130,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
});
|
||||
}
|
||||
|
||||
final zwgResult = await _accountProvider.fetchAccount(
|
||||
'ZWG$_phoneNumber',
|
||||
);
|
||||
final zwgResult = await _accountProvider.fetchAccount(_workspaceId, 'ZWG');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_isLoadingZwG = false;
|
||||
@@ -155,7 +148,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
!zwgResult.isSuccess &&
|
||||
_isLoggedIn) {
|
||||
setState(() {
|
||||
_isLoggedIn = false;
|
||||
_showAccountError = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -169,10 +162,47 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
return _buildLoginPrompt(theme, isDark);
|
||||
}
|
||||
|
||||
if (_phoneNumber == null || _phoneNumber!.isEmpty) {
|
||||
if (_workspaceId == null || _workspaceId!.isEmpty) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
if (_showAccountError) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Container(
|
||||
width: double.infinity,
|
||||
padding: const EdgeInsets.symmetric(vertical: 14, horizontal: 18),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.3),
|
||||
width: 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(
|
||||
Icons.error_outline_rounded,
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.7),
|
||||
size: 16,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Unable to load account balances. Please try refreshing.',
|
||||
style: TextStyle(
|
||||
fontSize: 12,
|
||||
color: theme.colorScheme.error.withValues(alpha: 0.7),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
child: Column(
|
||||
@@ -231,9 +261,7 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
: theme.colorScheme.primary,
|
||||
),
|
||||
label: Text(
|
||||
_isLoadingUsd || _isLoadingZwG
|
||||
? 'Refreshing...'
|
||||
: 'Refresh',
|
||||
_isLoadingUsd || _isLoadingZwG ? 'Refreshing...' : 'Refresh',
|
||||
style: TextStyle(
|
||||
fontSize: 11,
|
||||
fontWeight: FontWeight.w600,
|
||||
@@ -301,7 +329,10 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: theme.colorScheme.primary,
|
||||
foregroundColor: Colors.white,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 16,
|
||||
vertical: 8,
|
||||
),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
@@ -343,18 +374,17 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: gradientColors[0].withValues(alpha: isSelected ? 0.5 : 0.25),
|
||||
blurRadius: isSelected ? 12 : 6,
|
||||
offset: Offset(0, isSelected ? 4 : 2),
|
||||
),
|
||||
],
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: gradientColors[0].withValues(
|
||||
alpha: isSelected ? 0.5 : 0.25,
|
||||
),
|
||||
blurRadius: isSelected ? 12 : 6,
|
||||
offset: Offset(0, isSelected ? 4 : 2),
|
||||
),
|
||||
],
|
||||
border: isSelected
|
||||
? Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.8),
|
||||
width: 2,
|
||||
)
|
||||
? Border.all(color: Colors.white.withValues(alpha: 0.8), width: 2)
|
||||
: Border.all(
|
||||
color: Colors.white.withValues(alpha: 0.15),
|
||||
width: 1,
|
||||
@@ -474,4 +504,4 @@ class _AccountBalanceWidgetState extends State<AccountBalanceWidget> {
|
||||
final formatter = NumberFormat('#,##0.00', 'en_US');
|
||||
return '\$${formatter.format(balance)}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user