Speed up opening the program by fetching price after
This commit is contained in:
parent
60a11252cb
commit
8436769aa8
17
main.cpp
17
main.cpp
|
@ -52,7 +52,11 @@ double getConversionRate() {
|
||||||
void displayMenu(WINDOW *menu_win, int highlight, const std::string choices[], int n_choices, double solRate) {
|
void displayMenu(WINDOW *menu_win, int highlight, const std::string choices[], int n_choices, double solRate) {
|
||||||
int x = 2, y = 2;
|
int x = 2, y = 2;
|
||||||
box(menu_win, 0, 0);
|
box(menu_win, 0, 0);
|
||||||
|
if(solRate == 0.0) {
|
||||||
|
mvwprintw(menu_win, 1, 1, "Fetching SOL price...");
|
||||||
|
} else {
|
||||||
mvwprintw(menu_win, 1, 1, "1 SOL = $%.2f ", solRate);
|
mvwprintw(menu_win, 1, 1, "1 SOL = $%.2f ", solRate);
|
||||||
|
}
|
||||||
for(int i = 0; i < n_choices; ++i) {
|
for(int i = 0; i < n_choices; ++i) {
|
||||||
if(highlight == i + 1) {
|
if(highlight == i + 1) {
|
||||||
wattron(menu_win, A_REVERSE);
|
wattron(menu_win, A_REVERSE);
|
||||||
|
@ -90,7 +94,7 @@ int main() {
|
||||||
start_color();
|
start_color();
|
||||||
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
init_pair(1, COLOR_CYAN, COLOR_BLACK);
|
||||||
|
|
||||||
double rate = getConversionRate();
|
double rate = 0.0;
|
||||||
|
|
||||||
WINDOW *menu_win = newwin(7, 60, 4, 4);
|
WINDOW *menu_win = newwin(7, 60, 4, 4);
|
||||||
keypad(menu_win, TRUE);
|
keypad(menu_win, TRUE);
|
||||||
|
@ -101,12 +105,23 @@ int main() {
|
||||||
|
|
||||||
int highlight = 1;
|
int highlight = 1;
|
||||||
|
|
||||||
|
bool needsFetch = true;
|
||||||
|
|
||||||
displayMenu(menu_win, highlight, choices, n_choices, rate);
|
displayMenu(menu_win, highlight, choices, n_choices, rate);
|
||||||
|
|
||||||
int choice = 0;
|
int choice = 0;
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
while(1) {
|
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);
|
c = wgetch(menu_win);
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case KEY_UP:
|
case KEY_UP:
|
||||||
|
|
Loading…
Reference in New Issue