Skip to content

Commit

Permalink
feat: add example
Browse files Browse the repository at this point in the history
  • Loading branch information
AbigailDeng authored and AbigailDeng committed Oct 31, 2023
1 parent 09794c7 commit 1213ed2
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 25 deletions.
6 changes: 3 additions & 3 deletions packages/example/craco.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ module.exports = {
devServer: {
proxy: {
'/api': {
target: 'https://localtest-applesign2.portkey.finance', //https://localtest-applesign.portkey.finance',
target: 'https://did-portkey-test.portkey.finance',
changeOrigin: true,
secure: true,
},
'/connect': {
target: 'http://192.168.67.51:8080', //'https://auth-portkey-test.portkey.finance',
target: 'https://auth-portkey-test.portkey.finance',
changeOrigin: true,
secure: true,
},
'/AElfIndexer_DApp/PortKeyIndexerCASchema': {
// source: '/AElfIndexer_DApp/:path*',
// target: 'http://192.168.67.172:8083',
target: 'http://192.168.67.51:8083/AElfIndexer_DApp/PortKeyIndexerCASchema/graphql', //'https://dapp-portkey-test.portkey.finance',
target: 'https://dapp-portkey-test.portkey.finance',
changeOrigin: true,
secure: true,
},
Expand Down
14 changes: 13 additions & 1 deletion packages/example/src/components/CallContract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function useExampleCall(name: string, func: () => any) {
}

export default function CallContract() {
const { wallet } = useWebLogin();
const { wallet, callContract } = useWebLogin();
console.log(wallet);
const getAccountTDVW = useGetAccount('tDVW');
const { callViewMethod, callSendMethod } = useCallContract();
Expand Down Expand Up @@ -109,6 +109,18 @@ export default function CallContract() {
});
}),

useExampleCall('Approve in tDVW with useWebLogin', async () => {
return await callContract({
contractAddress: configTdvwJson.multiToken,
methodName: 'Approve',
args: {
symbol: 'ELF',
spender: configTdvwJson.multiToken,
amount: '100000000',
},
});
}),

useExampleCall('Approve in AELF', async () => {
return await callContractWithLog(callSendMethodAELF, {
contractAddress: configJson.multiToken,
Expand Down
33 changes: 15 additions & 18 deletions packages/example/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,20 @@ const CHAIN_ID = 'tDVW';
const NETWORK: string = 'TESTNET';
const IS_MAINNET = NETWORK === 'MAIN';
// portkey ip docs: https://hoopox.feishu.cn/wiki/GjdWwSqc3imGYxkE85bc8KEFnFd
const RPC_SERVER = 'https://localtest-applesign2.portkey.finance/api/app/search/chainsinfoindex';
const RPC_SERVER = 'https://explorer-test.aelf.io/chain';

const graphQLServer = 'http://192.168.67.51:8083/AElfIndexer_DApp/PortKeyIndexerCASchema/graphql';
// !IS_MAINNET
// ? 'https://dapp-portkey-test.portkey.finance'
// : 'https://dapp-portkey.portkey.finance';
const graphQLServer = !IS_MAINNET
? 'https://dapp-portkey-test.portkey.finance'
: 'https://dapp-portkey.portkey.finance';

const portkeyApiServer = 'https://localtest-applesign2.portkey.finance';
// !IS_MAINNET
// ? 'https://did-portkey-test.portkey.finance'
// : 'https://did-portkey.portkey.finance';
const portkeyApiServer = !IS_MAINNET
? 'https://did-portkey-test.portkey.finance'
: 'https://did-portkey.portkey.finance';

// did.config.setConfig
export const connectUrl = 'http://192.168.67.51:8080';
// !IS_MAINNET
// ? 'https://auth-portkey-test.portkey.finance'
// : 'https://auth-portkey.portkey.finance';
export const connectUrl = !IS_MAINNET
? 'https://auth-portkey-test.portkey.finance'
: 'https://auth-portkey.portkey.finance';

let portkeyScanUrl = `${graphQLServer}/Portkey_DID/PortKeyIndexerCASchema/graphql`;
// portkeyScanUrl = '/AElfIndexer_DApp/PortKeyIndexerCASchema/graphql';
Expand All @@ -34,11 +31,11 @@ setGlobalConfig({
defaultRpcUrl: RPC_SERVER,
portkey: {
useLocalStorage: true,
// graphQLUrl: portkeyScanUrl,
// connectUrl: connectUrl,
graphQLUrl: portkeyScanUrl,
connectUrl: connectUrl,
requestDefaults: {
// baseURL: portkeyApiServer,
timeout: 100000,
baseURL: portkeyApiServer,
timeout: 30000,
},
socialLogin: {
Portkey: {
Expand All @@ -60,7 +57,7 @@ setGlobalConfig({
},
tDVV: {
chainId: 'tDVV',
rpcUrl: RPC_SERVER,
rpcUrl: 'http://192.168.66.106:8000',
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion packages/login/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-web-login",
"version": "1.1.4-alpha.4",
"version": "1.1.4-alpha.5",
"main": "dist/esm/index.js",
"types": "dist/types/index.d.ts",
"exports": {
Expand Down
5 changes: 3 additions & 2 deletions packages/login/src/hooks/useCallContract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const sendAdapter = async <T>({
// don't deal with caContract(contractMethod: ApproveMethod)
// if dapp provides signature, we won't awake signature pop-up again
if ((params.contractAddress === chainInfo?.defaultToken.address && params.methodName) === 'Approve') {
const { href, hostname: name } = getUrl();
const { origin, href, hostname: name } = getUrl();
const icon = getFaviconUrl(href);
const originChainId = localStorage.getItem(PORTKEY_ORIGIN_CHAIN_ID_KEY);
// use amount from result of managerApprove not from params
Expand All @@ -84,7 +84,7 @@ export const sendAdapter = async <T>({
...params.args,
dappInfo: {
icon,
href,
href: origin,
name,
},
} as any)) as any;
Expand Down Expand Up @@ -203,6 +203,7 @@ export default function useCallContract(options?: CallContractHookOptions): Call
rpcUrl: chainInfo.endPoint,
});
});
console.log(caContract, didWalletInfo, sendOptions, 'xxxxxx');
const result = await sendAdapter({ caContract, didWalletInfo, params, chainId, sendOptions });
// compatible with aelf-sdk result of contract
if (result?.transactionId) {
Expand Down

0 comments on commit 1213ed2

Please sign in to comment.