Skip to content

Commit

Permalink
upgrade fleet-sdk to latest version and use ledger specific settings …
Browse files Browse the repository at this point in the history
…on transaction builder
  • Loading branch information
capt-nemo429 committed Apr 9, 2023
1 parent c07b816 commit 0b0299d
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
30 changes: 15 additions & 15 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"dependencies": {
"@download/blockies": "^1.0.3",
"@emurgo/cip4-js": "^1.0.7",
"@fleet-sdk/core": "^0.1.0-alpha.25",
"@fleet-sdk/core": "^0.1.0-alpha.26",
"@ledgerhq/hw-transport-webusb": "^6.27.6",
"@mdi/js": "^7.0.96",
"@oruga-ui/oruga-next": "^0.5.6",
Expand Down
15 changes: 13 additions & 2 deletions src/api/ergo/transaction/txBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ERG_DECIMALS, ERG_TOKEN_ID, MIN_BOX_VALUE } from "@/constants/ergo";
import { ACTIONS } from "@/constants/store";
import store from "@/store";
import { UnsignedTx } from "@/types/connector";
import { AddressState, BigNumberType, FeeSettings, StateAsset } from "@/types/internal";
import { AddressState, BigNumberType, FeeSettings, StateAsset, WalletType } from "@/types/internal";
import { undecimalize } from "@/utils/bigNumbers";
import { bip32Pool } from "@/utils/objectPool";
import {
Expand All @@ -19,6 +19,7 @@ import BigNumber from "bignumber.js";
import { isEmpty } from "lodash";
import { fetchBabelBoxes, getNanoErgsPerTokenRate, selectBestBabelBox } from "../babelFees";
import { fetchBoxes } from "../boxFetcher";
import { CherryPickSelectionStrategy } from "@fleet-sdk/core";

export type TxAssetAmount = {
asset: StateAsset;
Expand All @@ -28,11 +29,13 @@ export type TxAssetAmount = {
export async function createP2PTransaction({
recipientAddress,
assets,
fee
fee,
walletType
}: {
recipientAddress: string;
assets: TxAssetAmount[];
fee: FeeSettings;
walletType: WalletType;
}): Promise<UnsignedTx> {
const [inputs, currentHeight] = await Promise.all([
fetchBoxes(store.state.currentWallet.id),
Expand Down Expand Up @@ -98,6 +101,14 @@ export async function createP2PTransaction({
.payFee(feeNanoErgsAmount.toString())
.sendChangeTo(await safeGetChangeAddress(recipientAddress));

if (walletType === WalletType.Ledger) {
unsignedTx
.configure((settings) => settings.isolateErgOnChange().setMaxTokensPerChangeBox(1))
.configureSelector((selector) => selector.defineStrategy(new CherryPickSelectionStrategy()));
} else {
unsignedTx.configureSelector((selector) => selector.orderBy((input) => input.creationHeight));
}

if (isBabelFeeTransaction && fee.box) {
const nanoErgsChangeAmount = new BigNumber(fee.box.value).minus(
babelTokenUnitsAmount.multipliedBy(getNanoErgsPerTokenRate(fee.box))
Expand Down
4 changes: 3 additions & 1 deletion src/background/ergoApiHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export async function handleGetBoxesRequest(
}

const boxes = await fetchBoxes(session.walletId);
const selector = new BoxSelector(boxes.map((box) => new ErgoUnsignedInput(box)));
const selector = new BoxSelector(boxes.map((box) => new ErgoUnsignedInput(box))).orderBy(
(box) => box.creationHeight
);
let selection!: ErgoUnsignedInput[];

try {
Expand Down
3 changes: 2 additions & 1 deletion src/views/SendView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ export default defineComponent({
const unsignedTx = await createP2PTransaction({
recipientAddress: this.recipient,
assets: this.selected,
fee: this.feeSettings
fee: this.feeSettings,
walletType: this.currentWallet.type
});
const burning = new TxInterpreter(unsignedTx, [], this.$store.state.assetInfo).burning;
Expand Down

0 comments on commit 0b0299d

Please sign in to comment.