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

now all Authenticators handle cancel correctly #676

Merged
merged 6 commits into from
Nov 20, 2023
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
11 changes: 9 additions & 2 deletions src/antelope/stores/balances.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,20 +307,27 @@ export const useBalancesStore = defineStore(store_name, {
const funcname = 'transferTokens';
this.trace(funcname, token, to, amount.toString(), memo);
const label = CURRENT_CONTEXT;
let promise = Promise.resolve({} as TransactionResponse);
try {
useFeedbackStore().setLoading(funcname);
const chain = useChainStore().loggedChain;
if (chain.settings.isNative()) {
const chain_settings = chain.settings as NativeChainSettings;
const account = useAccountStore().loggedAccount;
return await this.transferNativeTokens(chain_settings, account, token, to, amount, memo ?? '')
promise = this.transferNativeTokens(chain_settings, account, token, to, amount, memo ?? '')
.then(r => this.subscribeForTransactionReceipt(account, r));
} else {
const chain_settings = chain.settings as EVMChainSettings;
const account = useAccountStore().loggedAccount as EvmAccountModel;
return this.transferEVMTokens(label, chain_settings, account, token, to, amount)
promise = this.transferEVMTokens(label, chain_settings, account, token, to, amount)
.then(r => this.subscribeForTransactionReceipt(account, r as TransactionResponse));
}
promise.catch((error) => {
const trxError = getAntelope().config.transactionError('antelope.evm.error_transfer_failed', error);
getAntelope().config.transactionErrorHandler(trxError, funcname);
throw trxError;
});
return promise;
} catch (error) {
const trxError = getAntelope().config.transactionError('antelope.evm.error_transfer_failed', error);
getAntelope().config.transactionErrorHandler(trxError, funcname);
Expand Down
23 changes: 18 additions & 5 deletions src/antelope/wallets/authenticators/OreIdAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,17 @@ export class OreIdAuth extends EVMAuthenticator {
return this.userChainAccount?.chainAccount as addressString;
}

handleCatchError(error: never): AntelopeError {
this.trace('handleCatchError', error);
console.error(error);
return new AntelopeError('antelope.evm.error_send_transaction', { error });
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleCatchError(error: Error): AntelopeError {
this.trace('handleCatchError', error.message);
if (
error.message === 'Closed by user' ||
error.message === 'sign_transaction_cancelled_by_user'
) {
return new AntelopeError('antelope.evm.error_transaction_canceled');
} else {
return new AntelopeError('antelope.evm.error_send_transaction', { error });
}
}

/**
Expand All @@ -226,7 +233,7 @@ export class OreIdAuth extends EVMAuthenticator {
}

async performOreIdTransaction(from: addressString, json: JSONObject): Promise<EvmTransactionResponse> {

this.trace('performOreIdTransaction', from, json);
const oreIdInstance = oreId as OreId;

// sign a blockchain transaction
Expand All @@ -253,10 +260,16 @@ export class OreIdAuth extends EVMAuthenticator {
this.trace('sendSystemToken', to, amount.toString());
const from = this.getAccountAddress();
const value = amount.toHexString();

// Send the transaction
return this.performOreIdTransaction(from, {
from,
to,
value,
}).then(
(transaction: ethers.providers.TransactionResponse) => transaction,
).catch((error) => {
throw this.handleCatchError(error);
});
}

Expand Down
16 changes: 12 additions & 4 deletions src/antelope/wallets/authenticators/WalletConnectAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,15 +287,23 @@ export class WalletConnectAuth extends EVMAuthenticator {
return web3Provider as ethers.providers.Web3Provider;
}

handleCatchError(error: never): AntelopeError {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
handleCatchError(error: any): AntelopeError {
this.trace('handleCatchError', error);
console.error(error);
return new AntelopeError('antelope.evm.error_send_transaction', { error });
if (error.message.includes('User rejected the')) {
return new AntelopeError('antelope.evm.error_transaction_canceled');
} else {
return new AntelopeError('antelope.evm.error_send_transaction', { error });
}
}

async sendSystemToken(to: string, amount: ethers.BigNumber): Promise<SendTransactionResult> {
this.trace('sendSystemToken', to, amount.toString());
return await sendTransaction(this.sendConfig as PrepareSendTransactionResult);
return sendTransaction(this.sendConfig as PrepareSendTransactionResult).then(
(transaction: SendTransactionResult) => transaction,
).catch((error) => {
throw this.handleCatchError(error);
});
}

async signCustomTransaction(contract: string, abi: EvmABI, parameters: EvmFunctionParam[], value?: BigNumber): Promise<WriteContractResult> {
Expand Down
Loading