Skip to content

Commit

Permalink
v0.3.0
Browse files Browse the repository at this point in the history
* Enable P/C atomic transactions
  • Loading branch information
kanatliemre authored Dec 2, 2021
1 parent eb3df49 commit ddc905b
Show file tree
Hide file tree
Showing 38 changed files with 1,275 additions and 1,058 deletions.
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const util = require('util')
const crypto = require('crypto')
window.crypto = crypto.webcrypto

window.TextEncoder = util.TextEncoder
window.TextDecoder = util.TextDecoder
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"test": "jest --verbose ./tests"
},
"dependencies": {
"@avalabs/avalanche-wallet-sdk": "0.9.6",
"@avalabs/vue_components": "0.9.0",
"@avalabs/avalanche-wallet-sdk": "0.11.1-beta.2",
"@avalabs/vue_components": "0.10.0",
"@ethereumjs/common": "2.0.0",
"@ethereumjs/tx": "3.0.0",
"@fortawesome/fontawesome-svg-core": "1.2.26",
Expand All @@ -34,7 +34,6 @@
"@obsidiansystems/hw-app-avalanche": "0.2.2",
"@openzeppelin/contracts": "^3.4.2",
"@types/big.js": "4.0.5",
"@types/bn.js": "4.11.6",
"@types/create-hash": "1.2.2",
"@types/crypto-js": "^4.0.2",
"@types/hdkey": "0.7.1",
Expand All @@ -45,13 +44,12 @@
"@types/vue-datetime": "1.0.0",
"@zxing/library": "0.15.2",
"abi-decoder": "2.4.0",
"avalanche": "3.8.1",
"axios": "0.21.1",
"avalanche": "3.10.1",
"axios": "0.21.2",
"big.js": "5.2.2",
"bip32": "2.0.5",
"bip32-path": "^0.4.2",
"bip39": "3.0.2",
"bn.js": "5.1.1",
"body-parser": "1.19.0",
"bootstrap": "4.5.0",
"bootstrap-vue": "2.15.0",
Expand Down
2 changes: 1 addition & 1 deletion src/components/SidePanels/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import BN from 'bn.js'
import { BN } from 'avalanche'
export interface TransactionValueDict {
[address: string]: number
}
Expand Down
9 changes: 3 additions & 6 deletions src/components/misc/AvaxInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@
<script lang="ts">
import 'reflect-metadata'
import { Vue, Component, Prop, Model } from 'vue-property-decorator'
import { Utils, Big } from '@avalabs/avalanche-wallet-sdk'
//@ts-ignore
import { BigNumInput } from '@avalabs/vue_components'
import { BN } from 'avalanche'
import Big from 'big.js'
import { bnToBig } from '../../helpers/helper'
import { priceDict } from '../../store/types'
@Component({
Expand All @@ -45,7 +43,7 @@ import { priceDict } from '../../store/types'
},
})
export default class AvaxInput extends Vue {
@Model('change', { type: Object }) readonly amount!: boolean
@Model('change', { type: Object }) readonly amount!: BN
@Prop({
default: null,
Expand All @@ -67,8 +65,7 @@ export default class AvaxInput extends Vue {
get amountUSD(): Big {
let usdPrice = this.priceDict.usd
// @ts-ignore
let amount = bnToBig(this.amount, 9)
let amount = Utils.bnToBig(this.amount, 9)
let usdBig = amount.times(usdPrice)
return usdBig
}
Expand Down
2 changes: 0 additions & 2 deletions src/components/misc/BalancePopup/BalanceRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import 'reflect-metadata'
import { Vue, Component, Prop } from 'vue-property-decorator'
import AvaAsset from '@/js/AvaAsset'
import * as BN from 'bn.js'
import Big from 'big.js'
@Component
export default class BalanceRow extends Vue {
Expand Down
2 changes: 1 addition & 1 deletion src/components/misc/BigNumInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</template>
<script>
import Big from 'big.js'
import * as BN from 'bn.js'
import { BN } from 'avalanche'
export default {
data() {
Expand Down
2 changes: 1 addition & 1 deletion src/components/misc/CurrencyInputDropdown.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import 'reflect-metadata'
import { Vue, Component, Prop, Emit, Watch } from 'vue-property-decorator'
import BN from 'bn.js'
import { BN } from 'avalanche'
// import Big from 'big.js';
import Dropdown from '@/components/misc/Dropdown.vue'
// import BigNumInput from "@/components/misc/BigNumInput";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
<div class="header">
<Identicon :value="account.baseAddresses.join('')"></Identicon>
<p style="text-align: center">{{ account.name }}</p>
<p class="subtext">This account exists only on this browser.</p>

<p class="err small" style="text-align: center">
Clearing your browser cache will remove this account. Make sure you have your
<b>mnemonic phrase</b>
or
<b>private key</b>
saved.
</p>
</div>

<div class="options" v-if="!subComponent">
Expand Down
7 changes: 1 addition & 6 deletions src/components/modals/ExportAvaxCsvModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ 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'
import { BN } from 'avalanche'
@Component({
components: {
Expand Down
9 changes: 9 additions & 0 deletions src/components/modals/SaveAccount/SaveAccountModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Identicon :value="baseAddresses.join('')"></Identicon>
</div>
<p>{{ $t('keys.save_account.desc') }}</p>

<input
v-model="accountName"
:name="$t('keys.save_account.placeholder_1')"
Expand All @@ -24,6 +25,14 @@
v-model="password_confirm"
/>
<p class="err">{{ err }}</p>
<p class="err small" style="text-align: center">
Clearing your browser cache will remove this account. Make sure you have
your
<b>mnemonic phrase</b>
or
<b>private key</b>
saved.
</p>
<v-btn
class="button_primary"
:disabled="!canSubmit"
Expand Down
79 changes: 53 additions & 26 deletions src/components/wallet/advanced/ChainImport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,44 @@
</div>
<p class="err" v-else-if="err">{{ err }}</p>
<template v-if="!isLoading">
<v-btn block class="button_secondary" depressed @click="atomicImportXFromP" small>
{{ $t('advanced.import.submit_x') }}
<v-btn block class="button_secondary" depressed @click="atomicImportX('P')" small>
Import X (From P)
</v-btn>
<v-btn block class="button_secondary" depressed @click="atomicImportXFromC" small>
{{ $t('advanced.import.submit_c_x') }}
<v-btn block class="button_secondary" depressed @click="atomicImportX('C')" small>
Import X (From C)
</v-btn>
<v-btn block class="button_secondary" depressed @click="atomicImportP" small>
{{ $t('advanced.import.submit_p') }}
<v-btn block class="button_secondary" depressed @click="atomicImportP('X')" small>
Import P (From X)
</v-btn>
<v-btn
block
class="button_secondary"
depressed
@click="atomicImportP('C')"
small
v-if="!isMainnet"
>
Import P (From C)
</v-btn>
<v-btn
v-if="isEVMSupported"
block
class="button_secondary"
depressed
@click="atomicImportC"
@click="atomicImportC('X')"
small
>
{{ $t('advanced.import.submit_c') }}
Import C (from X)
</v-btn>
<v-btn
block
class="button_secondary"
depressed
@click="atomicImportC('P')"
small
v-if="!isMainnet"
>
Import C (from P)
</v-btn>
</template>
<Spinner class="spinner" v-else></Spinner>
Expand All @@ -37,6 +57,14 @@ import { Vue, Component, Prop } from 'vue-property-decorator'
import Spinner from '@/components/misc/Spinner.vue'
import { WalletType } from '@/js/wallets/types'
import { BN } from 'avalanche'
import {
ExportChainsC,
ExportChainsP,
ExportChainsX,
GasHelper,
Utils,
} from '@avalabs/avalanche-wallet-sdk'
@Component({
components: { Spinner },
Expand All @@ -57,50 +85,49 @@ export default class ChainImport extends Vue {
return this.wallet.ethAddress
}
async atomicImportXFromP() {
this.beforeSubmit()
if (!this.wallet) return
// Import from P
try {
let txId = await this.wallet.importToXChain('P')
this.onSuccess(txId)
} catch (e) {
if (this.isSuccess) return
this.onError(e)
}
// TODO: Remove after mainnet support
get isMainnet() {
const activeNet = this.$store.state.Network.selectedNetwork
return activeNet?.networkId === 1
}
async atomicImportXFromC() {
async atomicImportX(sourceChain: ExportChainsX) {
this.beforeSubmit()
if (!this.wallet) return
// // Import from C
try {
let txId = await this.wallet.importToXChain('C')
let txId = await this.wallet.importToXChain(sourceChain)
this.onSuccess(txId)
} catch (e) {
if (this.isSuccess) return
this.onError(e)
}
}
async atomicImportP() {
async atomicImportP(source: ExportChainsP) {
this.beforeSubmit()
if (!this.wallet) return
try {
let txId = await this.wallet.importToPlatformChain()
let txId = await this.wallet.importToPlatformChain(source)
this.onSuccess(txId)
} catch (e) {
this.onError(e)
}
}
async atomicImportC() {
async atomicImportC(source: ExportChainsC) {
this.beforeSubmit()
if (!this.wallet) return
try {
let txId = await this.wallet.importToCChain()
const baseFee = await GasHelper.getBaseFeeRecommended()
const gas = GasHelper.estimateImportGasFeeFromMockTx(
source,
new BN(0),
this.wallet.getEvmAddress()
)
const totFee = baseFee.mul(new BN(gas))
let txId = await this.wallet.importToCChain(source, Utils.avaxCtoX(totFee))
this.onSuccess(txId)
} catch (e) {
this.onError(e)
Expand Down
Loading

0 comments on commit ddc905b

Please sign in to comment.