Skip to content

Commit

Permalink
fix: solve problem to render right users in ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
dnielopez committed Oct 31, 2023
1 parent 32d8493 commit 771cf20
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 218 deletions.
79 changes: 51 additions & 28 deletions lib/pages/home.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class _HomeScreenState extends State<HomeScreen> {
String? _balance;
SolanaClient? client;
String imageProfile = '';
bool loading = true;

final storage = const FlutterSecureStorage();

@override
void initState() {
super.initState();
_readPk();
getInitialInfo();
}

@override
Expand All @@ -56,7 +56,9 @@ class _HomeScreenState extends State<HomeScreen> {
SizedBox(height: statusBarHeight),
GestureDetector(
onTap: () {
GoRouter.of(context).replace('/profile');
if (!loading && _publicKey != null) {
GoRouter.of(context).replace('/profile');
}
},
child: Card(
color: Colors.white,
Expand Down Expand Up @@ -97,7 +99,7 @@ class _HomeScreenState extends State<HomeScreen> {
),
const SizedBox(height: 3),
Text(
_publicKey == null
loading || _publicKey == null
? 'Loading...'
: '${_publicKey!.substring(0, 6)}...${_publicKey!.substring(_publicKey!.length - 6, _publicKey!.length)}',
maxLines: 1,
Expand Down Expand Up @@ -186,16 +188,23 @@ class _HomeScreenState extends State<HomeScreen> {
),
child: TabBarView(
physics: const NeverScrollableScrollPhysics(),
children: [
const MiniGamesScreen(),
const RankingScreen(),
MydinogrowScreen(
address: _publicKey ?? '', getBalance: () => _getBalance()),
WalletScreen(
address: _publicKey ?? '',
balance: _balance,
getBalance: () => _getBalance()),
],
children: loading
? List.filled(
4,
const Center(
child: CircularProgressIndicator(),
))
: [
const MiniGamesScreen(),
const RankingScreen(),
MydinogrowScreen(
address: _publicKey ?? '',
getBalance: () => _getBalance()),
WalletScreen(
address: _publicKey ?? '',
balance: _balance,
getBalance: () => _getBalance()),
],
),
),
),
Expand All @@ -214,25 +223,35 @@ class _HomeScreenState extends State<HomeScreen> {
}

void _initializeClient() async {
await dotenv.load(fileName: ".env");
try {
setState(() {
loading = true;
});
} finally {
await dotenv.load(fileName: ".env");

client = SolanaClient(
rpcUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_URL'].toString()),
websocketUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_WSS'].toString()),
);
_getBalance();
client = SolanaClient(
rpcUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_URL'].toString()),
websocketUrl: Uri.parse(dotenv.env['QUICKNODE_RPC_WSS'].toString()),
);
_getBalance();
}
}

void _getBalance() async {
setState(() {
_balance = null;
});
final getBalance = await client?.rpcClient
.getBalance(_publicKey!, commitment: Commitment.confirmed);
final balance = (getBalance!.value) / lamportsPerSol;
setState(() {
_balance = balance.toString();
});
try {
setState(() {
_balance = null;
});
final getBalance = await client?.rpcClient
.getBalance(_publicKey!, commitment: Commitment.confirmed);
final balance = (getBalance!.value) / lamportsPerSol;
setState(() {
_balance = balance.toString();
});
} finally {
getInitialInfo();
}
}

Future getInitialInfo() async {
Expand Down Expand Up @@ -260,6 +279,10 @@ class _HomeScreenState extends State<HomeScreen> {
..backgroundColor = Colors.red;

SnakAlertWidget().show(alert);
} finally {
setState(() {
loading = false;
});
}
}

Expand Down
13 changes: 5 additions & 8 deletions lib/pages/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,12 @@ class _LoginScreenState extends State<LoginScreen> {
}
GoRouter.of(context).pushReplacement("/home");
} else {
const snackBar = SnackBar(
content: Text(
'Error: Invalid Password',
style: TextStyle(color: Colors.white),
),
backgroundColor: Colors.red,
);
ShowProps alert = ShowProps()
..text = 'Error: Invalid Password'
..context = context
..backgroundColor = Colors.red;

ScaffoldMessenger.of(context).showSnackBar(snackBar);
SnakAlertWidget().show(alert);

setState(() {
_loading = false;
Expand Down
Loading

0 comments on commit 771cf20

Please sign in to comment.