Skip to content

Commit

Permalink
[Dependencies] Skip camino-wallet-sdk (#291)
Browse files Browse the repository at this point in the history
* Skip camino-wallet-sdk

* Fallback to false on non-browser node modules

* Modify webpack fallbacks

---------

Co-authored-by: Rafail Kordonias <[email protected]>
  • Loading branch information
aeddaqqa and Rafail Kordonias authored Jul 14, 2023
1 parent c576eec commit 9222208
Show file tree
Hide file tree
Showing 24 changed files with 18,899 additions and 18,618 deletions.
2 changes: 1 addition & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
node_modules/
dist/
tests/
camino-wallet-sdk/
caminojs/
patches
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "camino-wallet-sdk"]
path = camino-wallet-sdk
url = https://github.com/chain4travel/camino-wallet-sdk.git
[submodule "caminojs"]
path = caminojs
url = https://github.com/chain4travel/caminojs
branch = dist
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist
node_modules
camino-wallet-sdk
caminojs
patches
1 change: 0 additions & 1 deletion camino-wallet-sdk
Submodule camino-wallet-sdk deleted from e9156d
1 change: 1 addition & 0 deletions caminojs
Submodule caminojs added at 1a05e4
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
modulePathIgnorePatterns: ['camino-wallet-sdk'],
modulePathIgnorePatterns: ['caminojs'],
moduleFileExtensions: ['js', 'ts', 'json', 'vue'],
transform: {
'.*\\.(vue)$': '@vue/vue2-jest',
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@babel/plugin-transform-runtime": "^7.15.8",
"@babel/preset-env": "^7.15.8",
"@babel/preset-typescript": "^7.18.6",
"@c4tplatform/camino-wallet-sdk": "file:camino-wallet-sdk",
"@c4tplatform/caminojs": "file:caminojs",
"@c4tplatform/vue_components": "^0.2.6",
"@cypress/grep": "^3.1.4",
"@cypress/webpack-preprocessor": "^5.17.0",
Expand Down Expand Up @@ -167,6 +167,7 @@
"vue-virtual-scroll-list": "^2.3.2",
"vuex": "3.1.2",
"web3-eth": "1.3.6",
"web3": "^1.8.2",
"webpack": "^5.57.1",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.3.1",
Expand Down
17 changes: 4 additions & 13 deletions src/components/SidePanels/History/ViewTypes/ImportExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
</div>
</template>
<script lang="ts">
import { bintools } from '@/AVA'
import { chainIdFromAlias, bnToBig } from '@/helpers/helper'
import { Vue, Component, Prop } from 'vue-property-decorator'
import { ITransactionData } from '@/store/modules/history/types'
import { ava } from '@/AVA'
Expand Down Expand Up @@ -52,19 +54,8 @@ export default class ImportExport extends Vue {
// }
get chainAlias() {
let chainId
if (this.isExport) {
chainId = this.fromChainId
} else {
chainId = this.destinationChainId
}
if (chainId === ava.PChain().getBlockchainID()) {
return 'P'
} else if (chainId === ava.XChain().getBlockchainID()) {
return 'X'
}
return chainId
let chainId = this.isExport ? this.fromChainId : this.destinationChainId
return chainIdFromAlias(chainId)
}
get amt(): BN {
Expand Down
22 changes: 10 additions & 12 deletions src/components/wallet/advanced/ChainImport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@
import 'reflect-metadata'
import { Vue, Component } from 'vue-property-decorator'
import { CrossChainsC, CrossChainsP, CrossChainsX } from '@/constants'
import { getBaseFeeRecommended, estimateImportGasFeeFromMockTx } from '@/helpers/gas_helper'
import { avaxCtoX } from '@/helpers/helper'
import Spinner from '@/components/misc/Spinner.vue'
import { WalletType } from '@/js/wallets/types'
import { BN } from '@c4tplatform/caminojs/dist'
import {
ExportChainsC,
ExportChainsP,
ExportChainsX,
GasHelper,
avaxCtoX,
} from '@c4tplatform/camino-wallet-sdk/dist'
import { SignatureError } from '@c4tplatform/caminojs/dist/common'
@Component({
components: { Spinner },
Expand All @@ -71,7 +69,7 @@ export default class ChainImport extends Vue {
return this.wallet.ethAddress
}
async atomicImportX(sourceChain: ExportChainsX) {
async atomicImportX(sourceChain: CrossChainsX) {
this.beforeSubmit()
if (!this.wallet) return
Expand All @@ -85,7 +83,7 @@ export default class ChainImport extends Vue {
}
}
async atomicImportP(source: ExportChainsP) {
async atomicImportP(source: CrossChainsP) {
this.beforeSubmit()
if (!this.wallet) return
try {
Expand All @@ -96,15 +94,15 @@ export default class ChainImport extends Vue {
}
}
async atomicImportC(source: ExportChainsC) {
async atomicImportC(source: CrossChainsC) {
this.beforeSubmit()
if (!this.wallet) return
try {
const utxoSet = await this.wallet.evmGetAtomicUTXOs(source)
const utxos = utxoSet.getAllUTXOs()
const numIns = utxos.length
const baseFee = await GasHelper.getBaseFeeRecommended()
const baseFee = await getBaseFeeRecommended()
if (numIns === 0) {
throw new Error('Nothing to import.')
Expand All @@ -115,7 +113,7 @@ export default class ChainImport extends Vue {
return acc + utxo.getOutput().getAddresses().length
}, 0)
const gas = GasHelper.estimateImportGasFeeFromMockTx(numIns, numSigs)
const gas = estimateImportGasFeeFromMockTx(numIns, numSigs)
const totFee = baseFee.mul(new BN(gas))
let txId = await this.wallet.importToCChain(source, avaxCtoX(totFee))
Expand Down
3 changes: 2 additions & 1 deletion src/components/wallet/advanced/ConsolidateFunds.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import Big from 'big.js'
import MnemonicWallet from '@/js/wallets/MnemonicWallet'
import AvaAsset from '@/js/AvaAsset'
import { ITransaction } from '@/components/wallet/transfer/types'
import { BN, Buffer, ChainIdType } from '@c4tplatform/camino-wallet-sdk'
import { BN, Big, bnToBig } from '@/helpers/helper'
import { ChainIdType } from '@/constants'
const uuidv1 = require('uuid/v1')
@Component({
Expand Down
140 changes: 87 additions & 53 deletions src/components/wallet/earn/ChainTransfer/ChainTransfer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,33 @@ import { Component, Vue, Watch } from 'vue-property-decorator'
import Dropdown from '@/components/misc/Dropdown.vue'
import AvaxInput from '@/components/misc/AvaxInput.vue'
import AvaAsset from '@/js/AvaAsset'
import { BN } from '@c4tplatform/caminojs/dist'
import { ava } from '@/AVA'
import MnemonicWallet from '@/js/wallets/MnemonicWallet'
import Spinner from '@/components/misc/Spinner.vue'
import ChainCard from '@/components/wallet/earn/ChainTransfer/ChainCard.vue'
import TxStateCard from '@/components/wallet/earn/ChainTransfer/TxState.vue'
import { ChainSwapFormData, TxState } from '@/components/wallet/earn/ChainTransfer/types'
import { ChainIdType } from '@/constants'
import { ChainIdType, CrossChainsC, CrossChainsP, CrossChainsX } from '@/constants'
import ChainSwapForm from '@/components/wallet/earn/ChainTransfer/Form.vue'
import { WalletType } from '@/js/wallets/types'
import * as SDK from '@c4tplatform/camino-wallet-sdk/dist'
import {
BN,
Big,
avaxCtoX,
bnToBig,
bnToAvaxX,
bnToBigAvaxX,
bnToBigAvaxC,
bigToBN,
} from '@/helpers/helper'
import {
estimateExportGasFeeFromMockTx,
estimateImportGasFeeFromMockTx,
getBaseFeeRecommended,
} from '@/helpers/gas_helper'
import { SignatureError } from '@c4tplatform/caminojs/dist/common'
const IMPORT_DELAY = 5000 // in ms
const BALANCE_DELAY = 2000 // in ms
Expand Down Expand Up @@ -208,7 +222,7 @@ export default class ChainTransfer extends Vue {
get evmUnlocked(): BN {
let balRaw = this.wallet.ethBalance
return SDK.avaxCtoX(balRaw)
return avaxCtoX(balRaw)
}
get balanceBN(): BN {
Expand All @@ -221,59 +235,59 @@ export default class ChainTransfer extends Vue {
}
}
get balanceBig(): SDK.Big {
return SDK.bnToBig(this.balanceBN, 9)
get balanceBig(): Big {
return bnToBig(this.balanceBN, 9)
}
get formAmtText() {
return SDK.bnToAvaxX(this.formAmt)
return bnToAvaxX(this.formAmt)
}
get fee(): SDK.Big {
get fee(): Big {
return this.exportFee.add(this.importFee)
}
get feeBN(): BN {
return this.importFeeBN.add(this.exportFeeBN)
}
getFee(chain: ChainIdType, isExport: boolean): SDK.Big {
getFee(chain: ChainIdType, isExport: boolean): Big {
if (chain === 'X') {
return SDK.bnToBigAvaxX(ava.XChain().getTxFee())
return bnToBigAvaxX(ava.XChain().getTxFee())
} else if (chain === 'P') {
return SDK.bnToBigAvaxX(ava.PChain().getTxFee())
return bnToBigAvaxX(ava.PChain().getTxFee())
} else {
const fee = isExport
? SDK.GasHelper.estimateExportGasFeeFromMockTx(
this.targetChain as SDK.ExportChainsC,
? estimateExportGasFeeFromMockTx(
this.targetChain as CrossChainsC,
this.amt,
this.wallet.getEvmAddress(),
this.wallet.getCurrentAddressPlatform()
)
: SDK.GasHelper.estimateImportGasFeeFromMockTx(1, 1)
: estimateImportGasFeeFromMockTx(1, 1)
const totFeeWei = this.baseFee.mul(new BN(fee))
return SDK.bnToBigAvaxC(totFeeWei)
return bnToBigAvaxC(totFeeWei)
}
}
get importFee(): SDK.Big {
get importFee(): Big {
return this.getFee(this.targetChain, false)
}
/**
* Returns the import fee in nNative
*/
get importFeeBN(): BN {
return SDK.bigToBN(this.importFee, 9)
return bigToBN(this.importFee, 9)
}
get exportFee(): SDK.Big {
get exportFee(): Big {
return this.getFee(this.sourceChain, true)
}
get exportFeeBN(): BN {
return SDK.bigToBN(this.exportFee, 9)
return bigToBN(this.exportFee, 9)
}
/**
Expand Down Expand Up @@ -315,7 +329,7 @@ export default class ChainTransfer extends Vue {
}
async updateBaseFee() {
this.baseFee = await SDK.GasHelper.getBaseFeeRecommended()
this.baseFee = await getBaseFeeRecommended()
}
async submit() {
Expand All @@ -339,32 +353,54 @@ export default class ChainTransfer extends Vue {
let exportTxId
this.exportState = TxState.started
switch (sourceChain) {
case 'X':
exportTxId = await wallet.exportFromXChain(
amt,
destinationChain as SDK.ExportChainsX,
this.importFeeBN
)
break
case 'P':
exportTxId = await wallet.exportFromPChain(
amt,
destinationChain as SDK.ExportChainsP,
this.importFeeBN
)
break
case 'C':
exportTxId = await wallet.exportFromCChain(
amt,
destinationChain as SDK.ExportChainsC,
this.exportFeeBN
)
break
}
try {
switch (sourceChain) {
case 'X':
exportTxId = await wallet.exportFromXChain(
amt,
destinationChain as CrossChainsX,
this.importFeeBN
)
break
case 'P':
exportTxId = await wallet.exportFromPChain(
amt,
destinationChain as CrossChainsP,
this.importFeeBN
)
break
case 'C':
exportTxId = await wallet.exportFromCChain(
amt,
destinationChain as CrossChainsC,
this.exportFeeBN
)
break
}
this.exportId = exportTxId
this.waitExportStatus(exportTxId)
this.exportId = exportTxId
this.waitExportStatus(exportTxId)
} catch (e: any) {
// if (e instanceof SignatureError) {
// this.$store.dispatch('Notifications/add', {
// type: 'info',
// title: 'Multisignature',
// message: e.message,
// })
// setTimeout(() => {
// this.$store.dispatch('Assets/updateUTXOs')
// this.$store.dispatch('Signavault/updateTransaction').then(() => {
// this.$store.dispatch('History/updateMultisigTransactionHistory')
// })
// }, 3000)
// this.exportState = TxState.success
// this.exportStatus = 'Recorded'
// } else {
// this.exportState = TxState.failed
// this.exportStatus = 'Failed'
// throw e
// }
}
}
// STEP 2
Expand Down Expand Up @@ -424,17 +460,15 @@ export default class ChainTransfer extends Vue {
let importTxId
try {
if (this.targetChain === 'P') {
importTxId = await wallet.importToPlatformChain(
this.sourceChain as SDK.ExportChainsP
)
importTxId = await wallet.importToPlatformChain(this.sourceChain as CrossChainsP)
} else if (this.targetChain === 'X') {
importTxId = await wallet.importToXChain(this.sourceChain as SDK.ExportChainsX)
importTxId = await wallet.importToXChain(this.sourceChain as CrossChainsX)
} else {
//TODO: Import only the exported UTXO
importTxId = await wallet.importToCChain(
this.sourceChain as SDK.ExportChainsC,
this.importFeeBN
this.sourceChain as CrossChainsC,
this.importFeeBN,
undefined,
this.exportId
)
}
} catch (e) {
Expand Down
Loading

0 comments on commit 9222208

Please sign in to comment.