Skip to content

Commit

Permalink
devop: set dust values for btc networks
Browse files Browse the repository at this point in the history
  • Loading branch information
kvhnuke committed Sep 15, 2023
1 parent 851749b commit 11559c0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const bitcoinOptions: BitcoinNetworkOptions = {
currencyNameLong: "Test Bitcoin",
icon: require("./icons/tbtc.svg"),
decimals: 8,
dust: 0.00000546,
node: "https://api.blockchain.info/haskoin-store/btc-testnet/",
activityHandler: wrapActivityHandler(haskoinHandler),
basePath: "m/49'/1'/0'/0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const bitcoinOptions: BitcoinNetworkOptions = {
basePath: "m/49'/0'/0'/0",
feeHandler: BTCFeeHandler,
apiType: HaskoinAPI,
dust: 0.00000546,
networkInfo: {
messagePrefix: "\x18Bitcoin Signed Message:\n",
bech32: "bc",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const dogeOptions: BitcoinNetworkOptions = {
node: "https://partners.mewapi.io/nodes/ss/doge",
coingeckoID: "dogecoin",
apiType: SSApi,
dust: 0.01,
activityHandler: wrapActivityHandler(ssHandler),
basePath: "m/44'/3'/0'/0",
feeHandler: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const litecoinOptions: BitcoinNetworkOptions = {
decimals: 8,
node: "https://partners.mewapi.io/nodes/ss/ltc",
coingeckoID: "litecoin",
dust: 0.0001,
apiType: SSApi,
activityHandler: wrapActivityHandler(ssHandler),
basePath: "m/49'/2'/0'/0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface BitcoinNetworkOptions {
coingeckoID?: string;
basePath: string;
networkInfo: BitcoinNetworkInfo;
dust: number;
feeHandler: () => Promise<Record<GasPriceTypes, number>>;
activityHandler: (
network: BaseNetwork,
Expand All @@ -60,6 +61,7 @@ export const getAddress = (pubkey: string, network: BitcoinNetworkInfo) => {
export class BitcoinNetwork extends BaseNetwork {
public assets: BaseToken[] = [];
public networkInfo: BitcoinNetworkInfo;
public dust: number;
private activityHandler: (
network: BaseNetwork,
address: string
Expand All @@ -85,6 +87,7 @@ export class BitcoinNetwork extends BaseNetwork {
this.activityHandler = options.activityHandler;
this.networkInfo = options.networkInfo;
this.feeHandler = options.feeHandler;
this.dust = options.dust;
}

public async getAllTokens(pubkey: string): Promise<BaseToken[]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ const hasEnoughBalance = computed(() => {
if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) {
return false;
}
if (Number(sendAmount.value) < (props.network as BitcoinNetwork).dust) {
return false;
}
return toBN(selectedAsset.value.balance ?? "0").gte(
toBN(toBase(sendAmount.value ?? "0", selectedAsset.value.decimals!)).add(
toBN(
Expand Down Expand Up @@ -211,8 +214,10 @@ onMounted(async () => {
});
const nativeBalanceAfterTransaction = computed(() => {
if (nativeBalance.value && amount.value !== "") {
const rawAmount = toBN(toBase(amount.value, selectedAsset.value.decimals!));
if (nativeBalance.value) {
const rawAmount = toBN(
toBase(sendAmount.value, selectedAsset.value.decimals!)
);
return toBN(nativeBalance.value).sub(rawAmount);
}
return toBN(0);
Expand Down Expand Up @@ -276,6 +281,8 @@ const isInputsValid = computed<boolean>(() => {
if (!isValidDecimals(sendAmount.value, selectedAsset.value.decimals!)) {
return false;
}
if (Number(sendAmount.value) < (props.network as BitcoinNetwork).dust)
return false;
if (new BigNumber(sendAmount.value).gt(assetMaxValue.value)) return false;
return true;
});
Expand Down Expand Up @@ -382,7 +389,7 @@ const sendAction = async () => {
});
});
const balance = toBN(selectedAsset.value.balance!);
const toAmount = toBN(toBase(amount.value, selectedAsset.value.decimals));
const toAmount = toBN(toBase(sendAmount.value, selectedAsset.value.decimals));
const currentFee = toBN(
toBase(
gasCostValues.value[selectedFee.value].nativeValue,
Expand Down

1 comment on commit 11559c0

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.