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

[Issue-3901-v2] Allow signing once for multi-transactions #3923

Open
wants to merge 2 commits into
base: subwallet-dev
Choose a base branch
from
Open
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
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 @@ -232,13 +232,13 @@
externalUrl?: string;
rarity?: string;
description?: string;
properties?: Record<any, any> | null;

Check warning on line 235 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

Check warning on line 235 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

interface NftItemExtraInfo {
type?: _AssetType.ERC721 | _AssetType.PSP34 | RMRK_VER; // for sending
rmrk_ver?: RMRK_VER;
onChainOption?: any; // for sending PSP-34 tokens, should be done better

Check warning on line 241 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
assetHubType?: AssetHubNftType // for sending assetHub nft. There're 2 types nft
}

Expand Down Expand Up @@ -543,7 +543,7 @@
[ExtrinsicType.STAKING_COMPOUNDING]: RequestTuringStakeCompound,
[ExtrinsicType.STAKING_CANCEL_COMPOUNDING]: RequestTuringCancelStakeCompound,
[ExtrinsicType.STAKING_CANCEL_UNSTAKE]: RequestStakeCancelWithdrawal,
[ExtrinsicType.STAKING_POOL_WITHDRAW]: any,

Check warning on line 546 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type

// Yield
[ExtrinsicType.JOIN_YIELD_POOL]: RequestYieldStepSubmit,
Expand Down Expand Up @@ -574,9 +574,9 @@
[ExtrinsicType.CLAIM_BRIDGE]: RequestClaimBridge

[ExtrinsicType.EVM_EXECUTE]: TransactionConfig,
[ExtrinsicType.CROWDLOAN]: any,

Check warning on line 577 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
[ExtrinsicType.SWAP]: SwapTxData
[ExtrinsicType.UNKNOWN]: any

Check warning on line 579 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export enum ExtrinsicStatus {
Expand Down Expand Up @@ -675,7 +675,7 @@
// : T extends ExtrinsicType.MINT_VDOT
// ? Pick<SubmitBifrostLiquidStaking, 'rewardTokenSlug' | 'estimatedAmountReceived'>
// : undefined;
export interface TransactionHistoryItem<ET extends ExtrinsicType = ExtrinsicType.TRANSFER_BALANCE> {

Check warning on line 678 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

'ET' is defined but never used
origin?: 'app' | 'migration' | 'subsquid' | 'subscan', // 'app' or history source
callhash?: string,
signature?: string,
Expand All @@ -700,7 +700,7 @@
tip?: AmountData,
fee?: AmountData,
explorerUrl?: string,
additionalInfo?: any,

Check warning on line 703 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
startBlock?: number,
nonce?: number,
addressPrefix?: number
Expand Down Expand Up @@ -931,12 +931,12 @@
recipientAddress: string,

nftItemName?: string, // Use for confirmation view only
params: Record<string, any>,

Check warning on line 934 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
nftItem: NftItem
}

export interface EvmNftTransaction extends ValidateTransactionResponse {
tx: Record<string, any> | null;

Check warning on line 939 in packages/extension-base/src/background/KoniTypes.ts

View workflow job for this annotation

GitHub Actions / Build Development Preview

Unexpected any. Specify a different type
}

export interface ValidateNetworkResponse {
Expand Down Expand Up @@ -1114,6 +1114,7 @@
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 @@ -181,6 +182,12 @@ const Component = ({ className = '', isAllAccount, targetAccountProxy }: Compone

const [loading, setLoading] = useState(false);
const [isTransferAll, setIsTransferAll] = useState(false);
const [isSignMultiTransaction, setIsSignMultiTransaction] = useState(true);

// todo: remove after test
useEffect(() => {
setIsSignMultiTransaction(false);
}, []);

// use this to reinit AddressInput component
const [addressInputRenderKey, setAddressInputRenderKey] = useState<string>(defaultAddressInputRenderKey);
Expand Down Expand Up @@ -458,7 +465,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 +490,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 +521,23 @@ 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; // todo: also can set at init of any state except first step
submitPromise = handleBasicSubmit(values, options);
}

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

if (success) {
if (isSignMultiTransaction) {
isPassConfirmation = true;
}

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

const onSetMaxTransferable = useCallback((value: boolean) => {
const bnMaxTransfer = new BN(maxTransfer);
Expand All @@ -550,7 +571,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
Loading