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

Clean wallet connections #935

Merged
merged 2 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion src/common/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,14 @@ const routes: Readonly<RouteRecordRaw[]> = [
beforeEnter: checkAcceptedTerms,
},
{
path: '/:type/success/tx/:txId',
path: '/:type/success/tx/:txId/:amount/:confirmations',
name: 'SuccessTx',
component: () => import(/* webpackChunkName: "tx-success" */ '../views/SuccessTx.vue'),
props: (route) => ({
type: route.params.type,
txId: route.params.txId,
amount: route.params.amount,
confirmations: route.params.confirmations,
}),
beforeEnter: [checkFromRoute],
},
Expand Down
48 changes: 15 additions & 33 deletions src/common/views/SuccessTx.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,10 @@
<script lang="ts">
import { mdiContentCopy } from '@mdi/js';
import { defineComponent, computed, PropType } from 'vue';
import { useAction, useGetter, useState } from '@/common/store/helper';
import { useAction, useState } from '@/common/store/helper';
import * as constants from '@/common/store/constants';
import { useRouter } from 'vue-router';
import {
PegInTxState, PegOutTxState, SatoshiBig, TxStatusType, PeginQuote, QuotePegOut2WP,
} from '@/common/types';
import { PegInTxState, SatoshiBig, TxStatusType } from '@/common/types';
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
import { blockConfirmationsToTimeString } from '@/common/utils';

