Skip to content

Commit

Permalink
feat: add sendMultiTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
aelf-lxy committed Sep 29, 2024
1 parent 94b4206 commit 31b27ed
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 108 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
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.10.6-alpha.4",
"@portkey/did-ui-react": "^2.10.6-alpha.8",
"@portkey/request": "^2.7.1-alpha.0",
"@portkey/services": "^2.7.1-alpha.0",
"@portkey/types": "^2.7.1-alpha.0",
Expand Down
50 changes: 48 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,46 @@ export default function CallContract() {
rpcUrl: 'https://tdvw-test-node.aelf.io',
});

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

const paramsForMuti: IMultiTransactionParams<IParmsItem> = {
multiChainInfo: {
AELF: {
chainUrl: 'https://aelf-test-node.aelf.io/',
contractAddress: 'JRmBduh4nXWi1aXgdUsj5gJrzeZb2LxmrAbf7W99faZSvoAaE',
},
tDVW: {
chainUrl: 'https://tdvw-test-node.aelf.io/',
contractAddress: 'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx',
},
},
rpcUrl: 'https://tdvw-test-node.aelf.io/',
gatewayUrl: 'https://gateway-test.aelf.io',
contractAddress: 'ASh2Wt7nSEmYqnGxPPzp4pnVDU4uhj1XW9Se5VeZcX2UDdyjx',
method: 'Transfer',
params: {
AELF: {
symbol: 'ELF',
amount: '100000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk',
},
tDVW: {
symbol: 'ELF',
amount: '150000000',
to: 'GyQX6t18kpwaD9XHXe1ToKxfov8mSeTLE9q9NwUAeTE8tULZk',
},
},
};

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

useExampleCall('call getBalance', async () => {
return callContractWithLog(callViewMethod, {
contractAddress: configJson.multiToken,
Expand Down
8 changes: 4 additions & 4 deletions packages/login/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
},
"dependencies": {
"@aelf-react/core": "^0.1.19",
"@portkey/detect-provider": "^2.3.4",
"@portkey/provider-types": "^2.3.4",
"@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.4.16-alpha.3",
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.10.6-alpha.4",
"@portkey/did-ui-react": "^2.10.6-alpha.8",
"@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.10.6-alpha.4",
"@portkey/did-ui-react": "^2.10.6-alpha.8",
"@portkey/request": "^2.7.1-alpha.0",
"@portkey/services": "^2.7.1-alpha.0",
"@portkey/types": "^2.7.1-alpha.0",
Expand Down
14 changes: 8 additions & 6 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,16 +235,16 @@ export default function useCallContract(options?: CallContractHookOptions): Call
],
);

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

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

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

type MultiParams<T> = Partial<{
[x in ChainId]: T;
}>;
export interface IMultiTransactionParams<T> {
multiChainInfo: MultiChainInfo;
rpcUrl: string;
gatewayUrl: string;
contractAddress: string;
method: string;
params: MultiParams<T>;
}

export interface IMultiTransactionResult {
string: string[];
}

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

/**
Expand Down Expand Up @@ -171,6 +194,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
Loading

0 comments on commit 31b27ed

Please sign in to comment.