-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ana/multiple denoms in porfolio (missing better designs) #3365
Changes from 15 commits
ba70382
81e6c7e
3d31015
3866659
6e7c8ba
3682bf4
337b69c
802012a
0c25e23
f3b3102
66d8554
14b8681
4f20515
2eded47
22564e1
a03eb2f
9c6aee6
e8be4eb
aeff1d0
33ccad9
2ff9be8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Added] [#3365](https://github.com/cosmos/lunie/pull/3365) TmBalance now displays multiple tokens balances and has a currency selector to display total value in the selected fiat currency @Bitcoinera |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,13 +11,47 @@ | |
</div> | ||
<div v-else> | ||
<div class="values-container"> | ||
<div class="total-atoms"> | ||
<h3>Total {{ stakingDenom }}</h3> | ||
<h2 class="total-atoms__value"> | ||
{{ overview.totalStake | shortDecimals | noBlanks }} | ||
</h2> | ||
<div class="upper-header"> | ||
<div class="total-atoms"> | ||
<h3>Total {{ stakingDenom }}</h3> | ||
<h2 class="total-atoms__value"> | ||
{{ overview.totalStake | shortDecimals | noBlanks }} | ||
</h2> | ||
</div> | ||
<TmFormGroup | ||
v-if="balances && balances.length > 1" | ||
class="currency-selector" | ||
field-id="currency" | ||
field-label="Currency" | ||
> | ||
<TmField | ||
v-model="selectedFiatCurrency" | ||
:title="`Select your fiat currency`" | ||
:options="fiatCurrencies" | ||
placeholder="Select your currency..." | ||
type="select" | ||
/> | ||
</TmFormGroup> | ||
</div> | ||
<div v-if="balances && balances.length > 1" class="row small-container"> | ||
<div class="col"> | ||
<h3>Total Tokens</h3> | ||
<h2> | ||
<TmField | ||
id="balance" | ||
:title="`All your token balances`" | ||
:options=" | ||
convertedBalances.length > 1 | ||
? convertedBalances | ||
: concatBalances | ||
" | ||
:placeholder="selectedTokenFiatValue" | ||
type="select" | ||
:is-disabled="true" | ||
/> | ||
</h2> | ||
</div> | ||
</div> | ||
|
||
<div class="row small-container"> | ||
<div v-if="overview.totalStake > 0" class="available-atoms"> | ||
<h3>Available {{ stakingDenom }}</h3> | ||
|
@@ -58,12 +92,17 @@ import { noBlanks } from "src/filters" | |
import TmBtn from "common/TmBtn" | ||
import SendModal from "src/ActionModal/components/SendModal" | ||
import ModalWithdrawRewards from "src/ActionModal/components/ModalWithdrawRewards" | ||
import TmFormGroup from "common/TmFormGroup" | ||
import TmField from "src/components/common/TmField" | ||
import { UserTransactionAdded } from "src/gql" | ||
import { mapGetters } from "vuex" | ||
import gql from "graphql-tag" | ||
|
||
export default { | ||
name: `tm-balance`, | ||
components: { | ||
TmFormGroup, | ||
TmField, | ||
TmBtn, | ||
SendModal, | ||
ModalWithdrawRewards | ||
|
@@ -75,7 +114,12 @@ export default { | |
data() { | ||
return { | ||
overview: {}, | ||
stakingDenom: "" | ||
stakingDenom: "", | ||
balances: [], | ||
balancesWithFiat: [], | ||
selectedTokenFiatValue: `Tokens Total Fiat Value`, | ||
selectedFiatCurrency: ``, | ||
convertedBalances: [] | ||
} | ||
}, | ||
computed: { | ||
|
@@ -84,6 +128,35 @@ export default { | |
// the validator rewards are needed to filter the top 5 validators to withdraw from | ||
readyToWithdraw() { | ||
return this.overview.totalRewards > 0 | ||
}, | ||
concatBalances() { | ||
let balancesArray = [] | ||
if (this.balances.length > 1) { | ||
balancesArray = this.balances.map(({ denom, amount }) => ({ | ||
value: ``, | ||
key: denom.concat(` ` + amount) | ||
})) | ||
} | ||
return balancesArray | ||
}, | ||
fiatCurrencies() { | ||
return [ | ||
{ key: `EUR`, value: `EUR` }, | ||
{ key: `USD`, value: `USD` }, | ||
{ key: `GBP`, value: `GBP` }, | ||
{ key: `CHF`, value: `CHF` }, | ||
{ key: `JPY`, value: `JPY` } | ||
] | ||
} | ||
}, | ||
watch: { | ||
balancesWithFiat: function() { | ||
this.convertedBalances = this.balancesWithFiat.map( | ||
({ denom, fiatValue }) => ({ | ||
value: ``, | ||
key: denom.concat(` ` + fiatValue) | ||
}) | ||
) | ||
} | ||
}, | ||
methods: { | ||
|
@@ -120,9 +193,66 @@ export default { | |
} | ||
}, | ||
skip() { | ||
/* istanbul ignore next */ | ||
return !this.address | ||
} | ||
}, | ||
balances: { | ||
query: gql` | ||
query balances($networkId: String!, $address: String!) { | ||
balances(networkId: $networkId, address: $address) { | ||
denom | ||
amount | ||
} | ||
} | ||
`, | ||
variables() { | ||
/* istanbul ignore next */ | ||
return { | ||
networkId: this.network, | ||
address: this.address | ||
} | ||
}, | ||
skip() { | ||
/* istanbul ignore next */ | ||
return !this.address | ||
} | ||
}, | ||
balancesWithFiat: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it correct, that we load the balances twice now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see any other option. Unless there is some way to use one fragment or another conditionally (either
or
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ?! why not just load the latter? it holds all the info right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because I don't have fiatCurrency at the beginning... Well, this is easily fixed by selecting a default fiatCurrency. And then I can also make I will go this way ✌️ |
||
query: gql` | ||
query balances( | ||
$networkId: String! | ||
$address: String! | ||
$fiatCurrency: String | ||
) { | ||
balances( | ||
networkId: $networkId | ||
address: $address | ||
fiatCurrency: $fiatCurrency | ||
) { | ||
denom | ||
amount | ||
fiatValue | ||
} | ||
} | ||
`, | ||
variables() { | ||
/* istanbul ignore next */ | ||
return { | ||
networkId: this.network, | ||
address: this.address, | ||
fiatCurrency: this.selectedFiatCurrency | ||
} | ||
}, | ||
skip() { | ||
/* istanbul ignore next */ | ||
return !this.address || !this.selectedFiatCurrency | ||
}, | ||
update(data) { | ||
/* istanbul ignore next */ | ||
return data.balances | ||
} | ||
}, | ||
stakingDenom: { | ||
query: gql` | ||
query Network($networkId: String!) { | ||
|
@@ -133,6 +263,7 @@ export default { | |
} | ||
`, | ||
variables() { | ||
/* istanbul ignore next */ | ||
return { | ||
networkId: this.network | ||
} | ||
|
@@ -145,12 +276,14 @@ export default { | |
$subscribe: { | ||
userTransactionAdded: { | ||
variables() { | ||
/* istanbul ignore next */ | ||
return { | ||
networkId: this.network, | ||
address: this.address | ||
} | ||
}, | ||
skip() { | ||
/* istanbul ignore next */ | ||
return !this.address | ||
}, | ||
query: UserTransactionAdded, | ||
|
@@ -161,11 +294,13 @@ export default { | |
}, | ||
blockAdded: { | ||
variables() { | ||
/* istanbul ignore next */ | ||
return { | ||
networkId: this.network | ||
} | ||
}, | ||
query() { | ||
/* istanbul ignore next */ | ||
return gql` | ||
subscription($networkId: String!) { | ||
blockAdded(networkId: $networkId) { | ||
|
@@ -217,6 +352,12 @@ export default { | |
padding-right: 2.5rem; | ||
} | ||
|
||
.currency-selector.tm-form-group { | ||
position: absolute; | ||
right: 1.25rem; | ||
top: -0.7rem; | ||
} | ||
|
||
.rewards h2 { | ||
color: var(--success); | ||
font-size: var(--m); | ||
|
@@ -277,6 +418,11 @@ export default { | |
text-align: center; | ||
} | ||
|
||
.currency-selector.tm-form-group { | ||
width: 40px; | ||
right: 2.5rem; | ||
} | ||
|
||
.button-container { | ||
width: 100%; | ||
padding: 1rem; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you considered making this a computed instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the issue here is that I cannot query
balancesWithFiat
at the beginning, when the component loads, since I lack of the fiatCurrency parameter. That is why I went the watch way.