Expand All @@ -67,39 +65,25 @@ export default defineComponent({
type: String,
required: true,
},
amount: {
type: String,
required: true,
},
confirmations: {
type: Number,
required: true,
},
},
setup(props) {
const clearStatus = useAction('status', constants.STATUS_CLEAR);
const router = useRouter();
const pegInTxState = useState<PegInTxState>('pegInTx');
const pegOutTxState = useState<PegOutTxState>('pegOutTx');
const environmentContext = EnvironmentContextProviderService.getEnvironmentContext();
const estimatedBtcToReceive = useGetter<SatoshiBig>('pegOutTx', constants.PEGOUT_TX_GET_ESTIMATED_BTC_TO_RECEIVE);
const peginSelectedQuote = useGetter<PeginQuote>('flyoverPegin', constants.FLYOVER_PEGIN_GET_SELECTED_QUOTE);
const pegoutSelectedQuote = useGetter<QuotePegOut2WP>('flyoverPegout', constants.FLYOVER_PEGOUT_GET_SELECTED_QUOTE);

const amountToReceive = computed(() => {
let amountText;
switch (props.type.toUpperCase()) {
case TxStatusType.PEGIN:
amountText = `${pegInTxState.value.amountToTransfer.toBTCTrimmedString()}
${environmentContext.getBtcTicker()}`;
break;
case TxStatusType.PEGOUT:
amountText = `${estimatedBtcToReceive.value.toBTCTrimmedString()}
${environmentContext.getBtcTicker()}`;
break;
case TxStatusType.FLYOVER_PEGIN:
amountText = `${pegOutTxState.value.amountToTransfer.toRBTCTrimmedString()}
${environmentContext.getBtcTicker()}`;
break;
case TxStatusType.FLYOVER_PEGOUT:
amountText = `${pegOutTxState.value.amountToTransfer.toRBTCTrimmedString()}
${environmentContext.getBtcTicker()}`;
break;
default:
amountText = '';
}
const amount = new SatoshiBig(props.amount, 'satoshi');
const amountText = `${amount.toBTCTrimmedString()}
${environmentContext.getBtcTicker()}`;
return `You will receive ${amountText}`;
});

Expand All @@ -110,11 +94,9 @@ export default defineComponent({
case TxStatusType.PEGOUT:
return '34 hours';
case TxStatusType.FLYOVER_PEGIN:
return `${blockConfirmationsToTimeString(peginSelectedQuote
.value.quote.confirmations ?? 0, 'btc')}`;
return `${blockConfirmationsToTimeString(props.confirmations ?? 0, 'btc')}`;
case TxStatusType.FLYOVER_PEGOUT:
return `${blockConfirmationsToTimeString(pegoutSelectedQuote
.value.quote.depositConfirmations ?? 0, 'btc')}`;
return `${blockConfirmationsToTimeString(props.confirmations ?? 0, 'rsk')}`;
default:
return '';
}
Expand Down
25 changes: 24 additions & 1 deletion src/pegin/components/create/SendBitcoin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@
</template>

<script lang="ts">
import { ref, defineComponent, watch } from 'vue';
import {
ref, defineComponent,
watch, computed,
} from 'vue';
import { useRouter } from 'vue-router';
import PegInForm from '@/pegin/components/create/PegInForm.vue';
import ConfirmTx from '@/pegin/components/create/ConfirmTx.vue';
import * as constants from '@/common/store/constants';
import {
SendBitcoinState, SatoshiBig, BtcWallet, Utxo,
TxStatusType,
PeginQuote,
} from '@/common/types';
import { Machine, getClearPeginTxState } from '@/common/utils';
import { useAction, useGetter, useStateAttribute } from '@/common/store/helper';
Expand Down Expand Up @@ -102,13 +106,23 @@ export default defineComponent({
const stopAskingForBalance = useAction('pegInTx', constants.PEGIN_TX_STOP_ASKING_FOR_BALANCE);
const addNormalizedTx = useAction('pegInTx', constants.PEGIN_TX_ADD_NORMALIZED_TX);
const clearStore = useAction('pegInTx', constants.PEGIN_TX_CLEAR_STATE);
const clearSessionState = useAction('web3Session', constants.WEB3_SESSION_CLEAR_ACCOUNT);
const init = useAction('pegInTx', constants.PEGIN_TX_INIT);
const setBtcWallet = useAction('pegInTx', constants.PEGIN_TX_ADD_BITCOIN_WALLET);
const setCurrenView = useAction('pegInTx', constants.PEGIN_TX_SET_CURRENT_VIEW);
const getChangeAddress = useGetter<string>('pegInTx', constants.PEGIN_TX_GET_CHANGE_ADDRESS);
const selectedUtxoList = useGetter<Utxo[]>('pegInTx', constants.PEGIN_TX_GET_SELECTED_UTXO_LIST);
const selectedFee = useGetter<SatoshiBig>('pegInTx', constants.PEGIN_TX_GET_SAFE_TX_FEE);
const selectedFlyoverQuote = useGetter<PeginQuote>('flyoverPegin', constants.FLYOVER_PEGIN_GET_SELECTED_QUOTE);
const type = useStateAttribute<string>('pegInTx', 'peginType');
const amountToTransfer = useStateAttribute<SatoshiBig>('pegInTx', 'amountToTransfer');

const valueToReceive = computed<SatoshiBig>(() => {
if (type.value === constants.peginType.FLYOVER) {
return selectedFlyoverQuote.value.quote.value;
}
return amountToTransfer.value;
});

async function toConfirmTx({
amountToTransferInSatoshi,
Expand Down Expand Up @@ -147,6 +161,11 @@ export default defineComponent({
addNormalizedTx(getClearPeginTxState().normalizedTx);
}

function clearWallets() {
clearStore();
clearSessionState();
}

function toTrackingId([error, txHash]: string[]) {
if (error !== '') {
txError.value = error;
Expand All @@ -160,9 +179,13 @@ export default defineComponent({
type: type.value === constants.peginType.FLYOVER
? TxStatusType.FLYOVER_PEGIN
: TxStatusType.PEGIN,
amount: valueToReceive.value.toSatoshiString(),
confirmations: type.value === constants.peginType.FLYOVER
? selectedFlyoverQuote.value.quote.confirmations : 0,
},
});
}
clearWallets();
}

function closeErrorDialog() {
Expand Down
73 changes: 49 additions & 24 deletions src/pegout/components/PegoutForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ export default defineComponent({
const selectedOption = ref<string>('');
const quoteDiffPercentage = EnvironmentAccessorService.getEnvironmentVariables()
.flyoverPegoutDiffPercentage;
const clearStore = useAction('pegInTx', constants.PEGOUT_TX_CLEAR_STATE);
const clearSessionState = useAction('web3Session', constants.WEB3_SESSION_CLEAR_ACCOUNT);

const pegoutQuotes = computed(() => {
const quoteList: QuotePegOut2WP[] = [];
Expand Down Expand Up @@ -257,30 +259,36 @@ export default defineComponent({

const sendingPegout = computed(():boolean => pegOutFormState.value.matches(['loading']));

const nativeQuote = computed(() => ({
quote: {
agreementTimestamp: 0,
btcRefundAddress: '',
callFee: new WeiBig(0, 'wei'),
depositAddr: '', // Must be derived
depositConfirmations: 0,
depositDateLimit: 0,
expireBlocks: 0,
expireDate: 0,
gasFee: pegOutTxState.value.calculatedFee,
lbcAddress: '',
liquidityProviderRskAddress: '',
lpBtcAddr: '',
nonce: 0n,
penaltyFee: new WeiBig(0, 'wei'),
productFeeAmount: new WeiBig(pegOutTxState.value.btcEstimatedFee.toBTCString(), 'rbtc'),
rskRefundAddress: account.value ?? '',
transferConfirmations: 0,
transferTime: 0,
value: pegOutTxState.value.amountToTransfer,
},
quoteHash: '',
}));
const nativeQuote = computed(() => {
const btcFee = new WeiBig(pegOutTxState.value.btcEstimatedFee.toBTCString(), 'rbtc');
const estimatedValueToReceive = pegOutTxState.value.amountToTransfer
.minus(pegOutTxState.value.calculatedFee)
.minus(btcFee);
return {
quote: {
agreementTimestamp: 0,
btcRefundAddress: '',
callFee: new WeiBig(0, 'wei'),
depositAddr: '', // Must be derived
depositConfirmations: 0,
depositDateLimit: 0,
expireBlocks: 0,
expireDate: 0,
gasFee: pegOutTxState.value.calculatedFee,
lbcAddress: '',
liquidityProviderRskAddress: '',
lpBtcAddr: '',
nonce: 0n,
penaltyFee: new WeiBig(0, 'wei'),
productFeeAmount: btcFee,
rskRefundAddress: account.value ?? '',
transferConfirmations: 0,
transferTime: 0,
value: estimatedValueToReceive,
},
quoteHash: '',
};
});

const isValid = computed(() => {
if (selectedQuote.value === undefined) return !loadingQuotes.value && isReadyToCreate.value;
Expand All @@ -294,6 +302,19 @@ export default defineComponent({
showTxErrorDialog.value = true;
}

const valueToReceive = computed<WeiBig>(() => {
const quoteHash = selectedQuoteHash.value || '';
if (quoteHash) {
return flyoverPegoutState.value.amountToTransfer;
}
return nativeQuote.value.quote.value;
});

function clearWallets() {
clearStore();
clearSessionState();
}

function changePage(type: string) {
router.push({
name: 'SuccessTx',
Expand All @@ -302,8 +323,12 @@ export default defineComponent({
txId: type === TxStatusType.FLYOVER_PEGOUT.toLowerCase()
? flyoverPegoutState.value.txHash
: pegOutTxState.value.txHash,
amount: SatoshiBig.fromWeiBig(valueToReceive.value).toSatoshiString(),
confirmations: type === TxStatusType.FLYOVER_PEGOUT.toLowerCase()
? selectedQuote.value.quote.depositConfirmations : 0,
},
});
clearWallets();
}

function getLPName(): string {
Expand Down
11 changes: 1 addition & 10 deletions src/pegout/components/PegoutOption.vue
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,7 @@ export default defineComponent({

const estimatedValueToReceive = computed(() => {
if (props.quote) {
if (isFlyover.value) {
return new SatoshiBig(props.quote.quote.value
.toRBTCTrimmedString(), 'btc')
.toBTCTrimmedString();
}

// TODO: SHOW THE AMOUNT WITHOUT FEES AFTER TESTNET GAS GOES DOWN
return new SatoshiBig(props.quote.quote.value
// .minus(props.quote.quote.gasFee)
// .minus(props.quote.quote.productFeeAmount)
return new SatoshiBig((props.quote.quote.value)
.toRBTCTrimmedString(), 'btc')
.toBTCTrimmedString();
}
Expand Down