Skip to content

Commit

Permalink
Merge pull request #412 from ava-labs/dev
Browse files Browse the repository at this point in the history
Update Master
  • Loading branch information
kanatliemre authored Jul 5, 2023
2 parents e608ad0 + 456575a commit 076f463
Show file tree
Hide file tree
Showing 19 changed files with 667 additions and 311 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@avalabs/avalanche-wallet-sdk": "0.20.0-alpha.11",
"@avalabs/glacier-sdk": "2.8.0-alpha.92",
"@avalabs/glacier-sdk": "2.8.0-alpha.108",
"@avalabs/vue_components": "0.10.0",
"@ethereumjs/common": "2.0.0",
"@ethereumjs/tx": "3.0.0",
Expand All @@ -28,7 +28,7 @@
"@ledgerhq/hw-transport-u2f": "5.36.0-deprecated",
"@ledgerhq/hw-transport-webhid": "5.51.1",
"@ledgerhq/hw-transport-webusb": "5.51.1",
"@openzeppelin/contracts": "4.9.0",
"@openzeppelin/contracts": "4.9.2",
"avalanche": "3.15.2",
"axios": "0.21.2",
"big.js": "5.2.2",
Expand Down
224 changes: 0 additions & 224 deletions src/components/SidePanels/History/ViewTypes/BaseTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -181,230 +181,6 @@ export default class BaseTx extends Vue {
get type() {
return this.transaction.txType as TransactionTypeName
}
// What did I lose?
// get inValues() {
// let addrs: string[] = this.addresses
//
// this.transaction.consumedUtxos.map((utxo) => {
// utxo.addresses
// utxo.addresses.in
// })
// let ins = this.transaction.inputs
// let res: TransactionValueDict = {} // asset id -> value dict
//
// // if empty
// if (!ins) {
// return res
// }
//
// ins.forEach((inputUtxo) => {
// const include = this.includeUtxo(inputUtxo.output, true)
// const assetId = inputUtxo.output.assetID
// const amt = inputUtxo.output.amount
//
// if (include) {
// if (res[assetId]) {
// res[assetId] += parseInt(amt)
// } else {
// res[assetId] = parseInt(amt)
// }
// }
// })
//
// return res
// }
/**
*
* @param utxo The UTXO object
* @param isInput is it an input UTXO?
*/
// includeUtxo(utxo: Utxo, isInput?: boolean) {
// // Does this wallet own this utxo
// const isOwner = utxo.addresses.filter((value) => this.addrsRaw.includes(value)).length > 0
//
// switch (this.transaction.txType) {
// case 'export':
// return utxo.consumedOnChainId === avm.getBlockchainID()
// case 'pvm_export':
// return utxo.consumedOnChainId === pChain.getBlockchainID()
// case 'pvm_import':
// case 'import':
// if (isInput) return false
// return isOwner
// case 'add_validator':
// case 'add_delegator':
// return !isInput && utxo.stake
// case 'operation':
// // if no payload it is avax
// // check if it is from wallet
// if (!utxo.payload && !isOwner) return false
// return true
// // default just return original logic
// // might need to be changed in the future as
// // more tx types are added
// case 'BaseTx':
// default:
// return isOwner
// }
//
// return false
// }
// get tokensReceived() {
// let tokens = this.summary.tokens
// let res = {}
// for (var assetId in tokens) {
// let asset = tokens[assetId]
// if (asset.amount.gte(new BN(0))) {
// //@ts-ignore
// res[assetId] = asset
// }
// }
// return res
// }
// get tokensSent() {
// let tokens = this.summary.tokens
// let res = {}
// for (var assetId in tokens) {
// let asset = tokens[assetId]
// if (asset.amount.lt(new BN(0))) {
// //@ts-ignore
// res[assetId] = asset
// }
// }
// return res
// }
// what did I gain?
// get outValues() {
// let addrs: string[] = this.addresses
// let addrsRaw = addrs.map((addr) => addr.split('-')[1])
// let outs = this.transaction.outputs
// let res: TransactionValueDict = {} // asset id -> value dict
//
// // if empty
// if (!outs) {
// return res
// }
//
// outs.forEach((utxoOut) => {
// let utxoAddrs = utxoOut.addresses
// let assetId = utxoOut.assetID
// let amt = utxoOut.amount
//
// const include = this.includeUtxo(utxoOut)
//
// if (include) {
// if (res[assetId]) {
// res[assetId] += parseInt(amt)
// } else {
// res[assetId] = parseInt(amt)
// }
// }
// })
//
// return res
// }
// get valList() {
// let ins = this.inValues
// let outs = this.outValues
// let res = JSON.parse(JSON.stringify(outs))
//
// for (var assetId in ins) {
// let inAmount = ins[assetId] || 0
// if (res[assetId]) {
// res[assetId] -= inAmount
// } else {
// res[assetId] = -1 * inAmount
// }
// }
//
// return res
// }
// get nftGroups() {
// let addrs: string[] = this.addresses
// let addrsRaw = addrs.map((addr) => addr.split('-')[1])
//
// let ins = this.transaction.inputs
// let outs = this.transaction.outputs
// let res: { [key in string]: { [key in string]: PayloadBase[] } } = {}
//
// // res = {
// // 'asset id': { ['group id']: 'payload' },
// // }
//
// const pushPayload = (rawPayload: string, assetID: string, groupID: number) => {
// let payload = Buffer.from(rawPayload, 'base64')
// payload = Buffer.concat([new Buffer(4).fill(payload.length), payload])
//
// try {
// let typeId = payloadtypes.getTypeID(payload)
// let pl: Buffer = payloadtypes.getContent(payload)
// let payloadbase: PayloadBase = payloadtypes.select(typeId, pl)
//
// if (res[assetID]) {
// if (res[assetID][groupID]) {
// res[assetID][groupID].push(payloadbase)
// } else {
// res[assetID] = {
// [groupID]: [payloadbase],
// }
// }
// } else {
// res[assetID] = {
// [groupID]: [payloadbase],
// }
// }
// } catch (e) {
// // console.error(e)
// }
// }
//
// if (ins) {
// ins.forEach((inputUtxo) => {
// const groupID = inputUtxo.output.groupID
// const assetID = inputUtxo.output.assetID
//
// if (inputUtxo.output.payload) {
// pushPayload(inputUtxo.output.payload, assetID, groupID)
// }
// })
// }
//
// if (outs) {
// outs.forEach((utxoOut) => {
// let groupID = utxoOut.groupID
// let assetID = utxoOut.assetID
//
// if (utxoOut.payload) {
// pushPayload(utxoOut.payload, assetID, groupID)
// }
// })
// }
//
// return res
// }
// get operationDirection() {
// if (this.type !== 'operation') return 'N/A'
//
// let addrs: string[] = this.addresses
// let addrsRaw = addrs.map((addr) => addr.split('-')[1])
//
// let ins = this.transaction.inputs || []
// const isFromWallet = ins.find((input) => {
// return input.output.addresses.find((value) => {
// return addrsRaw.includes(value)
// })
// })
//
// return isFromWallet ? 'Sent' : 'Received'
// }
}
</script>
<style scoped lang="scss">
Expand Down
101 changes: 88 additions & 13 deletions src/components/SidePanels/History/ViewTypes/ImportExport.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
<template>
<div class="import_row" :export="isExport">
<div class="import_row" :export="isExport && !isExportReceiver">
<p class="actionTitle">{{ actionTitle }} ({{ chainAlias }})</p>
<div class="flex-column">
<p class="amt" v-for="(bal, key) in balances" :key="key">
{{ isExport ? '-' : '' }}{{ toLocaleString(bal.amount, bal.decimals) }}
{{ bal.symbol }}
<p v-if="isExportReceiver" class="amt">
{{ toLocaleString(outputReceivedBalances, 9) }} AVAX
</p>
<template v-else>
<p class="amt" v-for="(bal, key) in balances" :key="key">
{{ isExport ? '-' : '' }}{{ toLocaleString(bal.amount, bal.decimals) }}
{{ bal.symbol }}
</p>
</template>
</div>
</div>
</template>
Expand All @@ -14,8 +19,27 @@ import { avm, cChain, pChain } from '@/AVA'
import { Vue, Component, Prop } from 'vue-property-decorator'
import { BN } from 'avalanche'
import { bnToBig } from '@/helpers/helper'
import { TransactionType, XChainTransaction } from '@/js/Glacier/models'
import {
isTransactionP,
isTransactionX,
TransactionType,
XChainTransaction,
} from '@/js/Glacier/models'
import { getExportBalances } from '@/components/SidePanels/History/ViewTypes/getExportBalances'
import { WalletType } from '@/js/wallets/types'
import { isOwnedUTXO } from '@/js/Glacier/isOwnedUtxo'
function idToAlias(chainId: string | undefined) {
if (chainId === pChain.getBlockchainID()) {
return 'P'
} else if (chainId === avm.getBlockchainID()) {
return 'X'
} else if (chainId === cChain.getBlockchainID()) {
return 'C'
}
return chainId
}
@Component
export default class ImportExport extends Vue {
@Prop() transaction!: TransactionType
Expand All @@ -33,7 +57,15 @@ export default class ImportExport extends Vue {
}
get actionTitle() {
return this.isExport ? 'Export' : 'Import'
if (this.isExport) {
if (this.isExportReceiver) {
return 'Received'
} else {
return 'Export'
}
} else {
return 'Import'
}
}
/**
Expand All @@ -51,20 +83,63 @@ export default class ImportExport extends Vue {
get chainAlias() {
let chainId = this.isExport ? this.sourceChainId : this.destinationChainId
return idToAlias(chainId)
}
if (chainId === pChain.getBlockchainID()) {
return 'P'
} else if (chainId === avm.getBlockchainID()) {
return 'X'
} else if (chainId === cChain.getBlockchainID()) {
return 'C'
/**
* All X/P addresses used by the wallet
*/
get addresses() {
let wallet: WalletType | null = this.$store.state.activeWallet
if (!wallet) return []
return wallet.getHistoryAddresses()
}
get ownedInputs() {
const tx = this.transaction
if (isTransactionP(tx)) {
return tx.consumedUtxos.filter((utxo) => {
return isOwnedUTXO(utxo, this.addresses)
})
} else {
return []
}
return chainId
}
get ownedOutputs() {
const tx = this.transaction
if (isTransactionP(tx)) {
return tx.emittedUtxos.filter((utxo) => {
return isOwnedUTXO(utxo, this.addresses)
})
} else {
return []
}
}
get sourceChainAlias() {
return idToAlias(this.sourceChainId)
}
get wallet(): WalletType {
return this.$store.state.activeWallet
}
get balances() {
return getExportBalances(this.transaction, this.destinationChainId, this.getAssetFromID)
}
// If user received tokens from the export, but didnt consume any of their utxos
// Essentially, the P chain sending hack
get isExportReceiver() {
return this.isExport && this.ownedInputs.length === 0 && this.ownedOutputs.length > 0
}
get outputReceivedBalances() {
return this.ownedOutputs.reduce((agg, utxo) => {
return agg.add(new BN(utxo.amount))
}, new BN(0))
}
}
</script>
<style scoped lang="scss">
Expand Down
Loading

0 comments on commit 076f463

Please sign in to comment.