Skip to content

Commit

Permalink
Handle errors (#1072)
Browse files Browse the repository at this point in the history
  • Loading branch information
bobo-k2 authored Dec 5, 2023
1 parent c7f225d commit dc6aae0
Showing 1 changed file with 48 additions and 44 deletions.
92 changes: 48 additions & 44 deletions src/v2/services/implementations/PolkadotWalletService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,56 +99,60 @@ export class PolkadotWalletService extends WalletService implements IWalletServi
resolve(error.message);
}
} else {
const unsub = await extrinsic.signAndSend(
senderAddress,
{
signer: await this.getSigner(senderAddress),
nonce: -1,
tip,
},
(result) => {
try {
isDetectExtensionsAction && this.detectExtensionsAction(false);
isSnap && this.eventAggregator.publish(new BusyMessage(true));
if (result.isCompleted) {
if (!this.isExtrinsicFailed(result.events)) {
if (result.isError) {
this.eventAggregator.publish(
new ExtrinsicStatusMessage({ success: false, message: AlertMsg.ERROR })
);
} else {
const subscanUrl = getSubscanExtrinsic({
subscanBase: subscan,
hash: result.txHash.toHex(),
});
this.eventAggregator.publish(
new ExtrinsicStatusMessage({
success: true,
message: successMessage ?? AlertMsg.SUCCESS,
method: `${extrinsic.method.section}.${extrinsic.method.method}`,
explorerUrl: subscanUrl,
})
);
try {
const unsub = await extrinsic.signAndSend(
senderAddress,
{
signer: await this.getSigner(senderAddress),
nonce: -1,
tip,
},
(result) => {
try {
isDetectExtensionsAction && this.detectExtensionsAction(false);
isSnap && this.eventAggregator.publish(new BusyMessage(true));
if (result.isCompleted) {
if (!this.isExtrinsicFailed(result.events)) {
if (result.isError) {
this.eventAggregator.publish(
new ExtrinsicStatusMessage({ success: false, message: AlertMsg.ERROR })
);
} else {
const subscanUrl = getSubscanExtrinsic({
subscanBase: subscan,
hash: result.txHash.toHex(),
});
this.eventAggregator.publish(
new ExtrinsicStatusMessage({
success: true,
message: successMessage ?? AlertMsg.SUCCESS,
method: `${extrinsic.method.section}.${extrinsic.method.method}`,
explorerUrl: subscanUrl,
})
);
}
}
this.eventAggregator.publish(new BusyMessage(false));
if (finalizedCallback) {
finalizedCallback(result);
}
resolve(extrinsic.hash.toHex());
unsub();
} else {
if (isMobileDevice && !result.isCompleted) {
this.eventAggregator.publish(new BusyMessage(true));
}
}
} catch (error) {
this.eventAggregator.publish(new BusyMessage(false));
if (finalizedCallback) {
finalizedCallback(result);
}
resolve(extrinsic.hash.toHex());
unsub();
} else {
if (isMobileDevice && !result.isCompleted) {
this.eventAggregator.publish(new BusyMessage(true));
}
reject(error as Error);
}
} catch (error) {
this.eventAggregator.publish(new BusyMessage(false));
unsub();
reject(error as Error);
}
}
);
);
} catch (error) {
reject(error as Error);
}
}
});
} catch (e) {
Expand Down

0 comments on commit dc6aae0

Please sign in to comment.