Skip to content

Commit

Permalink
feat(ui-ux): update transferdomain to pass only one vin (#4060)
Browse files Browse the repository at this point in the history
* feat(ui-ux): update transferdomain to pass only one vin

* chore(deps): bump walletkit package
  • Loading branch information
lykalabrada authored Oct 16, 2023
1 parent 47e8756 commit 566af72
Show file tree
Hide file tree
Showing 3 changed files with 658 additions and 660 deletions.
36 changes: 34 additions & 2 deletions mobile-app/app/api/transaction/transfer_domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
TransferDomain,
Script,
} from "@defichain/jellyfish-transaction";
import { Prevout } from "@defichain/jellyfish-transaction-builder";
import { fromAddress, Eth } from "@defichain/jellyfish-address";
import { NetworkName } from "@defichain/jellyfish-network";
import { ConvertDirection } from "@screens/enum";
Expand Down Expand Up @@ -105,14 +106,45 @@ export async function transferDomainSigner({
],
};

const { utxos, walletOwnerDvmScript } = await getTransferDomainVin(
account,
networkName,
);

const signed = await builder.account.transferDomain(
transferDomain,
dvmScript,
walletOwnerDvmScript,
utxos,
);

return new CTransactionSegWit(signed);
}

async function getTransferDomainVin(
account: WhaleWalletAccount,
networkName: NetworkName,
): Promise<{ utxos: Prevout[]; walletOwnerDvmScript: Script }> {
const walletOwnerDvmAddress = await account.getAddress();
const walletOwnerDvmScript = fromAddress(walletOwnerDvmAddress, networkName)
?.script as Script;

const utxoList = await account.client.address.listTransactionUnspent(
walletOwnerDvmAddress,
);

const utxos: Prevout[] = [];
if (utxoList.length > 0) {
utxos.push({
txid: utxoList[0].vout.txid,
vout: utxoList[0].vout.n,
value: new BigNumber(utxoList[0].vout.value),
script: walletOwnerDvmScript,
tokenId: utxoList[0].vout.tokenId ?? 0,
});
}

return { utxos, walletOwnerDvmScript };
}

export function transferDomainCrafter({
amount,
convertDirection,
Expand Down
Loading

0 comments on commit 566af72

Please sign in to comment.