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

Add btc account select on top bar #867

Merged
merged 3 commits into from
Oct 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
28 changes: 19 additions & 9 deletions src/common/components/layouts/Top.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
<h1 class="text-purple text-h5">PowPeg</h1>
</div>
<div class="d-flex align-center ga-5">
<div class="d-flex align-center ga-2" v-if="truncatedAccount && accountBalance">
<peg-in-account-select v-if="isPeginSelected"/>
<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 All @@ -34,7 +35,10 @@
import { useAction, useGetter, useStateAttribute } from '@/common/store/helper';
import { useRoute, useRouter } from 'vue-router';
import { useTheme } from 'vuetify';
import { mdiContentCopy, mdiLinkOff } from '@mdi/js';
import {
mdiContentCopy, mdiLinkOff,
} from '@mdi/js';
import PegInAccountSelect from '@/pegin/components/create/PegInAccountSelect.vue';
import * as constants from '@/common/store/constants';
import { computed, ref, watch } from 'vue';
import { truncateString } from '@/common/utils';
Expand All @@ -43,18 +47,14 @@ import EnvironmentContextProviderService from '@/common/providers/EnvironmentCon

export default {
name: 'TopBar',
components: {
PegInAccountSelect,
},
setup() {
const router = useRouter();
const route = useRoute();
const themeLight = ref(false);
const vuetifyTheme = useTheme();
function goHome() {
if (route.name !== 'Home') router.push({ name: 'Home' });
}

function getLogoSrc() {
return vuetifyTheme.global.current.value.dark ? require('@/assets/logo-rootstock-white.svg') : require('@/assets/logo-rootstock-black.svg');
}

const account = useGetter<string>('web3Session', constants.SESSION_GET_CHECKSUMMED_ACCOUNT);
const truncatedAccount = computed(() => truncateString(account.value));
Expand All @@ -68,6 +68,7 @@ export default {
});

const clearSession = useAction('web3Session', constants.WEB3_SESSION_CLEAR_ACCOUNT);

function disconnectWallet() {
clearSession();
router.push({ name: 'Home' });
Expand All @@ -77,6 +78,14 @@ export default {
navigator.clipboard.writeText(account.value);
}

function goHome() {
if (route.name !== 'Home') router.push({ name: 'Home' });
}

function getLogoSrc() {
return vuetifyTheme.global.current.value.dark ? require('@/assets/logo-rootstock-white.svg') : require('@/assets/logo-rootstock-black.svg');
}

watch(themeLight, (enabledLight) => {
vuetifyTheme.global.name.value = enabledLight ? 'light' : 'dark';
});
Expand All @@ -93,6 +102,7 @@ export default {
accountBalance,
balance,
environmentContext,
isPeginSelected: computed(() => route.name === 'Create'),
};
},
};
Expand Down
2 changes: 1 addition & 1 deletion src/common/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const routes: Readonly<RouteRecordRaw[]> = [
path: '/pegin',
name: 'PegIn',
component: () => import(/* webpackChunkName: "pegin" */ '../../pegin/views/PegIn.vue'),
beforeEnter: [checkAcceptedTerms, checkRSKConnection],
beforeEnter: [checkAcceptedTerms],
},
{
path: '/pegout',
Expand Down
2 changes: 1 addition & 1 deletion src/common/services/EnkryptService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class EnkryptService extends WalletService {
}

availableAccounts(): BtcAccount[] {
return [constants.BITCOIN_NATIVE_SEGWIT_ADDRESS];
return [BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS];
}

isConnected(): Promise<boolean> {
Expand Down
2 changes: 1 addition & 1 deletion src/common/services/LeatherService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export default class LeatherService extends WalletService {
// eslint-disable-next-line class-methods-use-this
public availableAccounts(): BtcAccount[] {
return [
constants.BITCOIN_NATIVE_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS,
];
}

Expand Down
12 changes: 6 additions & 6 deletions src/common/services/LedgerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export default class LedgerService extends WalletService {
// eslint-disable-next-line class-methods-use-this
public availableAccounts(): BtcAccount[] {
return [
constants.BITCOIN_LEGACY_ADDRESS,
constants.BITCOIN_SEGWIT_ADDRESS,
constants.BITCOIN_NATIVE_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_LEGACY_ADDRESS,
BtcAccount.BITCOIN_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS,
];
}

Expand Down Expand Up @@ -113,14 +113,14 @@ export default class LedgerService extends WalletService {
let addressList: Array<WalletAddress> = [];
const { legacy, segwit, nativeSegwit } = this.addressesToFetch;
addressList = addressList.concat(
this.getDerivedAddresses(legacy.count, legacy.lastIndex, constants.BITCOIN_LEGACY_ADDRESS),
this.getDerivedAddresses(legacy.count, legacy.lastIndex, BtcAccount.BITCOIN_LEGACY_ADDRESS),
).concat(
this.getDerivedAddresses(segwit.count, segwit.lastIndex, constants.BITCOIN_SEGWIT_ADDRESS),
this.getDerivedAddresses(segwit.count, segwit.lastIndex, BtcAccount.BITCOIN_SEGWIT_ADDRESS),
).concat(
this.getDerivedAddresses(
nativeSegwit.count,
nativeSegwit.lastIndex,
constants.BITCOIN_NATIVE_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS,
),
);
return addressList;
Expand Down
6 changes: 3 additions & 3 deletions src/common/services/TrezorService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default class TrezorService extends WalletService {
// eslint-disable-next-line class-methods-use-this
public availableAccounts(): BtcAccount[] {
return [
constants.BITCOIN_LEGACY_ADDRESS,
constants.BITCOIN_SEGWIT_ADDRESS,
constants.BITCOIN_NATIVE_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_LEGACY_ADDRESS,
BtcAccount.BITCOIN_SEGWIT_ADDRESS,
BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS,
];
}

Expand Down
6 changes: 3 additions & 3 deletions src/common/services/WalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,9 @@ export default abstract class WalletService {

protected async setAccountsXpub(accountIdx: number): Promise<void> {
this.extendedPubKeys = {
p2pkh: await this.getXpub(constants.BITCOIN_LEGACY_ADDRESS, accountIdx),
p2sh: await this.getXpub(constants.BITCOIN_SEGWIT_ADDRESS, accountIdx),
p2wpkh: await this.getXpub(constants.BITCOIN_NATIVE_SEGWIT_ADDRESS, accountIdx),
p2pkh: await this.getXpub(BtcAccount.BITCOIN_LEGACY_ADDRESS, accountIdx),
p2sh: await this.getXpub(BtcAccount.BITCOIN_SEGWIT_ADDRESS, accountIdx),
p2wpkh: await this.getXpub(BtcAccount.BITCOIN_NATIVE_SEGWIT_ADDRESS, accountIdx),
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/common/services/XverseService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default class XverseService extends WalletService {
}

availableAccounts(): BtcAccount[] {
return [constants.BITCOIN_SEGWIT_ADDRESS];
return [BtcAccount.BITCOIN_SEGWIT_ADDRESS];
}

name(): Record<'formal_name' | 'short_name' | 'long_name', string> {
Expand Down
8 changes: 5 additions & 3 deletions src/common/types/pegInTx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import SatoshiBig from '@/common/types/SatoshiBig';
import { WalletService } from '@/common/services';
import * as constants from '@/common/store/constants';

export type BtcAccount = 'BITCOIN_LEGACY_ADDRESS' |
'BITCOIN_SEGWIT_ADDRESS' |
'BITCOIN_NATIVE_SEGWIT_ADDRESS';
export enum BtcAccount {
BITCOIN_LEGACY_ADDRESS = 'BITCOIN_LEGACY_ADDRESS',
BITCOIN_SEGWIT_ADDRESS = 'BITCOIN_SEGWIT_ADDRESS',
BITCOIN_NATIVE_SEGWIT_ADDRESS = 'BITCOIN_NATIVE_SEGWIT_ADDRESS'
}

export type BtcWallet = 'WALLET_LEDGER' | 'WALLET_TREZOR' | 'WALLET_LEATHER' | 'WALLET_XVERSE' | 'WALLET_ENKRYPT';

Expand Down
2 changes: 1 addition & 1 deletion src/common/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default {

async function selectConversion(txType: NonNullable<TransactionType>) {
addPeg(txType);
if (!rskAccount.value) {
if (txType === constants.PEG_OUT_TRANSACTION_TYPE && !rskAccount.value) {
try {
await connectWeb3();
} catch (e) {
Expand Down
Loading
Loading