diff --git a/server/public.go b/server/public.go
index 9b704f03..36a3bc37 100644
--- a/server/public.go
+++ b/server/public.go
@@ -808,23 +808,28 @@ func (s *PublicServer) amountSatsSpan(a *api.Amount, td *TemplateData, classes s
func (s *PublicServer) tokenAmountSpan(t *api.TokenTransfer, td *TemplateData, classes string) template.HTML {
primary := formatAmountWithDecimals(t.Value, t.Decimals)
var rv strings.Builder
- appendAmountWrapperSpan(&rv, primary, td.CoinShortcut, classes)
+ appendAmountWrapperSpan(&rv, primary, t.Symbol, classes)
appendAmountSpan(&rv, "prim-amt", primary, t.Symbol, "")
if td.SecondaryCoin != "" {
var currentBase, currentSecondary, txBase, txSecondary string
p, err := strconv.ParseFloat(primary, 64)
if err == nil {
- baseRate, found := s.api.GetContractBaseRate(td.CurrentTicker, t.Contract, 0)
- if found {
- base := p * baseRate
- currentBase = strconv.FormatFloat(base, 'f', 6, 64)
- currentSecondary = formatSecondaryAmount(base*td.CurrentSecondaryCoinRate, td)
- }
- baseRate, found = s.api.GetContractBaseRate(td.TxTicker, t.Contract, td.Tx.Blocktime)
- if found {
- base := p * baseRate
- txBase = strconv.FormatFloat(base, 'f', 6, 64)
- txSecondary = formatSecondaryAmount(base*td.TxSecondaryCoinRate, td)
+ if td.CurrentTicker != nil {
+ // get rate from current ticker
+ baseRateCurrent, found := td.CurrentTicker.GetTokenRate(t.Contract)
+ if found {
+ base := p * float64(baseRateCurrent)
+ currentBase = strconv.FormatFloat(base, 'f', 6, 64)
+ currentSecondary = formatSecondaryAmount(base*td.CurrentSecondaryCoinRate, td)
+ // get the historical rate only if current rate exist
+ // it is very costly to search in DB in vain for a rate for token for which there are no exchange rates
+ baseRate, found := s.api.GetContractBaseRate(td.TxTicker, t.Contract, td.Tx.Blocktime)
+ if found {
+ base := p * baseRate
+ txBase = strconv.FormatFloat(base, 'f', 6, 64)
+ txSecondary = formatSecondaryAmount(base*td.TxSecondaryCoinRate, td)
+ }
+ }
}
}
if txBase != "" {
diff --git a/server/public_ethereumtype_test.go b/server/public_ethereumtype_test.go
index 6d87cf86..5c372b67 100644
--- a/server/public_ethereumtype_test.go
+++ b/server/public_ethereumtype_test.go
@@ -24,7 +24,7 @@ func httpTestsEthereumType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `
Trezor Fake Coin ExplorerAddress address7b.eth
0x7B62EB7fe80350DC7EC945C0B73242cb9877FB1b
0.000000000123450123 FAKE
Confirmed | |
| Balance | 0.000000000123450123 FAKE |
| Transactions | 2 |
| Non-contract Transactions | 0 |
| Internal Transactions | 0 |
| Nonce | 123 |
Transactions
`,
+ `Trezor Fake Coin ExplorerAddress address7b.eth
0x7B62EB7fe80350DC7EC945C0B73242cb9877FB1b
0.000000000123450123 FAKE
Confirmed | |
| Balance | 0.000000000123450123 FAKE |
| Transactions | 2 |
| Non-contract Transactions | 0 |
| Internal Transactions | 0 |
| Nonce | 123 |
Transactions
`,
},
},
{
@@ -42,7 +42,7 @@ func httpTestsEthereumType(t *testing.T, ts *httptest.Server) {
status: http.StatusOK,
contentType: "text/html; charset=utf-8",
body: []string{
- `Trezor Fake Coin ExplorerTransaction
0xa9cd088aba2131000da6f38a33c20169baee476218deea6b78720700b895b101
| In Block | Unconfirmed |
| Status | Success |
| Value | 0 FAKE |
| Gas Used / Limit | 52025 / 78037 |
| Gas Price | 0.00000004 FAKE (40 Gwei) |
| Fees | 0.002081 FAKE |
| RBF | ON |
`,
+ `Trezor Fake Coin ExplorerTransaction
0xa9cd088aba2131000da6f38a33c20169baee476218deea6b78720700b895b101
| In Block | Unconfirmed |
| Status | Success |
| Value | 0 FAKE |
| Gas Used / Limit | 52025 / 78037 |
| Gas Price | 0.00000004 FAKE (40 Gwei) |
| Fees | 0.002081 FAKE |
| RBF | ON |
`,
},
}, {
name: "explorerTokenDetail " + dbtestdata.EthAddr7b,