Skip to content

Commit

Permalink
Merge pull request #254 from ava-labs/dev
Browse files Browse the repository at this point in the history
Update master
  • Loading branch information
kanatliemre authored Sep 2, 2021
2 parents 4ff1ae2 + 6874767 commit ae64a5f
Show file tree
Hide file tree
Showing 24 changed files with 1,601 additions and 144 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"test": "jest --verbose ./tests"
},
"dependencies": {
"@avalabs/avalanche-wallet-sdk": "0.9.1",
"@avalabs/vue_components": "0.9.0",
"@ethereumjs/common": "2.0.0",
"@ethereumjs/tx": "3.0.0",
Expand All @@ -43,7 +44,7 @@
"@types/vue-datetime": "1.0.0",
"@zxing/library": "0.15.2",
"abi-decoder": "2.4.0",
"avalanche": "3.6.1",
"avalanche": "3.8.1",
"axios": "0.21.1",
"big.js": "5.2.2",
"bip32": "2.0.5",
Expand All @@ -60,6 +61,7 @@
"core-js": "3.4.4",
"cors": "2.8.5",
"create-hash": "1.2.0",
"csv": "^5.5.0",
"ethereum-blockies-base64": "1.0.2",
"ethereumjs-tx": "2.1.2",
"ethereumjs-util": "^7.0.7",
Expand Down
6 changes: 6 additions & 0 deletions src/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,12 @@ textarea {
}
}

.v-input--checkbox{
label{
color: var(--primary-color) !important;
}
}

