Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

solution: unify create tx ui #1344

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = {
},
],
'unused-imports/no-unused-imports': 'warn',
'unused-imports/no-unused-vars': 'warn',
'unused-imports/no-unused-vars': ['warn', { args: 'after-used' }],
},
settings: {
'import/parsers': {
Expand Down
2 changes: 2 additions & 0 deletions .vscode/emerald-wallet.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@
"search.exclude": {
"**/.emerald-dev": true,
"**/.tests": true,
"**/.yarn": true,
"**/app": true,
"**/coverage": true,
"**/lib": true,
"**/node_modules": true,
"**/target": true,
Expand Down
17 changes: 16 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,25 @@
"tasks": [
{
"type": "npm",
"group": "build",
"group": {
"isDefault": true,
"kind": "build"
},
"label": "build:dev",
"script": "build:dev"
},
{
"type": "npm",
"group": "build",
"label": "build:native",
"script": "build:native"
},
{
"type": "npm",
"group": "build",
"label": "clean",
"script": "clean"
},
{
"type": "npm",
"group": "test",
Expand Down
1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@ethersproject/abi": "^5.7.0",
"@ethersproject/bignumber": "^5.7.0",
"bignumber.js": "8.0.2",
"bitcoinjs-lib": "^6.1.0",
"ethereumjs-util": "^7.1.5",
"jsonschema": "^1.4.1"
},
Expand Down
12 changes: 9 additions & 3 deletions packages/core/src/blockchains/blockchains.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BigAmount, CreateAmount, Unit, Units } from '@emeraldpay/bigamount';
import { Satoshi, Wei, WeiAny, WeiEtc } from '@emeraldpay/bigamount-crypto';
import { Satoshi, SatoshiAny, Wei, WeiAny, WeiEtc } from '@emeraldpay/bigamount-crypto';
import { LedgerApp } from '@emeraldpay/emerald-vault-core';
import { Bitcoin } from './Bitcoin';
import { Coin } from './coin';
Expand Down Expand Up @@ -165,7 +165,13 @@ export const WEIS_GOERLI = new Units([
new Unit(18, 'Goerli Ether', 'ETG'),
]);

export const SATOSHIS_TEST = new Units([new Unit(0, 'Test Satoshi', 'tsat'), new Unit(8, 'Test Bitcoin', 'TESTBTC')]);
export const SATOSHIS_TEST = new Units([
new Unit(0, 'Test Satoshi', 'tsat'),
new Unit(1, 'Test Finney', 'tfin'),
new Unit(2, 'Test bit', 'tμBTC'),
new Unit(5, 'Test millibit', 'tmBTC'),
new Unit(8, 'Test Bitcoin', 'TestBTC'),
]);

export function amountFactory(code: BlockchainCode): CreateAmount<BigAmount> {
switch (code) {
Expand All @@ -178,7 +184,7 @@ export function amountFactory(code: BlockchainCode): CreateAmount<BigAmount> {
case BlockchainCode.Goerli:
return (value) => new WeiAny(value, WEIS_GOERLI);
case BlockchainCode.TestBTC:
return (value) => new BigAmount(value, SATOSHIS_TEST);
return (value) => new SatoshiAny(value, SATOSHIS_TEST);
default:
throw new Error(`Unsupported blockchain: ${code}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class CreateBitcoinCancelTx extends CreateBitcoinTx {

return [
{
address: this.changeAddress,
address: this.changeAddress ?? '',
amount: totalChange.number.toNumber(),
entryId: this.entryId,
},
Expand All @@ -33,6 +33,10 @@ export class CreateBitcoinCancelTx extends CreateBitcoinTx {
return ValidationResult.INSUFFICIENT_FEE_PRICE;
}

if (this.changeAddress == null) {
return ValidationResult.NO_CHANGE_ADDRESS;
}

if (this.tx.from.length === 0) {
return ValidationResult.NO_FROM;
}
Expand Down
Loading
Loading