Skip to content

Commit

Permalink
Merge pull request #25 from liquality/feature-swap-inputs
Browse files Browse the repository at this point in the history
feat: added switch for fiat to crypto and update input for send and r…
  • Loading branch information
bradleySuira authored Jan 6, 2021
2 parents 1a41a18 + dc609b6 commit cccb0c1
Show file tree
Hide file tree
Showing 16 changed files with 396 additions and 183 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liquality-wallet",
"version": "0.10.5",
"version": "0.10.6",
"private": true,
"license": "MIT",
"author": "Liquality <[email protected]>",
Expand Down
13 changes: 12 additions & 1 deletion src/assets/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -511,4 +511,15 @@ svg.qr-icon {
.selectors-asset {
width: 40px;
font-weight: bold;
}
}


.infinity-rotate {
-webkit-animation:spin 1s ease infinite;
-moz-animation:spin 1s ease infinite;
animation:spin 1s ease infinite;
animation-fill-mode: forwards;
}
@-moz-keyframes spin { 0% { -moz-transform: rotate(0deg); } 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 0% { -moz-transform: rotate(0deg); } 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 0% { -moz-transform: rotate(0deg); } 100% { transform:rotate(360deg); } }
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,73 @@ import ListItem from '@/components/ListItem'
import { ACTIVITY_FILTER_TYPES, ACTIVITY_STATUSES, getItemIcon } from '@/utils/history'
import DatePick from 'vue-date-pick'
import '@/assets/scss/vue-date-pick.scss'
import { getCSVContent, exportToCSV } from '@/utils/export'
const CSV_HEADERS = [
{
label: 'ID',
key: 'id'
},
{
label: 'Order ID',
key: 'orderId'
},
{
label: 'Network',
key: 'network'
},
{
label: 'Created',
key: 'createdAt'
},
{
label: 'From Asset',
key: 'from'
},
{
label: 'To Asset',
key: 'to'
},
{
label: 'From',
key: 'fromAddress'
},
{
label: 'To',
key: 'toAddress'
},
{
label: 'Send To',
key: 'sendTo'
},
{
label: 'Send Amount',
key: 'fromAmount'
},
{
label: 'Receive Amount',
key: 'toAmount'
},
{
label: 'Send Amount USD',
key: 'fromAmountUsd'
},
{
label: 'Receive Amount USD',
key: 'toAmountUsd'
},
{
label: 'Status',
key: 'fromAmountUsd'
},
{
label: 'Wallet ID',
key: 'walletId'
}
]
export default {
props: ['activityData'],
components: {
CalendarIcon,
ChevronDownIcon,
Expand All @@ -101,6 +166,7 @@ export default {
},
data () {
return {
headers: [...CSV_HEADERS],
open: false,
dateFilters: {
start: null,
Expand Down Expand Up @@ -134,6 +200,8 @@ export default {
}
},
methods: {
getCSVContent,
exportToCSV,
getItemIcon,
toogleTypeFilter (key) {
if (key in this.typeFilters) {
Expand All @@ -150,7 +218,8 @@ export default {
}
},
exportActivity () {
this.$emit('export-requested')
const content = this.getCSVContent(this.activityData, this.headers)
this.exportToCSV({ filename: 'activity.csv', content })
},
resetFilters () {
this.dateFilters = { start: null, end: null }
Expand Down
5 changes: 5 additions & 0 deletions src/components/ListItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ export default {
text-decoration: none;
}
.list-item-title,
.list-item-detail {
color: $color-text-primary;
font-weight: 400;
}
.list-item-detail,
.list-item-detail-sub {
text-align: right;
Expand Down
2 changes: 1 addition & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"version": "0.10.5",
"version": "0.10.6",
"name": "Liquality Wallet",
"description": "Secure multi-crypto wallet with built-in Atomic Swaps!",
"homepage_url": "https://liquality.io",
Expand Down
4 changes: 3 additions & 1 deletion src/store/actions/updateBalances.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Bluebird from 'bluebird'

export const updateBalances = async ({ state, commit, getters }, { network, walletId }) => {
const assets = state.enabledAssets[network][walletId]

commit('UPDATE_BALANCE_LOADING', { loading: true })
await Bluebird.map(assets, async asset => {
const addresses = await getters.client(network, walletId, asset).wallet.getUsedAddresses()
const balance = addresses.length === 0
Expand All @@ -11,4 +11,6 @@ export const updateBalances = async ({ state, commit, getters }, { network, wall

commit('UPDATE_BALANCE', { network, walletId, asset, balance })
}, { concurrency: 1 })

commit('UPDATE_BALANCE_LOADING', { loading: false })
}
7 changes: 7 additions & 0 deletions src/store/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ const migrations = [
}
return { ...state, customTokens }
}
},
{ // Add updading balance flag
version: 4,
migrate: async (state) => {
state.updateBalanceLoading = false
return { ...state }
}
}
]

Expand Down
3 changes: 3 additions & 0 deletions src/store/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export default {

Vue.set(state.balances[network][walletId], asset, balance)
},
UPDATE_BALANCE_LOADING (state, { loading }) {
state.updateBalanceLoading = loading
},
UPDATE_FEES (state, { network, walletId, asset, fees }) {
ensureNetworkWalletTree(state.fees, network, walletId, {})

Expand Down
1 change: 1 addition & 0 deletions src/store/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default {

addresses: {},
balances: {},
updateBalanceLoading: false,
fiatRates: {},
fees: {},
history: {},
Expand Down
12 changes: 10 additions & 2 deletions src/utils/coinFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ export const prettyBalance = (amount, coin) => {

export const prettyFiatBalance = (amount, rate) => {
if (!amount) return amount

const fiatAmount = BN(amount).times(rate)

return fiatAmount.toFormat(2, BN.ROUND_CEIL)
}

export const cryptoToFiat = (amount, rate) => {
if (!amount) return amount
return BN(amount).times(rate).toFormat(2, BN.ROUND_CEIL)
}

export const fiatToCrypto = (amount, rate) => {
if (!amount) return amount
return BN(amount).dividedBy(rate).dp(VALUE_DECIMALS, BN.ROUND_FLOOR)
}
42 changes: 42 additions & 0 deletions src/utils/history.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import moment from '@/utils/moment'

export const SWAP_STATUS_STEP_MAP = {
QUOTE: 0,
SECRET_READY: 0,
Expand Down Expand Up @@ -123,3 +125,43 @@ export const getItemIcon = (name) => {
return require('../assets/icons/blank_asset.svg?inline')
}
}

export const applyActivityFilters = (activity, filters) => {
const { types, statuses, dates } = filters
let data = [...activity]
if (types.length > 0) {
data = data.filter(i => types.includes(i.type))
}

if (statuses.length > 0) {
data = data.filter(i => {
if (i.type === 'SWAP') {
return statuses.includes(SWAP_STATUS_FILTER_MAP[i.status])
}

if (i.type === 'SEND') {
return statuses.includes(SEND_STATUS_FILTER_MAP[i.status])
}

return true
})
}

if (dates.start) {
const filter = moment(dates.start)
data = data.filter(i => {
const start = moment(i.startTime)
return filter >= start
})
}

if (dates.end) {
const filter = moment(dates.end)
data = data.filter(i => {
const end = moment(i.startTime)
return filter <= end
})
}

return data
}
29 changes: 25 additions & 4 deletions src/views/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
</NavBar>
<div class="account_main">
<div class="account_top">
<RefreshIcon @click="refresh" class="account_refresh-icon" />
<RefreshIcon @click.stop="refresh"
class="account_refresh-icon"
:class="{ 'infinity-rotate': updateBalanceLoading }"
/>
<div class="account_balance">
<div v-if="fiatRates[asset]" class="account_balance_fiat">${{prettyFiatBalance(balance, fiatRates[asset])}}</div>
<div>
Expand Down Expand Up @@ -33,7 +36,8 @@
</div>
</div>
<div class="account_transactions">
<TransactionList :transactions="assetHistory" />
<ActivityFilter @filters-changed="applyFilters" :activity-data="activityData"/>
<TransactionList :transactions="activityData" />
</div>
</div>
</div>
Expand All @@ -51,6 +55,8 @@ import { prettyBalance, prettyFiatBalance } from '@/utils/coinFormatter'
import { shortenAddress } from '@/utils/address'
import { getAssetIcon } from '@/utils/asset'
import TransactionList from '@/components/TransactionList'
import ActivityFilter from '@/components/ActivityFilter'
import { applyActivityFilters } from '@/utils/history'
export default {
components: {
Expand All @@ -59,16 +65,27 @@ export default {
SendIcon,
ReceiveIcon,
SwapIcon,
ActivityFilter,
TransactionList
},
data () {
return {
addressCopied: false
addressCopied: false,
activityData: []
}
},
props: ['asset'],
computed: {
...mapState(['activeWalletId', 'activeNetwork', 'balances', 'addresses', 'history', 'fiatRates', 'marketData']),
...mapState([
'activeWalletId',
'activeNetwork',
'balances',
'addresses',
'history',
'fiatRates',
'marketData',
'updateBalanceLoading'
]),
balance () {
return prettyBalance(this.balances[this.activeNetwork][this.activeWalletId][this.asset], this.asset)
},
Expand Down Expand Up @@ -106,12 +123,16 @@ export default {
},
refresh () {
this.updateBalances({ network: this.activeNetwork, walletId: this.activeWalletId })
},
applyFilters (filters) {
this.activityData = applyActivityFilters([...this.assetHistory], filters)
}
},
async created () {
if (!this.address) {
await this.getUnusedAddresses({ network: this.activeNetwork, walletId: this.activeWalletId, assets: [this.asset] })
}
this.activityData = [...this.assetHistory]
}
}
</script>
Expand Down
Loading

0 comments on commit cccb0c1

Please sign in to comment.