.vdatetime {
background-color: var(--bg-light) !important;
padding: 6px 12px !important;
Expand Down
5 changes: 0 additions & 5 deletions src/components/CreateWalletWorkflow/CreateWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,6 @@ export default class CreateWallet extends Vue {
setTimeout(async () => {
await parent.$store.dispatch('accessWallet', this.keyPhrase)
// if(this.rememberPassword && this.rememberValid){
// // console.log("Will remember..");
// parent.$store.dispatch('rememberWallets', this.rememberPassword);
// }
}, 500)
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/SidePanels/History/ViewTypes/BaseTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ export default class BaseTx extends Vue {
let addrs: string[] = this.addresses
let addrsRaw = addrs.map((addr) => addr.split('-')[1])
const isFromWallet = this.transaction.inputs.find((input) => {
let ins = this.transaction.inputs || []
const isFromWallet = ins.find((input) => {
return input.output.addresses.find((value) => {
return addrsRaw.includes(value)
})
Expand Down
4 changes: 3 additions & 1 deletion src/components/SidePanels/History/ViewTypes/ImportExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class ImportExport extends Vue {
}
get fromChainId() {
if (!this.transaction.inputs) return '?'
return this.transaction.inputs[0].output.chainID
}
Expand Down Expand Up @@ -86,7 +87,8 @@ export default class ImportExport extends Vue {
}, new BN(0))
return sumAmt
} else {
let sumAmt = this.transaction.inputs.reduce((acc, val) => {
let ins = this.transaction.inputs || []
let sumAmt = ins.reduce((acc, val) => {
let amt = new BN(val.output.amount)
return acc.add(amt)
}, new BN(0))
Expand Down
34 changes: 31 additions & 3 deletions src/components/SidePanels/History/ViewTypes/StakingTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
{{ endDate.toLocaleTimeString() }}
</p>
</div>
<div class="data_row reward_row">
<p>AVAX Price at reward date</p>
<p v-if="rewardDateAvaxPrice">{{ rewardDateAvaxPrice.toFixed(2) }} USD</p>
<p v-else>Unknown</p>
</div>
<div class="data_row reward_row">
<p>Total reward in USD</p>
<p v-if="totalRewardUSD">{{ totalRewardUSD.toLocaleString(2) }} USD</p>
<p v-else>-</p>
</div>
<div class="data_row">
<p v-if="!isDelegatorReward">{{ $t('transactions.reward_amount') }}</p>
<p v-else>{{ $t('transactions.fee_amount') }}</p>
Expand Down Expand Up @@ -79,10 +89,10 @@ import { ITransactionData } from '@/store/modules/history/types'
import { BN } from 'avalanche'
import { bnToBig } from '@/helpers/helper'
import { UnixNow } from 'avalanche/dist/utils'
import { ValidatorListItem } from '@/store/modules/platform/types'
import { ValidatorRaw } from '@/components/misc/ValidatorList/types'
import moment from 'moment'
import { WalletType } from '@/js/wallets/types'
import { getPriceAtUnixTime } from '@/helpers/price_helper'
import Big from 'big.js'
@Component
export default class StakingTx extends Vue {
Expand Down Expand Up @@ -111,7 +121,8 @@ export default class StakingTx extends Vue {
if (this.isValidator) return false
// If its a delegation, and the wallet does not own any of the inputs
let inUtxos = this.transaction.inputs.map((input) => input.output)
let ins = this.transaction.inputs || []
let inUtxos = ins.map((input) => input.output)
let inAddrs = []
for (var i = 0; i < inUtxos.length; i++) {
Expand Down Expand Up @@ -171,6 +182,22 @@ export default class StakingTx extends Vue {
return tot
}
get rewardAmtBig(): Big {
return bnToBig(this.rewardAmt, 9)
}
get rewardDateAvaxPrice(): number | undefined {
if (!this.endDate) return undefined
let unixTime = this.endDate.getTime()
let price = getPriceAtUnixTime(unixTime)
return price
}
get totalRewardUSD(): Big | undefined {
if (!this.rewardDateAvaxPrice) return undefined
return this.rewardAmtBig.times(this.rewardDateAvaxPrice)
}
get rewardAmtText() {
return bnToBig(this.rewardAmt, 9)
}
Expand All @@ -184,6 +211,7 @@ export default class StakingTx extends Vue {
return this.transaction.rewarded
}
// DO NOT use this as the date reward received. Use validator end time instead.
get rewardTime() {
return this.transaction.rewardedTime
}
Expand Down
4 changes: 2 additions & 2 deletions src/components/misc/MnemonicDisplay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { Vue, Component, Prop } from 'vue-property-decorator'
export default class MnemonicDisplay extends Vue {
@Prop({ default: '#FFFFFF' }) bgColor?: string
@Prop({ default: 4 }) rowSize!: number
@Prop() phrase!: string
wordNum: number = 24
get phraseArray(): string[] {
Expand All @@ -26,8 +28,6 @@ export default class MnemonicDisplay extends Vue {
}
return res
}
@Prop() phrase!: string
}
</script>
<style scoped lang="scss">
Expand Down
159 changes: 159 additions & 0 deletions src/components/modals/ExportAvaxCsvModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<template>
<modal ref="modal" title="Export AVAX Transfers" class="modal_main">
<div class="csv_modal_body">
<p>Only X chain AVAX transactions will be exported.</p>
<v-btn
class="button_secondary"
small
@click="submit"
:disabled="!canSubmit"
depressed
block
style="margin-top: 12px"
>
Download CSV File
</v-btn>
</div>
</modal>
</template>
<script lang="ts">
import 'reflect-metadata'
import { Vue, Component, Prop } from 'vue-property-decorator'
import Modal from '@/components/modals/Modal.vue'
import { CsvRowAvaxTransferData, ITransactionData, UTXO } from '@/store/modules/history/types'
import { bnToBig } from '@/helpers/helper'
import { getPriceAtUnixTime } from '@/helpers/price_helper'
const generate = require('csv-generate')
import moment from 'moment'
import {
avaxTransferDataToCsvRow,
durationToString,
getOutputTotals,
getOwnedOutputs,
getNotOwnedOutputs,
getAssetOutputs,
getAddresses,
getRewardOuts,
getStakeAmount,
createCSVContent,
downloadCSVFile,
parseMemo,
} from '@/store/modules/history/history_utils'
import { ava, avm } from '@/AVA'
import BN from 'bn.js'
@Component({
components: {
Modal,
},
})
export default class ExportAvaxCsvModal extends Vue {
open(): void {
let modal = this.$refs.modal as Modal
modal.open()
}
get canSubmit() {
return true
}
get transactions(): ITransactionData[] {
return this.$store.state.History.allTransactions
}
get wallet() {
return this.$store.state.activeWallet
}
get xAddresses(): string[] {
return this.wallet.getAllAddressesX()
}
get xAddressesStripped(): string[] {
return this.xAddresses.map((addr: string) => addr.split('-')[1])
}
get avaxID() {
return this.$store.state.Assets.AVA_ASSET_ID
}
submit() {
let myAddresses = this.xAddressesStripped
let avaxID = this.avaxID
let txs = this.transactions.filter((tx) => {
let avaxOutAmt = tx.outputTotals[avaxID]
if (!avaxOutAmt) return false
return tx.type === 'base' || tx.type === 'operation'
})
let txFee = avm.getTxFee()
let rows: CsvRowAvaxTransferData[] = []
const ZERO = new BN(0)
for (let i = 0; i < txs.length; i++) {
let tx = txs[i]
let ins = tx.inputs || []
let inUTXOs = ins.map((input) => input.output)
let avaxIns = getAssetOutputs(inUTXOs, avaxID)
let avaxOuts = getAssetOutputs(tx.outputs, avaxID)
let myIns = getOwnedOutputs(avaxIns, myAddresses)
let myOuts = getOwnedOutputs(avaxOuts, myAddresses)
let inTot = getOutputTotals(myIns)
let outTot = getOutputTotals(myOuts)
let gain = outTot.sub(inTot)
let otherIns = getNotOwnedOutputs(avaxIns, myAddresses)
let otherOuts = getNotOwnedOutputs(avaxOuts, myAddresses)
// If its only the fee, continue
if (gain.abs().lte(txFee)) continue
let isGain = gain.gt(ZERO)
let fromOwnedAddrs = getAddresses(myIns)
let toOwnedAddrs = getAddresses(myOuts)
let fromAddrs = getAddresses(otherIns)
let toAddrs = getAddresses(otherOuts)
// Subtract the fee if we sent it
let sendAmt = isGain ? gain : gain.add(txFee)
let txParsed: CsvRowAvaxTransferData = {
txId: tx.id,
date: new Date(tx.timestamp),
amount: bnToBig(sendAmt, 9),
from: isGain ? fromAddrs : fromOwnedAddrs,
to: isGain ? toOwnedAddrs : toAddrs,
memo: parseMemo(tx.memo),
isGain: isGain,
}
rows.push(txParsed)
}
let csvRows = rows.map((row) => avaxTransferDataToCsvRow(row))
let headers = ['Tx ID', 'Date', 'Memo', 'From', 'To', 'Sent/Received', 'Amount (AVAX)']
let allRows = [headers, ...csvRows]
let csvContent = createCSVContent(allRows)
downloadCSVFile(csvContent, 'avax_transfers')
}
}
</script>
<style scoped lang="scss">
.csv_modal_body {
width: 420px;
max-width: 100%;
padding: 10px 20px;
}
</style>
Loading

0 comments on commit ae64a5f

Please sign in to comment.