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: account unification modals #953

Merged
merged 5 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 9 additions & 3 deletions src/components/assets/Account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<span class="text--accent">{{ $n(totalBal) }} USD</span>
</div>
<div class="column__icons">
<div>
<div v-if="isAccountUnification">
<button
type="button"
class="icon--primary icon--account"
Expand Down Expand Up @@ -154,8 +154,13 @@ export default defineComponent({
const isLockdropAccount = ref<boolean>(false);
const isModalLockdropWarning = ref<boolean>(true);
const { toggleEvmWalletSchema } = useConnectWallet();
const { currentAccount, currentAccountName, multisig, showAccountUnificationModal } =
useAccount();
const {
currentAccount,
currentAccountName,
multisig,
showAccountUnificationModal,
isAccountUnification,
} = useAccount();
const { balance, isLoadingBalance } = useBalance(currentAccount);
const { nativeTokenUsd } = usePrice();
const { requestSignature } = useEvmAccount();
Expand Down Expand Up @@ -284,6 +289,7 @@ export default defineComponent({
supportWalletObj,
signatoryIconWallet,
isModalLockdropWarning,
isAccountUnification,
handleModalLockdropWarning,
getShortenAddress,
copyAddress,
Expand Down
8 changes: 1 addition & 7 deletions src/components/header/modals/ModalConnectWallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,9 @@ export default defineComponent({
},
setup(props) {
const store = useStore();
const { currentAccountName, disconnectAccount } = useAccount();
const { currentAccountName, disconnectAccount, isAccountUnification } = useAccount();
const isClosing = ref<boolean>(false);
const { currentNetworkIdx } = useNetworkInfo();
const isAccountUnification = computed<boolean>(() => {
return !!(
(currentNetworkIdx.value === endpointKey.SHIBUYA && currentAccountName) ||
currentNetworkIdx.value === endpointKey.LOCAL
);
});

const closeModal = async (): Promise<void> => {
isClosing.value = true;
Expand Down
13 changes: 12 additions & 1 deletion src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { LOCAL_STORAGE } from 'src/config/localStorage';
import { SupportMultisig } from 'src/config/wallets';
import { Multisig } from 'src/modules/multisig';
import { useStore } from 'src/store';
import { SubstrateAccount, UnifiedAccount } from 'src/store/general/state';
import { SubstrateAccount } from 'src/store/general/state';
import { container } from 'src/v2/common';
import { IEventAggregator, UnifyAccountMessage } from 'src/v2/messaging';
import { IdentityRepository } from 'src/v2/repositories/implementations/IdentityRepository';
import { IAccountUnificationService } from 'src/v2/services';
import { Symbols } from 'src/v2/symbols';
import { computed, ref, watch } from 'vue';
import { useNetworkInfo } from './useNetworkInfo';
import { endpointKey } from 'src/config/chainEndpoints';

export const ETHEREUM_EXTENSION = 'Ethereum Extension';

Expand All @@ -18,6 +20,7 @@ const DELAY = 100;

export const useAccount = () => {
const store = useStore();
const { currentNetworkIdx } = useNetworkInfo();
const multisig = ref<Multisig>();

const isH160Formatted = computed(() => store.getters['general/isH160Formatted']);
Expand All @@ -26,6 +29,13 @@ export const useAccount = () => {
const currentAddress = computed(() => store.getters['general/selectedAddress']);
const unifiedAccount = computed(() => store.getters['general/getUnifiedAccount']);

const isAccountUnification = computed<boolean>(() => {
return !!(
(currentNetworkIdx.value === endpointKey.SHIBUYA && currentAccountName) ||
currentNetworkIdx.value === endpointKey.LOCAL
);
});

// Memo: converts EVM wallet address to SS58 for dApp staking queries
const senderSs58Account = computed<string>(() => {
if (isValidEvmAddress(currentAccount.value)) {
Expand Down Expand Up @@ -191,6 +201,7 @@ export const useAccount = () => {
senderSs58Account,
multisig,
isMultisig,
isAccountUnification,
disconnectAccount,
getSS58Address,
showAccountUnificationModal,
Expand Down
6 changes: 4 additions & 2 deletions src/hooks/wallet/useAccountUnification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
getEvmGas,
getIndividualClaimTxs,
toSS58Address,
wait,
} from '@astar-network/astar-sdk-core';
import { SubmittableExtrinsic } from '@polkadot/api/types';
import { ISubmittableResult } from '@polkadot/types/types';
Expand Down Expand Up @@ -53,7 +54,7 @@ export const useAccountUnification = () => {
const isSendingXc20Tokens = ref<boolean>(false);
const isLoadingDappStaking = ref<boolean>(false);
const accountName = ref<string>('');
const isStaking = ref<boolean>(true);
const isStaking = ref<boolean>(false);
const transferXc20CallData = ref<string>('');
const transferXc20Tokens = ref<TransferXc20Token[]>([]);

Expand Down Expand Up @@ -158,6 +159,8 @@ export const useAccountUnification = () => {
console.error(error);
return null;
} finally {
// Memo: give some time to sync in modals UI
await wait(500);
isLoadingDappStaking.value = false;
}
})
Expand Down Expand Up @@ -328,7 +331,6 @@ export const useAccountUnification = () => {
return unificationService.unifyAccounts(nativeAddress, evmAddress, accountName);
};

watch([currentAccount], setWeb3);
watch([web3], updateEvmProvider);
watch([selectedEvmAddress, dapps, era], checkStakerInfo);
watch([xcmAssets, web3], setTransferXc20CallData);
Expand Down
2 changes: 1 addition & 1 deletion src/i18n/en-US/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default {
haveStakingBalance:
'You have some Staking balance. Those staked token will not be merged to the unified account. Please unstake first.',
unifiedAccountName: 'Unified Account Name',
accountIcon: 'Account icon (EVM NFT can only be selected after creating the account)',
accountIcon: 'Account icon (we are working on adding your own NFT as an account icon)',
balanceTransferred: 'Your balance in the EVM account are going to be transferred.',
readyToUnify:
'Now xcTokens are sent and you are ready to unify both accounts! Please check below before confirm.',
Expand Down
Loading