Speed up opening the program by fetching price after

This commit is contained in:
Wizzard 2024-04-10 05:19:11 -04:00
parent 60a11252cb
commit 8436769aa8
1 changed files with 17 additions and 2 deletions

View File

@ -52,7 +52,11 @@ double getConversionRate() {
void displayMenu(WINDOW *menu_win, int highlight, const std::string choices[], int n_choices, double solRate) {
int x = 2, y = 2;
box(menu_win, 0, 0);
mvwprintw(menu_win, 1, 1, "1 SOL = $%.2f", solRate);
if(solRate == 0.0) {
mvwprintw(menu_win, 1, 1, "Fetching SOL price...");
} else {
mvwprintw(menu_win, 1, 1, "1 SOL = $%.2f ", solRate);
}
for(int i = 0; i < n_choices; ++i) {
if(highlight == i + 1) {
wattron(menu_win, A_REVERSE);
@ -90,7 +94,7 @@ int main() {
start_color();
init_pair(1, COLOR_CYAN, COLOR_BLACK);
double rate = getConversionRate();
double rate = 0.0;
WINDOW *menu_win = newwin(7, 60, 4, 4);
keypad(menu_win, TRUE);
@ -101,12 +105,23 @@ int main() {
int highlight = 1;
bool needsFetch = true;
displayMenu(menu_win, highlight, choices, n_choices, rate);
int choice = 0;
int c;
while(1) {
if (needsFetch) {
printw("Fetching SOL conversion rate, please wait...\n");
refresh();
rate = getConversionRate();
needsFetch = false;
clear();
displayMenu(menu_win, highlight, choices, n_choices, rate);
}
c = wgetch(menu_win);
switch(c) {
case KEY_UP: