Skip to content

Commit

Permalink
fix: refactor PolkadotWalletService (#1125)
Browse files Browse the repository at this point in the history
* feat: updated checkIsSubstrateConnectInstalled function

* refactor: PolkadotWalletService

* fix: background color
  • Loading branch information
impelcrypto committed Jan 15, 2024
1 parent ded75e4 commit 309adca
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/config/api/polkadot/connectApi.ts
Expand Up @@ -17,7 +17,7 @@ type Provider = WsProvider | ScProvider;

export const checkIsLightClient = (endpoint: string): boolean => endpoint.startsWith('light://');
export const checkIsSubstrateConnectInstalled = (): boolean =>
!!document.getElementById('substrateConnectExtensionAvailable');
!!document.getElementById('substrateConnectExtensionAvailableV2');

const getParachainSpec = (networkIdx: endpointKey): string => {
switch (networkIdx) {
Expand Down
8 changes: 0 additions & 8 deletions src/css/app.scss
Expand Up @@ -17,10 +17,6 @@ body {
overflow: hidden;
}

main {
background: #fff;
}

.screen--phone {
@media (min-width: $sm) {
display: none !important;
Expand Down Expand Up @@ -75,10 +71,6 @@ main {
}

.body--dark {
main {
background: $body-bg-dark;
}

.border--separator {
border-top: 1px solid $border-separator-dark;
}
Expand Down
6 changes: 6 additions & 0 deletions src/layouts/DashboardLayout.vue
Expand Up @@ -84,4 +84,10 @@ export default defineComponent({
padding: 0 40px;
}
}
.body--dark {
.wrapper--dashboard-layout__inner {
background: $body-bg-dark;
}
}
</style>
3 changes: 0 additions & 3 deletions src/pages/StakeManage.vue
Expand Up @@ -21,8 +21,5 @@ export default defineComponent({
<style lang="scss" scoped>
.stake-top {
padding: 0 16px;
@media (min-width: $lg) {
margin-top: 50px;
}
}
</style>
30 changes: 23 additions & 7 deletions src/v2/services/implementations/PolkadotWalletService.ts
Expand Up @@ -46,7 +46,7 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
* Signs given transaction.
* @param extrinsic Transaction to sign.
* @param senderAddress Sender address.
* @param successMessage Mesage to be displayed to user in case of successful tansaction.
* @param successMessage Mesage to be displayed to user in case of successful transaction.
* If not defined, default message will be shown.
* @param tip Transaction tip, If not provided it will be fetched from gas price provider,
*/
Expand All @@ -61,9 +61,7 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
Guard.ThrowIfUndefined('extrinsic', extrinsic);
Guard.ThrowIfUndefined('senderAddress', senderAddress);

const isSnap =
String(localStorage.getItem(LOCAL_STORAGE.SELECTED_WALLET)) === SupportWallet.Snap;
const isDetectExtensionsAction = !isMobileDevice || !isSnap;
const isDetectExtensionsAction = this.checkIsDetectableWallet();

let result: string | null = null;
try {
Expand Down Expand Up @@ -119,8 +117,10 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
},
(result) => {
try {
isDetectExtensionsAction && this.detectExtensionsAction(false);
isSnap && this.eventAggregator.publish(new BusyMessage(true));
isDetectExtensionsAction
? this.detectExtensionsAction(false)
: this.eventAggregator.publish(new BusyMessage(true));

if (result.isCompleted) {
if (!this.isExtrinsicFailed(result.events)) {
if (result.isError) {
Expand Down Expand Up @@ -230,8 +230,24 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
}
}

// Memo: this helper method is used to display the loading animation while sending transactions
private checkIsDetectableWallet(): boolean {
const selectedWallet = String(
localStorage.getItem(LOCAL_STORAGE.SELECTED_WALLET)
) as SupportWallet;

// Memo: Wallets which are not be able to tell the sending transaction status via events
const notDetectableWallet = [
SupportWallet.EnkryptNative,
SupportWallet.Snap,
SupportWallet.Math,
];

const isDetectable = !notDetectableWallet.includes(selectedWallet);
return !isMobileDevice && isDetectable;
}

// Memo: detects status in the wallet extension
// Fixme: doesn't work on MathWallet Mobile
// Ref: https://github.com/polkadot-js/extension/issues/674
// Ref: https://github.com/polkadot-js/extension/blob/297b2af14c68574b24bb8fdeda2208c473eccf43/packages/extension/src/page.ts#L10-L22
private detectExtensionsAction(isMonitorExtension: boolean): void {
Expand Down

0 comments on commit 309adca

Please sign in to comment.