Skip to content

Commit

Permalink
Merge pull request #162 from AElfProject/feature/multi-transaction
Browse files Browse the repository at this point in the history
Feature/multi transaction
  • Loading branch information
aelf-lxy authored Oct 8, 2024
2 parents 44d9f7a + 4b11962 commit 8f4814f
Show file tree
Hide file tree
Showing 9 changed files with 1,661 additions and 1,478 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
8 changes: 4 additions & 4 deletions packages/example/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ module.exports = {
},
},
devServer: {
https: {
key: './ssl/server.key',
cert: './ssl/server.cert',
},
// https: {
// key: './ssl/server.key',
// cert: './ssl/server.cert',
// },
proxy: {
'/v1/api': {
target: 'https://did-portkey-test.portkey.finance',
Expand Down
2 changes: 1 addition & 1 deletion packages/example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@portkey-v1/types": "1.5.4-alpha.22",
"@portkey-v1/utils": "1.5.4-alpha.22",
"@portkey/contracts": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.11.0",
"@portkey/request": "^2.7.1-alpha.0",
"@portkey/services": "^2.7.1-alpha.0",
"@portkey/types": "^2.7.1-alpha.0",
Expand Down
57 changes: 55 additions & 2 deletions packages/example/src/components/CallContract.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { CallContractParams, WebLoginState, useCallContract, useCurrentChainSync, useWebLogin } from 'aelf-web-login';
import {
CallContractParams,
IMultiTransactionParams,
WebLoginState,
useCallContract,
useCurrentChainSync,
useWebLogin,
} from 'aelf-web-login';
import { useState } from 'react';
import configJson from '../assets/config.json';
import configTdvwJson from '../assets/config.tdvw.json';
Expand Down Expand Up @@ -67,7 +74,7 @@ export default function CallContract() {
const { wallet, callContract, version } = useWebLogin();
const getAccountTDVW = useGetAccount('tDVW');
const getCurrentChainIdSync = useCurrentChainSync('tDVW');
const { callViewMethod, callSendMethod } = useCallContract();
const { callViewMethod, callSendMethod, sendMultiTransaction } = useCallContract();
const { callViewMethod: callViewMethodAELF, callSendMethod: callSendMethodAELF } = useCallContract({
chainId: 'AELF',
rpcUrl: 'https://aelf-test-node.aelf.io',
Expand All @@ -77,7 +84,53 @@ export default function CallContract() {
rpcUrl: 'https://tdvw-test-node.aelf.io',
});

interface IParmsItem {
caHash: string;
symbol: string;
amount: string;
to: string;
}

const paramsForMuti: IMultiTransactionParams<IParmsItem> = {
multiChainInfo: {
AELF: {
chainUrl: 'https://aelf-test-node.aelf.io/',
contractAddress: '238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb',
},
tDVW: {
chainUrl: 'https://tdvw-test-node.aelf.io/',
contractAddress: '238X6iw1j8YKcHvkDYVtYVbuYk2gJnK8UoNpVCtssynSpVC8hb',
},
},
gatewayUrl: 'https://gateway-test.aelf.io',
chainId: 'tDVW',
params: {
AELF: {
method: 'ManagerTransfer',
params: {
caHash: wallet.portkeyInfo.caInfo.caHash,
symbol: 'ELF',
amount: '10000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk',
},
},
tDVW: {
method: 'ManagerTransfer',
params: {
caHash: wallet.portkeyInfo.caInfo.caHash,
symbol: 'ELF',
amount: '15000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk',
},
},
},
};

const examples = [
useExampleCall('test sendMultiTransaction', async () => {
return await sendMultiTransaction(paramsForMuti);
}),

useExampleCall('call getBalance', async () => {
return callContractWithLog(callViewMethod, {
contractAddress: configJson.multiToken,
Expand Down
12 changes: 6 additions & 6 deletions packages/login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-web-login",
"version": "2.1.6",
"version": "2.1.8",
"main": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
Expand Down Expand Up @@ -49,11 +49,11 @@
},
"dependencies": {
"@aelf-react/core": "^0.1.19",
"@portkey/detect-provider": "2.0.0-alpha.5",
"@portkey/provider-types": "2.0.0-alpha.5",
"@portkey/detect-provider": "^2.3.5-alpha.2",
"@portkey/provider-types": "^2.3.5-alpha.2",
"@types/bn.js": "^5.1.3",
"aelf-bridge": "^0.0.11-alpha.4",
"aelf-sdk": "^3.3.0",
"aelf-sdk": "^3.4.16-alpha.7",
"ahooks": "^3.7.7",
"antd": "^4.24.4",
"bn.js": "^5.2.1",
Expand All @@ -70,7 +70,7 @@
"@portkey-v1/types": "1.5.4-alpha.22",
"@portkey-v1/utils": "1.5.4-alpha.22",
"@portkey/contracts": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.11.0",
"@portkey/request": "^2.7.1-alpha.0",
"@portkey/services": "^2.7.1-alpha.0",
"@portkey/types": "^2.7.1-alpha.0",
Expand All @@ -88,7 +88,7 @@
"@portkey-v1/types": "1.5.4-alpha.22",
"@portkey-v1/utils": "1.5.4-alpha.22",
"@portkey/contracts": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.7.1-alpha.0",
"@portkey/did-ui-react": "^2.11.0",
"@portkey/request": "^2.7.1-alpha.0",
"@portkey/services": "^2.7.1-alpha.0",
"@portkey/types": "^2.7.1-alpha.0",
Expand Down
9 changes: 9 additions & 0 deletions packages/login/src/hooks/useCallContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import {
CallContractHookInterface,
CallContractHookOptions,
CallContractParams,
IMultiTransactionParams,
IMultiTransactionResult,
IPortkeySendAdapterProps,
} from '../types';
import { getConfig } from '../config';
Expand Down Expand Up @@ -233,9 +235,16 @@ export default function useCallContract(options?: CallContractHookOptions): Call
],
);

const sendMultiTransaction = useCallback(async function sendMultiTransactionFunc<T>(
params: IMultiTransactionParams<T>,
): Promise<IMultiTransactionResult> {
return did.sendMultiTransaction(params);
}, []);

return {
contractHookId: `${loginId}_${chainId}_${walletType}}`,
callViewMethod,
callSendMethod,
sendMultiTransaction,
};
}
26 changes: 26 additions & 0 deletions packages/login/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,31 @@ export interface CallContractParams<T> {
};
}

type MultiChainInfo = Partial<{
[x in ChainId]: {
chainUrl: string;
contractAddress: string;
};
}>;

type MultiParams<T> = Partial<{
[x in ChainId]: {
method: string;
params: T;
};
}>;

export interface IMultiTransactionParams<T> {
multiChainInfo: MultiChainInfo;
gatewayUrl: string;
chainId: ChainId;
params: MultiParams<T>;
}

export interface IMultiTransactionResult {
string: string[];
}

export type CallContractFunc<T, R> = (params: CallContractParams<T>) => Promise<R>;

/**
Expand Down Expand Up @@ -171,6 +196,7 @@ export type CallContractHookOptions = {

export type CallContractHookInterface = {
contractHookId: string;
sendMultiTransaction<T>(params: IMultiTransactionParams<T>): Promise<IMultiTransactionResult>;
callViewMethod<T, R>(params: CallContractParams<T>): Promise<R>;
callSendMethod<T, R>(params: CallContractParams<T>, sendOptions: SendOptions | SendOptionsV1 | undefined): Promise<R>;
};
Expand Down
3 changes: 2 additions & 1 deletion packages/login/src/wallets/portkey/usePortkey/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@ export function usePortkey({
setPreparing(true);
setLoading(true);
try {
setApproveModalInTG(false);
setModalOpen(false);
localStorage.setItem(PORTKEY_ORIGIN_CHAIN_ID_KEY, didWalletInfo.chainId);
try {
if (didWalletInfo.chainId !== chainId) {
Expand Down Expand Up @@ -273,7 +275,6 @@ export function usePortkey({
// debugger;
setLoading(false);
setPreparing(false);
setApproveModalInTG(false);
}
},
[appName, chainId, eventEmitter, setLoading, setLoginError, setLoginState, setApproveModalInTG, setWalletType],
Expand Down
Loading

0 comments on commit 8f4814f

Please sign in to comment.