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

Fix BTC balances #919

Merged
merged 1 commit into from
Nov 26, 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
5 changes: 4 additions & 1 deletion src/common/components/layouts/Top.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h1 class="text-purple text-h5">PowPeg</h1>
</div>
<div class="d-flex align-center ga-5">
<peg-in-account-select v-if="isPeginSelected"/>
<peg-in-account-select v-if="isPeginSelected && walletDataReady"/>
<div class="d-flex align-center ga-2" v-else-if="truncatedAccount && accountBalance">
<v-btn variant="text" size="small" density="compact" rounded="full" :icon="mdiContentCopy"
@click="copyFullAccountAddress"
Expand Down Expand Up @@ -62,6 +62,8 @@ export default {
const balance = useStateAttribute<WeiBig>('web3Session', 'balance');
const environmentContext = EnvironmentContextProviderService.getEnvironmentContext();

const walletDataReady = useStateAttribute<boolean>('pegInTx', 'walletDataReady');

const accountBalance = computed(() => {
const amount = balance.value.toRBTCString().slice(0, 7);
return `${amount} ${environmentContext.getRbtcTicker()}`;
Expand Down Expand Up @@ -103,6 +105,7 @@ export default {
balance,
environmentContext,
isPeginSelected: computed(() => route.name === 'Create'),
walletDataReady,
};
},
};
Expand Down
2 changes: 2 additions & 0 deletions src/common/store/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const PEGIN_TX_ADD_STATUS_SAFE_FEE = 'PEGIN_TX_ADD_STATUS_SAFE_FEE';
export const PEGIN_TX_ADD_STATUS_REFUND_ADDRESS = 'PEGIN_TX_ADD_STATUS_REFUND_ADDRESS';
export const PEGIN_TX_ADD_STATUS_TX_ID = 'PEGIN_TX_ADD_STATUS_TX_ID';
export const PEGIN_TX_ADD_PEGIN_TYPE = 'PEGIN_TX_ADD_PEGIN_TYPE';
export const PEGIN_TX_SET_CURRENT_VIEW = 'PEGIN_TX_SET_CURRENT_VIEW';

// PegOut actions
export const PEGOUT_TX_INIT = 'PEGOUT_TX_INIT';
Expand Down Expand Up @@ -137,6 +138,7 @@ export const PEGIN_TX_SET_STATUS_SAFE_FEE = 'PEGIN_TX_SET_STATUS_SAFE_FEE';
export const PEGIN_TX_SET_STATUS_REFUND_ADDRESS = 'PEGIN_TX_SET_STATUS_REFUND_ADDRESS';
export const PEGIN_TX_SET_STATUS_TX_ID = 'PEGIN_TX_SET_STATUS_TX_ID';
export const PEGIN_TX_SET_PEGIN_TYPE = 'PEGIN_TX_SET_PEGIN_TYPE';
export const PEGIN_TX_SET_VIEW = 'PEGIN_TX_SET_VIEW';

// PegOut mutations
export const PEGOUT_TX_SET_SELECTED_FEE_LEVEL = 'PEGOUT_TX_SET_SELECTED_FEE_LEVEL';
Expand Down
4 changes: 4 additions & 0 deletions src/common/styles/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@

.grecaptcha-badge {
bottom:70px !important;
}

.opacity-100 {
opacity: 1;
}
52 changes: 27 additions & 25 deletions src/pegin/components/create/PegInAccountSelect.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<v-row >
<v-col cols="7" class="d-flex align-center justify-end">
<v-row no-gutters align="center">
<v-col class="d-flex align-center ga-1">
<v-btn v-if="singleAccountType" variant="text" size="small"
density="compact" rounded="full" :icon="mdiContentCopy"
@click="copyFullAccountAddress"
Expand All @@ -14,29 +14,21 @@
>{{ selectedAccountBalance.toBTCString() }} {{ environmentContext.getBtcTicker() }}
</v-tooltip>
</span>
<v-chip v-if="singleAccountType" class="mx-1"
variant="flat" :color="selectedAccountTypeBadge.color" density="compact">
{{ selectedAccountTypeBadge.text }}
</v-chip>
</v-col>
<v-col cols="5" class="pa-0 d-flex align-center">
<div v-if="singleAccountType" class="d-flex align-center justify-end ga-4">
<v-btn
v-bind="props"
variant="plain"
class="h-100"
>
<template #default>
<v-chip v-show="selectedAccountType"
variant="flat" :color="selectedAccountTypeBadge.color" density="compact">
{{ selectedAccountTypeBadge.text }}
</v-chip>
</template>
</v-btn>
</div>
<div v-else class="d-flex align-center justify-end h-100 w-100 pa-0">
<v-menu location="bottom" no-click-animation="true">
<v-col v-if="!singleAccountType">
<div>
<v-menu location="bottom end" no-click-animation="true"
:disabled="loadingBalance || !atPeginForm">
<template v-slot:activator="{ props }">
<v-btn
class="opacity-100"
v-bind="props"
variant="plain"
class="h-100"
size="small"
>
<template #default>
<v-chip v-show="selectedAccountType"
Expand Down Expand Up @@ -70,23 +62,23 @@
</v-list-item>
</v-list>
</v-menu>
<div v-if="loadingBalance" class="d-flex align-center ga-2">
<v-progress-circular size="small" indeterminate color="bw-500"/>
</div>
</div>
</v-col>
<v-progress-circular v-if="loadingBalance" size="small" indeterminate color="bw-500"/>
</v-row>
</template>

<script lang="ts">
import {
ref, defineComponent, computed,
ref, defineComponent, computed, watch,
} from 'vue';
import { mdiBitcoin, mdiContentCopy, mdiChevronDown } from '@mdi/js';
import * as constants from '@/common/store/constants';
import { BtcAccount, WalletAddress } from '@/common/types/pegInTx';
import EnvironmentContextProviderService from '@/common/providers/EnvironmentContextProvider';
import { useAction, useGetter, useStateAttribute } from '@/common/store/helper';
import {
useAction, useGetter, useStateAttribute,
} from '@/common/store/helper';
import { AccountBalance, BtcWallet, SatoshiBig } from '@/common/types';
import { WalletService } from '@/common/services';
import { truncateString } from '@/common/utils';
Expand All @@ -105,6 +97,8 @@ export default defineComponent({
const selectAccount = useAction('pegInTx', constants.PEGIN_TX_SELECT_ACCOUNT_TYPE);
const calculateTxFee = useAction('pegInTx', constants.PEGIN_TX_CALCULATE_TX_FEE);
const selectedAccountBalance = useGetter<SatoshiBig>('pegInTx', constants.PEGIN_TX_GET_SELECTED_BALANCE);
const peginCurrentView = useStateAttribute<string>('pegInTx', 'currentView');
const atPeginForm = computed(() => peginCurrentView.value === 'PegInForm');

function accountChanged(account: BtcAccount) {
selectedAccountType.value = account;
Expand Down Expand Up @@ -167,6 +161,13 @@ export default defineComponent({
const [firstAccount] = walletService.value.availableAccounts();
selectedAccountType.value = firstAccount;
}

watch(loadingBalance, () => {
if (!loadingBalance.value) {
balancesPerAccountType.value.sort((a, b) => Number(b.title) - Number(a.title));
}
});

selectAccount(selectedAccountType.value);
calculateTxFee();

Expand Down Expand Up @@ -194,6 +195,7 @@ export default defineComponent({
mdiChevronDown,
walletInfo,
copyFullAccountAddress,
atPeginForm,
};
},
});
Expand Down
7 changes: 6 additions & 1 deletion src/pegin/components/create/SendBitcoin.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
</template>

<script lang="ts">
import { ref, defineComponent } from 'vue';
import { ref, defineComponent, watch } from 'vue';
import { useRouter } from 'vue-router';
import PegInForm from '@/pegin/components/create/PegInForm.vue';
import ConfirmTx from '@/pegin/components/create/ConfirmTx.vue';
Expand Down Expand Up @@ -104,6 +104,7 @@ export default defineComponent({
const clearStore = useAction('pegInTx', constants.PEGIN_TX_CLEAR_STATE);
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);
Expand Down Expand Up @@ -255,6 +256,10 @@ export default defineComponent({
.then(() => setBtcWallet(wallet));
}

watch(currentComponent, () => {
setCurrenView(currentComponent.value);
}, { immediate: true });

setTxBuilder();

return {
Expand Down
3 changes: 3 additions & 0 deletions src/pegin/store/PeginTx/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,7 @@ export const actions: ActionTree<PegInTxState, RootState> = {
[constants.PEGIN_TX_ADD_PEGIN_TYPE]: ({ commit }, peginType: constants.peginType): void => {
commit(constants.PEGIN_TX_SET_PEGIN_TYPE, peginType);
},
[constants.PEGIN_TX_SET_CURRENT_VIEW]: ({ commit }, view: string): void => {
commit(constants.PEGIN_TX_SET_VIEW, view);
},
};
3 changes: 3 additions & 0 deletions src/pegin/store/PeginTx/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ export const mutations: MutationTree<PegInTxState> = {
[constants.PEGIN_TX_SET_PEGIN_TYPE]: (state, peginType: constants.peginType) => {
state.peginType = peginType;
},
[constants.PEGIN_TX_SET_VIEW]: (state, view: string) => {
state.currentView = view;
},
};
Loading