Skip to content

Commit

Permalink
[Issue-3901] feat: skip later confirmation in signing multi-transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
bluezdot committed Dec 16, 2024
1 parent aecd1c0 commit 4310974
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
1 change: 1 addition & 0 deletions packages/extension-base/src/background/KoniTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,7 @@ export interface ConfirmationsQueueItemOptions {
requiredPassword?: boolean;
address?: string;
networkKey?: string;
isPassConfirmation?: boolean;
}

export interface ConfirmationsQueueItem<T> extends ConfirmationsQueueItemOptions, ConfirmationRequestBase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,7 @@ export default class KoniExtension {
}

private async makeCrossChainTransfer (inputData: RequestCrossChainTransfer): Promise<SWTransactionResponse> {
const { destinationNetworkKey, from, originNetworkKey, to, tokenSlug, transferAll, transferBounceable, value } = inputData;

const { destinationNetworkKey, from, isPassConfirmation, originNetworkKey, to, tokenSlug, transferAll, transferBounceable, value } = inputData;
const originTokenInfo = this.#koniState.getAssetBySlug(tokenSlug);
const destinationTokenInfo = this.#koniState.getXcmEqualAssetByChain(destinationNetworkKey, tokenSlug);
const [errors, fromKeyPair] = validateXcmTransferRequest(destinationTokenInfo, from, value);
Expand Down Expand Up @@ -1552,6 +1551,7 @@ export default class KoniExtension {
transferNativeAmount: _isNativeToken(originTokenInfo) ? value : '0',
ignoreWarnings,
isTransferAll: transferAll,
isPassConfirmation,
errors,
additionalValidator: additionalValidator,
eventsHandler: eventsHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ export default class EvmRequestHandler {
this.#requestService.popupOpen();
}

if (options.isPassConfirmation) {
await this.completeConfirmation({ evmSendTransactionRequest: { id, url, isApproved: true, payload: '' } });
}

this.#requestService.updateIconV2();

return promise;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -869,7 +869,7 @@ export default class TransactionService {
return ethers.Transaction.from(txObject).unsignedSerialized as HexString;
}

private async signAndSendEvmTransaction ({ address, chain, id, transaction, url }: SWTransaction): Promise<TransactionEmitter> {
private async signAndSendEvmTransaction ({ address, chain, id, isPassConfirmation, transaction, url }: SWTransaction): Promise<TransactionEmitter> {
const payload = (transaction as EvmSendTransactionRequest);
const evmApi = this.state.chainService.getEvmApi(chain);
const chainInfo = this.state.chainService.getChainInfoByKey(chain);
Expand Down Expand Up @@ -1027,7 +1027,7 @@ export default class TransactionService {
emitter.emit('error', eventData);
});
} else {
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, {})
this.state.requestService.addConfirmation(id, url || EXTENSION_REQUEST_URL, 'evmSendTransactionRequest', payload, { isPassConfirmation })
.then(async ({ isApproved, payload }) => {
if (isApproved) {
let signedTransaction: string | undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface SWTransaction extends ValidateTransactionResponse, Partial<Pick
transaction: SubmittableExtrinsic | TransactionConfig | TonTransactionConfig;
additionalValidator?: (inputTransaction: SWTransactionResponse) => Promise<void>;
eventsHandler?: (eventEmitter: TransactionEmitter) => void;
isPassConfirmation?: boolean
}

export type SWTransactionResult = Omit<SWTransaction, 'transaction' | 'additionalValidator' | 'eventsHandler'>
Expand All @@ -41,6 +42,7 @@ export interface SWTransactionInput extends SwInputBase, Partial<Pick<SWTransact
errors?: SWTransaction['errors'];
edAsWarning?: boolean;
isTransferAll?: boolean;
isPassConfirmation?: boolean
resolveOnDone?: boolean;
skipFeeValidation?: boolean;
}
Expand Down
1 change: 1 addition & 0 deletions packages/extension-base/src/types/transaction/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface RequestBaseTransfer {
value?: string;
transferAll?: boolean;
transferBounceable?: boolean;
isPassConfirmation?: boolean;
}

export interface RequestCheckTransfer extends RequestBaseTransfer {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type ComponentProps = {
interface TransferOptions {
isTransferAll: boolean;
isTransferBounceable: boolean;
isPassConfirmation: boolean;
}

function getTokenItems (
Expand Down Expand Up @@ -458,7 +459,8 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone
to,
value,
transferAll: options.isTransferAll,
transferBounceable: options.isTransferBounceable
transferBounceable: options.isTransferBounceable,
isPassConfirmation: options.isPassConfirmation
});
}

Expand All @@ -482,6 +484,8 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone

// Submit transaction
const doSubmit = useCallback((values: TransferParams, options: TransferOptions) => {
let isPassConfirmation = false;

if (isShowWarningOnSubmit(values)) {
return;
}
Expand Down Expand Up @@ -511,12 +515,21 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone
return await submitData(step + 1);
} else {
const stepType = processState.steps[step].type;
const submitPromise: Promise<SWTransactionResponse> | undefined = stepType === CommonStepType.TOKEN_APPROVAL ? handleBridgeSpendingApproval(values) : handleBasicSubmit(values, options);
let submitPromise: Promise<SWTransactionResponse> | undefined;

if (stepType === CommonStepType.TOKEN_APPROVAL) {
submitPromise = handleBridgeSpendingApproval(values);
} else {
options.isPassConfirmation = isPassConfirmation;
submitPromise = handleBasicSubmit(values, options);
}

const rs = await submitPromise;
const success = onSuccess(isLastStep, needRollback)(rs);

if (success) {
isPassConfirmation = true;

return await submitData(step + 1);
} else {
return false;
Expand All @@ -537,7 +550,7 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone
setLoading(false);
});
}, 300);
}, [handleBasicSubmit, handleBridgeSpendingApproval, isShowWarningOnSubmit, onError, onSuccess, processState]);
}, [handleBasicSubmit, handleBridgeSpendingApproval, isShowWarningOnSubmit, onError, onSuccess, processState.currentStep, processState.steps]);

const onSetMaxTransferable = useCallback((value: boolean) => {
const bnMaxTransfer = new BN(maxTransfer);
Expand All @@ -550,7 +563,8 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone
const onSubmit: FormCallbacks<TransferParams>['onFinish'] = useCallback((values: TransferParams) => {
const options: TransferOptions = {
isTransferAll: isTransferAll,
isTransferBounceable: false
isTransferBounceable: false,
isPassConfirmation: false
};

let checkTransferAll = false;
Expand Down

0 comments on commit 4310974

Please sign in to comment.