Skip to content

Commit

Permalink
error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Szegoo committed Sep 7, 2023
1 parent 32317ec commit 29e5cec
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 73 deletions.
24 changes: 14 additions & 10 deletions src/pages/transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -249,16 +249,20 @@ const TransferPage = () => {

setTransferring(true);

await NativeTransfer.transfer(
api,
keypair.pairs[0],
selectedAsset,
receiverKeypair.pairs[0].publicKey,
amount * Math.pow(10, selectedAsset.decimals),
activeSigner
);

setTransferring(false);
try {
await NativeTransfer.transfer(
api,
keypair.pairs[0],
selectedAsset,
receiverKeypair.pairs[0].publicKey,
amount * Math.pow(10, selectedAsset.decimals),
activeSigner
);
} catch (e: any) {
toastError(`Transfer failed. Error: ${e.toString()}`);
} finally {
setTransferring(false);
}

return;
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/nativeTransfer/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ class SubstrateAssets {

const account = signer ? sender.address : sender;
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/nativeTransfer/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ class SubstrateNative {

const account = signer ? sender.address : sender;
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
});
return new Promise(async (resolve, reject) => {
try {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
});
} catch (e) {
reject(e);
}
});
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/nativeTransfer/orml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ class SubstrateOrml {

const account = signer ? sender.address : sender;
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/nativeTransfer/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,17 @@ class SubstrateTokens {

const account = signer ? sender.address : sender;
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await transferCall.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}
}
Expand Down
54 changes: 33 additions & 21 deletions src/utils/xcmTransfer/reserveTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ class ReserveTransfer {
const account = signer ? sender.keypair.address : sender.keypair;

// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}

Expand Down Expand Up @@ -80,13 +84,17 @@ class ReserveTransfer {
const account = signer ? sender.keypair.address : sender.keypair;

// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}

Expand Down Expand Up @@ -119,13 +127,17 @@ class ReserveTransfer {
const account = signer ? sender.keypair.address : sender.keypair;

// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await reserveTransfer.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}

Expand Down
18 changes: 11 additions & 7 deletions src/utils/xcmTransfer/teleportTransfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,17 @@ class TeleportTransfer {
const account = signer ? sender.address : sender;

// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await teleport.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await teleport.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
});
} catch (e) {
reject(e);
}
});
}
}
Expand Down
18 changes: 11 additions & 7 deletions src/utils/xcmTransfer/transferAsset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ class TransferAsset {

const account = signer ? sender.address : sender;
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve) => {
const unsub = await xcmExecute.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
return new Promise(async (resolve, reject) => {
try {
const unsub = await xcmExecute.signAndSend(account, (result: any) => {
if (result.status.isFinalized) {
unsub();
resolve();
}
})
} catch (e) {
reject(e);
}
});
}

Expand Down

0 comments on commit 29e5cec

Please sign in to comment.