-
Notifications
You must be signed in to change notification settings - Fork 573
Expand file tree
/
Copy pathLifiToken.java
More file actions
91 lines (74 loc) · 2.17 KB
/
LifiToken.java
File metadata and controls
91 lines (74 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.alphawallet.app.entity.lifi;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
import java.util.Objects;
public class LifiToken
{
@SerializedName("address")
@Expose
public String address;
@SerializedName("symbol")
@Expose
public String symbol;
@SerializedName("decimals")
@Expose
public long decimals;
@SerializedName("chainId")
@Expose
public long chainId;
@SerializedName("name")
@Expose
public String name;
@SerializedName("coinKey")
@Expose
public String coinKey;
@SerializedName("priceUSD")
@Expose
public String priceUSD;
@SerializedName("logoURI")
@Expose
public String logoURI;
public String balance;
public double fiatEquivalent;
@Override
public boolean equals(Object o)
{
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LifiToken lToken = (LifiToken) o;
return address.equals(lToken.address) && symbol.equals(lToken.symbol);
}
@Override
public int hashCode()
{
return Objects.hash(address, symbol);
}
// Note: In the LIFI API, the native token has either of these two addresses.
public boolean isNativeToken()
{
return address.equalsIgnoreCase("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") ||
address.equalsIgnoreCase("0x0000000000000000000000000000000000000000");
}
public double getFiatValue()
{
try
{
double value = Double.parseDouble(balance);
double priceUSD = Double.parseDouble(this.priceUSD);
return value * priceUSD;
}
catch (NumberFormatException | NullPointerException e)
{
return 0.0;
}
}
public boolean isSimilarTo(com.alphawallet.app.entity.tokens.Token aToken, String walletAddress)
{
if (this.chainId == aToken.tokenInfo.chainId
&& this.address.equalsIgnoreCase(aToken.getAddress()))
{
return true;
}
return aToken.getAddress().equalsIgnoreCase(walletAddress) && isNativeToken();
}
}