CodingNic

Market Data and API Integration

Connect Cross-View Currency Actions

Market Data and API Integration 15 min read

Connect Cross-View Currency Actions

Connect Cross-View Currency Actions

The Rates and Popular Currencies screens should not be dead ends. They should update the same converter state already built in earlier lessons.

For a Rates-table Convert button, use the code already embedded by renderRates:

javascript
$("ratesBody").querySelectorAll("[data-c]").forEach(button => {
  button.onclick = () => {
    to = button.dataset.c;
    switchTab("convert");
    update();
  };
});

Popular Currencies uses the same idea: clicking a card changes to, while clicking its star saves the current pair.

Test it

From Rates, click Convert for EUR. You should land on Convert with EUR selected as the target currency.

Checkpoint

A currency chosen on another view must produce the same pair and rate you would get by selecting it directly in Convert.