Skip to content

Commit cb4573a

Browse files
authored
Merge pull request ava-labs#119 from ava-labs/dev
Master Update
2 parents b8ea770 + eebec39 commit cb4573a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1908
-790
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
"@types/vue-datetime": "1.0.0",
5353
"@zxing/library": "0.15.2",
5454
"avalanche": "3.1.0",
55+
"axios": "0.21.1",
5556
"big.js": "5.2.2",
5657
"bip32": "2.0.5",
5758
"bip32-path": "^0.4.2",

src/_dark_theme.scss

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
$purple: #4C2E56;
2-
$purple-light: #867E89;
3-
$pink: #E84970;
4-
$pink-light: #FF8080;
1+
$purple: #4c2e56;
2+
$purple-light: #867e89;
3+
$pink: #e84970;
4+
$pink-light: #ff8080;
55
$pink-extra-light: #ffe6e6;
6-
$gray: #F5F6FA;
7-
$white: #FFF;
8-
$green: #6BC688;
6+
$gray: #f5f6fa;
7+
$white: #fff;
8+
$green: #6bc688;
9+
$info: #008dc5;
910
$green-light: #83f2a6;
1011
$green-extra-light: #a9efbf;
1112

@@ -14,4 +15,4 @@ $primary-color-light: $purple-light;
1415
$secondary-color: $pink;
1516
$secondary-color-light: $pink-light;
1617
$secondary-color-extra-light: $pink-extra-light;
17-
$background-color: $gray;
18+
$background-color: $gray;

