Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandermake committed Oct 30, 2024
2 parents 087ec7f + 318a900 commit 976c2ab
Show file tree
Hide file tree
Showing 21 changed files with 3,600 additions and 2,081 deletions.
5,292 changes: 3,315 additions & 1,977 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,30 @@
"@cosmjs/stargate": "0.32.4",
"@cosmjs/tendermint-rpc": "0.32.4",
"@headlessui/vue": "^1.7.19",
"@heroicons/vue": "^2.1.1",
"@heroicons/vue": "^2.1.5",
"@injectivelabs/sdk-ts": "^1.14.13",
"@keplr-wallet/crypto": "0.12.108",
"@keplr-wallet/types": "0.12.108",
"@keplr-wallet/unit": "0.12.108",
"@ledgerhq/hw-app-cosmos": "^6.30.0",
"@ledgerhq/hw-transport-web-ble": "^6.29.0",
"@ledgerhq/hw-transport-webhid": "^6.29.0",
"@ledgerhq/hw-transport-webusb": "^6.29.0",
"@keplr-wallet/crypto": "0.12.144",
"@keplr-wallet/types": "0.12.144",
"@keplr-wallet/unit": "0.12.144",
"@ledgerhq/hw-app-cosmos": "^6.30.4",
"@ledgerhq/hw-transport-web-ble": "^6.29.4",
"@ledgerhq/hw-transport-webhid": "^6.29.4",
"@ledgerhq/hw-transport-webusb": "^6.29.4",
"@ledgerhq/logs": "^6.12.0",
"@nolus/nolusjs": "^2.4.16",
"@skip-go/client": "^0.8.0",
"chart.js": "^4.4.1",
"@nolus/nolusjs": "^2.4.17",
"@skip-go/client": "^0.10.3",
"chart.js": "^4.4.5",
"chartjs-adapter-date-fns": "^3.0.0",
"cosmjs-types": "^0.9.0",
"cosmjs-types-legacy": "npm:[email protected]",
"date-fns": "^3.3.1",
"ethers": "^6.13.0",
"marked": "^13.0.2",
"pinia": "^2.2.1",
"vue": "^3.4.31",
"ethers": "^6.13.4",
"marked": "^14.1.3",
"pinia": "^2.2.4",
"vue": "^3.5.12",
"vue-chartjs": "^5.3.0",
"vue-i18n": "9.13.1",
"vue-router": "^4.4.0",
"vue-i18n": "10.0.4",
"vue-router": "^4.4.5",
"web-components": "github:nolus-protocol/web-components#v1.6.1"
},
"devDependencies": {
Expand Down
60 changes: 50 additions & 10 deletions src/common/components/modals/long/LongFormComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ import { Button, Tooltip } from "web-components";
import type { LeaseComponentProps } from "./types/LeaseComponentProps";
import type { ExternalCurrency } from "@/common/types";

import { computed, nextTick, onMounted, type PropType, ref, watch } from "vue";
import { computed, nextTick, onMounted, onUnmounted, type PropType, ref, watch } from "vue";
import { CurrencyUtils } from "@nolus/nolusjs";
import { useWalletStore } from "@/common/stores/wallet";
import { Dec } from "@keplr-wallet/unit";
import { useOracleStore } from "@/common/stores/oracle";
import { AppUtils, AssetUtils, LeaseUtils } from "@/common/utils";
import { AssetUtils, getMicroAmount, LeaseUtils, SkipRouter } from "@/common/utils";
import { useApplicationStore } from "@/common/stores/application";
import { CurrencyMapping } from "@/config/currencies";
import { CurrencyDemapping, CurrencyMapping } from "@/config/currencies";

import {
Contracts,
Expand All @@ -155,6 +155,9 @@ const app = useApplicationStore();
const oracle = useOracleStore();
const swapFee = ref(0);

const timeOut = 200;
let time: NodeJS.Timeout;

onMounted(() => {
if (props.modelValue.dialogSelectedCurrency) {
const [ticker, protocol] = props.modelValue.dialogSelectedCurrency.split("@");
Expand All @@ -169,8 +172,10 @@ onMounted(() => {
props.modelValue.selectedCurrency = app.currenciesData![props.modelValue.dialogSelectedCurrency!];
});
}
});

setSwapFee();
onUnmounted(() => {
clearTimeout(time);
});

const props = defineProps({
Expand All @@ -194,15 +199,51 @@ watch(
);

watch(
() => props.modelValue.selectedCurrency,
() => [props.modelValue.leaseApply],
(value) => {
setSwapFee();
}
);

const setSwapFee = async () => {
const asset = props.modelValue.selectedCurrency;
swapFee.value = (await AppUtils.getSwapFee())[asset.ticker] ?? 0;
clearTimeout(time);
if (props.modelValue.downPaymentErrorMsg.length == 0 && Number(props.modelValue.downPayment) > 0) {
time = setTimeout(async () => {
const currency = props.modelValue.selectedDownPaymentCurrency;
const lease = props.modelValue.selectedCurrency;
const [_, p] = lease.key.split("@");

const microAmount = CurrencyUtils.convertDenomToMinimalDenom(
props.modelValue.downPayment,
props.modelValue.selectedDownPaymentCurrency.ibcData,
props.modelValue.selectedDownPaymentCurrency.decimal_digits
).amount.toString();

const lpn = AssetUtils.getLpnByProtocol(p);
let amountIn = 0;
let amountOut = 0;
const [r, r2] = await Promise.all([
SkipRouter.getRoute(currency.ibcData, lease.ibcData, microAmount).then((data) => {
amountIn += Number(data.usdAmountIn);
amountOut += Number(data.usdAmountOut);

return Number(data?.swapPriceImpactPercent ?? 0);
}),
SkipRouter.getRoute(lpn.ibcData, lease.ibcData, props.modelValue.leaseApply!.borrow.amount).then((data) => {
amountIn += Number(data.usdAmountIn);
amountOut += Number(data.usdAmountOut);

return Number(data?.swapPriceImpactPercent ?? 0);
})
]);
const out_a = Math.max(amountOut, amountIn);
const in_a = Math.min(amountOut, amountIn);

const diff = out_a - in_a;
const fee = diff / in_a;
swapFee.value = fee;
}, timeOut);
}
};

const totalBalances = computed(() => {
Expand Down Expand Up @@ -275,15 +316,14 @@ const coinList = computed(() => {
if (CurrencyMapping[ticker as keyof typeof CurrencyMapping]) {
ticker = CurrencyMapping[ticker as keyof typeof CurrencyMapping]?.ticker;
}

if (!app.lease?.[protocol].includes(ticker)) {
if (!app.lease?.[protocol].includes(CurrencyDemapping[ticker]?.ticker ?? ticker)) {
return false;
}

if (IGNORE_LEASE_ASSETS.includes(ticker) || IGNORE_LEASE_ASSETS.includes(`${ticker}@${protocol}`)) {
return false;
}
return app.leasesCurrencies.includes(ticker);
return app.leasesCurrencies.includes(CurrencyDemapping[ticker]?.ticker ?? ticker);
})
.map((item) => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import type { AssetBalance } from "@/common/stores/wallet/types";
import MarketCloseFormComponent from "./MarketCloseFormComponent.vue";
import ConfirmComponent from "../templates/ConfirmComponent.vue";
import { computed, inject, ref, watch, type PropType, onMounted } from "vue";
import { computed, inject, ref, watch, type PropType, onMounted, onUnmounted } from "vue";
import { Lease } from "@nolus/nolusjs/build/contracts";
import { CurrencyUtils, NolusClient, NolusWallet } from "@nolus/nolusjs";
import { Dec, Int } from "@keplr-wallet/unit";
import { CONFIRM_STEP } from "@/common/types";
import { TxType } from "@/common/types";
import { AssetUtils, Logger, getMicroAmount, walletOperation } from "@/common/utils";
import { AssetUtils, Logger, SkipRouter, getMicroAmount, walletOperation } from "@/common/utils";
import { useWalletStore } from "@/common/stores/wallet";
import { storeToRefs } from "pinia";
import { useI18n } from "vue-i18n";
Expand All @@ -60,6 +60,8 @@ const walletRef = storeToRefs(walletStore);
const oracle = useOracleStore();
const i18n = useI18n();
const app = useApplicationStore();
const timeOut = 200;
let time: NodeJS.Timeout;
const onModalClose = inject("onModalClose", () => {});
const getLeases = inject("getLeases", () => {});
Expand All @@ -72,6 +74,10 @@ const props = defineProps({
}
});
onUnmounted(() => {
clearTimeout(time);
});
const closeModal = onModalClose;
const { config } = useLeaseConfig(props.leaseData?.protocol as string, (error: Error | any) => {});
Expand All @@ -93,8 +99,6 @@ const balances = computed(() => {
}
return assets.filter((item) => item.key == `${ticker}@${props.leaseData?.protocol}`);
return assets;
});
const state = ref({
Expand All @@ -111,10 +115,6 @@ const state = ref({
onNextClick: () => onNextClick()
} as MarketCloseComponentProps);
onMounted(async () => {
setSwapFee();
});
watch(
() => state.value.selectedCurrency,
() => {
Expand All @@ -126,13 +126,49 @@ watch(
() => [...state.value.amount],
(currentValue, oldValue) => {
isAmountValid();
setSwapFee();
}
);
async function setSwapFee() {
const asset = state.value.selectedCurrency;
state.value.swapFee = (await AppUtils.getSwapFee())[asset.ticker] ?? 0;
}
// async function setSwapFee() {
// const asset = state.value.selectedCurrency;
// state.value.swapFee = (await AppUtils.getSwapFee())[asset.ticker] ?? 0;
// }
const setSwapFee = async () => {
clearTimeout(time);
if (isAmountValid()) {
time = setTimeout(async () => {
const lease = state.value.selectedCurrency;
const currecy =
app.currenciesData![`${props.leaseData?.leaseData?.leasePositionTicker}@${props.leaseData?.protocol}`];
const lpn = AssetUtils.getLpnByProtocol(props.leaseData?.protocol as string);
const microAmount = CurrencyUtils.convertDenomToMinimalDenom(
state.value.amount,
lease.balance.ibcData,
lease.decimal_digits
).amount.toString();
let amountIn = 0;
let amountOut = 0;
const [r] = await Promise.all([
SkipRouter.getRoute(currecy.ibcData, lpn.ibcData, microAmount).then((data) => {
amountIn += Number(data.usdAmountIn);
amountOut += Number(data.usdAmountOut);
return Number(data?.swapPriceImpactPercent ?? 0);
})
]);
const out_a = Math.max(amountOut, amountIn);
const in_a = Math.min(amountOut, amountIn);
const diff = out_a - in_a;
const fee = diff / in_a;
state.value.swapFee = fee;
}, timeOut);
}
};
async function onNextClick() {
if (isAmountValid()) {
Expand Down
53 changes: 45 additions & 8 deletions src/common/components/modals/repay/RepayMainComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ import type { AssetBalance } from "@/common/stores/wallet/types";
import RepayFormComponent from "./RepayFormComponent.vue";
import ConfirmComponent from "@/common/components/modals/templates/ConfirmComponent.vue";
import { computed, inject, ref, watch, type PropType, onMounted } from "vue";
import { computed, inject, ref, watch, type PropType, onMounted, onUnmounted } from "vue";
import { Lease } from "@nolus/nolusjs/build/contracts";
import { CurrencyUtils, NolusClient, NolusWallet } from "@nolus/nolusjs";
import { Dec, Int } from "@keplr-wallet/unit";
import { CONFIRM_STEP } from "@/common/types";
import { TxType } from "@/common/types";
import { AssetUtils, LeaseUtils, getMicroAmount, walletOperation } from "@/common/utils";
import { AssetUtils, LeaseUtils, SkipRouter, getMicroAmount, walletOperation } from "@/common/utils";
import { useWalletStore } from "@/common/stores/wallet";
import { storeToRefs } from "pinia";
import { useI18n } from "vue-i18n";
Expand Down Expand Up @@ -70,6 +70,8 @@ const getLeases = inject("getLeases", () => {});
const step = ref(CONFIRM_STEP.CONFIRM);
const showConfirmScreen = ref(false);
const timeOut = 200;
let time: NodeJS.Timeout;
const closeModal = onModalClose;
Expand Down Expand Up @@ -128,8 +130,8 @@ const state = ref({
onNextClick: () => onNextClick()
} as RepayComponentProps);
onMounted(async () => {
setSwapFee();
onUnmounted(() => {
clearTimeout(time);
});
watch(
Expand All @@ -143,14 +145,49 @@ watch(
watch(
() => [...state.value.amount],
(currentValue, oldValue) => {
setSwapFee();
isAmountValid();
}
);
async function setSwapFee() {
const asset = state.value.selectedCurrency;
state.value.swapFee = (await AppUtils.getSwapFee())[asset.ticker] ?? 0;
}
// async function setSwapFee() {
// const asset = state.value.selectedCurrency;
// state.value.swapFee = (await AppUtils.getSwapFee())[asset.ticker] ?? 0;
// }
const setSwapFee = async () => {
clearTimeout(time);
if (isAmountValid()) {
time = setTimeout(async () => {
const lease = state.value.selectedCurrency;
const currecy =
app.currenciesData![`${props.leaseData?.leaseData?.leasePositionTicker}@${props.leaseData?.protocol}`];
const microAmount = CurrencyUtils.convertDenomToMinimalDenom(
state.value.amount,
lease.balance.ibcData,
lease.decimal_digits
).amount.toString();
let amountIn = 0;
let amountOut = 0;
const [r] = await Promise.all([
SkipRouter.getRoute(lease.ibcData, currecy.ibcData, microAmount).then((data) => {
amountIn += Number(data.usdAmountIn);
amountOut += Number(data.usdAmountOut);
return Number(data?.swapPriceImpactPercent ?? 0);
})
]);
const out_a = Math.max(amountOut, amountIn);
const in_a = Math.min(amountOut, amountIn);
const diff = out_a - in_a;
const fee = diff / in_a;
state.value.swapFee = fee;
}, timeOut);
}
};
async function onNextClick() {
if (isAmountValid()) {
Expand Down
Loading

0 comments on commit 976c2ab

Please sign in to comment.