src/_main.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ html[data-theme='day']{
405405
--link-secondary: #6E7479;
406406
--error:#f00;
407407
--success: #6BC688;
408+
--info: #2c7490;
409+
--info-1: 44, 116, 144;
408410

409411
--bg-wallet: #F5F6FA;
410412
--bg-wallet-light: #FFF;
@@ -424,6 +426,8 @@ html[data-theme='night']{
424426
--link-secondary: #6E7479;
425427
--error:#E84970;
426428
--success: #6BC688;
429+
--info: #4c8caf;
430+
--info-1: 76, 140, 175;
427431

428432
--bg-wallet: #181B1D;
429433
--bg-wallet-light: #242729;
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
<template>
2+
<div>
3+
<div class="utxos">
4+
<tx-history-value
5+
v-for="(amount, assetId) in valList"
6+
:key="assetId"
7+
:amount="amount"
8+
:type="type"
9+
:asset-id="assetId"
10+
:is-income="false"
11+
:operation-color="operationColor"
12+
:operation-direction="operationDirection"
13+
></tx-history-value>
14+
<div class="nfts">
15+
<div v-for="(groupIDs, assetID) in nftGroups" :key="assetID">
16+
<tx-history-nft-family-group
17+
v-for="(payloads, id) in groupIDs"
18+
:key="id"
19+
:payloads="payloads"
20+
:assetID="assetID"
21+
class="group"
22+
></tx-history-nft-family-group>
23+
</div>
24+
</div>
25+
</div>
26+
</div>
27+
</template>
28+
<script lang="ts">
29+
import { Vue, Component, Prop } from 'vue-property-decorator'
30+
import { ITransactionData, UTXO } from '@/store/modules/history/types'
31+
import { TransactionValueDict } from '@/components/SidePanels/types'
32+
import { PayloadBase, PayloadTypes } from 'avalanche/dist/utils'
33+
import { Buffer } from 'avalanche'
34+
import { WalletType } from '@/store/types'
35+
import { avm, pChain } from '@/AVA'
36+
37+
import TxHistoryValue from '@/components/SidePanels/TxHistoryValue.vue'
38+
import TxHistoryNftFamilyGroup from '@/components/SidePanels/TxHistoryNftFamilyGroup.vue'
39+
40+
let payloadtypes = PayloadTypes.getInstance()
41+
42+
@Component({
43+
components: {
44+
TxHistoryValue,
45+
TxHistoryNftFamilyGroup,
46+
},
47+
})
48+
export default class BaseTx extends Vue {
49+
@Prop() transaction!: ITransactionData
50+
51+
get addresses() {
52+
let wallet: WalletType = this.$store.state.activeWallet
53+
if (!wallet) return []
54+
55+
return wallet.getHistoryAddresses()
56+
}
57+
58+
get addrsRaw() {
59+
let addrs: string[] = this.addresses
60+
return addrs.map((addr) => addr.split('-')[1])
61+
}
62+
63+
get type() {
64+
return this.transaction.type
65+
}
66+
67+
// What did I lose?
68+
get inValues() {
69+
let addrs: string[] = this.addresses
70+
let addrsRaw = addrs.map((addr) => addr.split('-')[1])
71+
72+
let ins = this.transaction.inputs
73+
let res: TransactionValueDict = {} // asset id -> value dict
74+
75+
// if empty
76+
if (!ins) {
77+
return res
78+
}
79+
80+
ins.forEach((inputUtxo) => {
81+
const include = this.includeUtxo(inputUtxo.output, true)
82+
const assetId = inputUtxo.output.assetID
83+
const amt = inputUtxo.output.amount
84+
85+
if (include) {
86+
if (res[assetId]) {
87+
res[assetId] += parseInt(amt)
88+
} else {
89+
res[assetId] = parseInt(amt)
90+
}
91+
}
92+
})
93+
94+
return res
95+
}
96+
97+
includeUtxo(utxo: UTXO, isInput?: boolean) {
98+
const isIncludes =
99+
utxo.addresses.filter((value) => this.addrsRaw.includes(value)).length > 0
100+
101+
switch (this.transaction.type) {
102+
case 'export':
103+
return utxo.chainID === avm.getBlockchainID()
104+
case 'pvm_export':
105+
return utxo.chainID === pChain.getBlockchainID()
106+
case 'pvm_import':
107+
case 'import':
108+
if (isInput) return false
109+
return isIncludes
110+
case 'add_validator':
111+
case 'add_delegator':
112+
return !isInput && utxo.stake
113+
case 'operation':
114+
// if no payload it is avax
115+
// check if it is from wallet
116+
if (!utxo.payload && !isIncludes) return false
117+
return true
118+
// default just return original logic
119+
// might need to be changed in the future as
120+
// more tx types are added
121+
case 'base':
122+
default:
123+
return isIncludes
124+
}
125+
126+
return false
127+
}
128+
129+
// what did I gain?
130+
get outValues() {
131+
let addrs: string[] = this.addresses
132+
let addrsRaw = addrs.map((addr) => addr.split('-')[1])
133+
let outs = this.transaction.outputs
134+
let res: TransactionValueDict = {} // asset id -> value dict
135+
136+
// if empty
137+
if (!outs) {
138+
return res
139+
}
140+
141+
outs.forEach((utxoOut) => {
142+
let utxoAddrs = utxoOut.addresses
143+
let assetId = utxoOut.assetID
144+
let amt = utxoOut.amount
145+
146+
const include = this.includeUtxo(utxoOut)
147+
148+
if (include) {
149+
if (res[assetId]) {
150+
res[assetId] += parseInt(amt)
151+
} else {
152+
res[assetId] = parseInt(amt)
153+
}
154+
}
155+
})
156+
157+
return res
158+
}
159+
160+
get valList() {
161+
let ins = this.inValues
162+
let outs = this.outValues
163+
let res = JSON.parse(JSON.stringify(outs))
164+
165+
for (var assetId in ins) {
166+
let inAmount = ins[assetId] || 0
167+
if (res[assetId]) {
168+
res[assetId] -= inAmount
169+
} else {
170+
res[assetId] = -1 * inAmount
171+
}
172+
}
173+
174+
return res
175+
}
176+
177+
get nftGroups() {
178+
let addrs: string[] = this.addresses
179+
let addrsRaw = addrs.map((addr) => addr.split('-')[1])
180+
181+
let ins = this.transaction.inputs || {}
182+
let outs = this.transaction.outputs || {}
183+
let res: { [key in string]: { [key in string]: PayloadBase[] } } = {}
184+
185+
// res = {
186+
// 'asset id': { ['group id']: 'payload' },
187+
// }
188+
189+
const pushPayload = (rawPayload: string, assetID: string, groupID: number) => {
190+
let payload = Buffer.from(rawPayload, 'base64')
191+
payload = Buffer.concat([new Buffer(4).fill(payload.length), payload])
192+
193+
try {
194+
let typeId = payloadtypes.getTypeID(payload)
195+
let pl: Buffer = payloadtypes.getContent(payload)
196+
let payloadbase: PayloadBase = payloadtypes.select(typeId, pl)
197+
198+
if (res[assetID]) {
199+
if (res[assetID][groupID]) {
200+
res[assetID][groupID].push(payloadbase)
201+
} else {
202+
res[assetID] = {
203+
[groupID]: [payloadbase],
204+
}
205+
}
206+
} else {
207+
res[assetID] = {
208+
[groupID]: [payloadbase],
209+
}
210+
}
211+
} catch (e) {
212+
// console.error(e)
213+
}
214+
}
215+
216+
ins.forEach((inputUtxo) => {
217+
const groupID = inputUtxo.output.groupID
218+
const assetID = inputUtxo.output.assetID
219+
220+
if (inputUtxo.output.payload) {
221+
pushPayload(inputUtxo.output.payload, assetID, groupID)
222+
}
223+
})
224+
outs.forEach((utxoOut) => {
225+
let groupID = utxoOut.groupID
226+
let assetID = utxoOut.assetID
227+
228+
if (utxoOut.payload) {
229+
pushPayload(utxoOut.payload, assetID, groupID)
230+
}
231+
})
232+
233+
return res
234+
}
235+
236+
get operationDirection() {
237+
if (this.type !== 'operation') return 'N/A'
238+
239+
let addrs: string[] = this.addresses
240+
let addrsRaw = addrs.map((addr) => addr.split('-')[1])
241+
242+
const isFromWallet = this.transaction.inputs.find((input) => {
243+
return input.output.addresses.find((value) => {
244+
return addrsRaw.includes(value)
245+
})
246+
})
247+
248+
return isFromWallet ? 'Sent' : 'Received'
249+
}
250+
251+
get operationColor() {
252+
return this.operationDirection === 'Received' ? 'success' : 'sent'
253+
}
254+
}
255+
</script>
256+
<style scoped lang="scss">
257+
.nfts {
258+
display: flex;
259+
flex-wrap: wrap;
260+
margin-top: 5px;
261+
justify-content: flex-end;
262+
> div {
263+
margin-left: 5px;
264+
}
265+
}
266+
</style>

0 commit comments

Comments
 (0)