Skip to content

Commit

Permalink
feat: add did-ui-react as peerDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
aelf-lxy committed Aug 26, 2024
1 parent b5b4a01 commit 74a7f5a
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 16 deletions.
5 changes: 4 additions & 1 deletion packages/base/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-base",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -43,6 +43,9 @@
"jsdom": "^23.0.1",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.7.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand Down
14 changes: 10 additions & 4 deletions packages/bridge/package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
{
"name": "@aelf-web-login/wallet-adapter-bridge",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
"typings": "dist/esm/index.d.ts",
"exports": {
"import": "./dist/esm/index.js",
"require": "./dist/lib/index.js",
"types": "./dist/esm/index.d.ts"
".": {
"import": "./dist/esm/index.js",
"require": "./dist/lib/index.js",
"types": "./dist/esm/index.d.ts"
},
"./css": "./dist/esm/ui.css"
},
"files": [
"dist",
Expand Down Expand Up @@ -39,6 +42,9 @@
"father": "^4.3.8",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.7.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-react",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
12 changes: 12 additions & 0 deletions packages/starter/src/Demo/ContractDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Button } from 'antd';
import { useConnectWallet } from '@aelf-web-login/wallet-adapter-react';
import configJson from './contract/config.json';
import configTdvwJson from './contract/config.tdvw.json';
import { callViewMethod as callViewMethodOfUtils } from '@aelf-web-login/utils';

function useExampleCall(name: string, func: () => any) {
const [result, setResult] = useState({});
Expand Down Expand Up @@ -55,6 +56,17 @@ const ContractDemo: React.FC = () => {
console.log('ContractDemo init----------');

const examples = [
useExampleCall('call getBalance in callViewMethodOfUtils', async () => {
return callViewMethodOfUtils({
endPoint: 'https://tdvw-test-node.aelf.io',
contractAddress: configTdvwJson.multiToken,
methodName: 'GetBalance',
args: {
symbol: 'ELF',
owner: 'rRZCro3wsAk2mW1s4CvM66wCe8cYgKKBCUFGuBhF6rUtoQNyk',
},
});
}),
useExampleCall('call getBalance', async () => {
return callViewMethod({
contractAddress: configJson.multiToken,
Expand Down
5 changes: 4 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/utils",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -62,6 +62,9 @@
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.7.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand Down
43 changes: 43 additions & 0 deletions packages/utils/src/contract/callViewMethod.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import AElf from 'aelf-sdk';

const CacheViewContracts: { [key: string]: any } = {};
const httpProviders: any = {};
function getAElf(rpc: string) {
if (!httpProviders[rpc]) httpProviders[rpc] = new AElf(new AElf.providers.HttpProvider(rpc));
return httpProviders[rpc];
}
const getContract = async (
endPoint: string,
contractAddress: string,
wallet?: any,
): Promise<any> => {
const key = endPoint + contractAddress;

if (!CacheViewContracts[key]) {
if (!wallet) wallet = AElf.wallet.createNewWallet();
const aelf = getAElf(endPoint);
const contract = await aelf.chain.contractAt(contractAddress, wallet);
CacheViewContracts[endPoint + contractAddress] = contract;
return contract;
}

return CacheViewContracts[key];
};

export async function callViewMethod<T, R>({
endPoint,
contractAddress,
methodName,
args,
wallet,
}: {
endPoint: string;
contractAddress: string;
methodName: string;
args: T;
wallet?: any;
}) {
const contract = await getContract(endPoint, contractAddress, wallet);
const rs = contract[methodName].call(args);
return rs as R;
}
1 change: 1 addition & 0 deletions packages/utils/src/contract/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export * from './useCheckAllowanceAndApprove';
export * from './useGetBalance';
export * from './getRawTransaction';
export * from './getTxResultRetry';
export * from './callViewMethod';
2 changes: 1 addition & 1 deletion packages/wallets/night-elf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-night-elf",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
7 changes: 5 additions & 2 deletions packages/wallets/portkey-aa/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-aa",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand All @@ -27,14 +27,17 @@
"dependencies": {
"@aelf-web-login/wallet-adapter-base": "workspace:*",
"@portkey/contracts": "^2.6.2",
"@portkey/did-ui-react": "^2.7.2",
"@portkey/utils": "^2.4.5"
},
"devDependencies": {
"@portkey/did-ui-react": "^2.7.2",
"@portkey/types": "^2.7.2",
"father": "^4.3.8",
"typescript": "^5.3.3"
},
"peerDependencies": {
"@portkey/did-ui-react": "^2.7.2"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
"access": "public"
Expand Down
2 changes: 1 addition & 1 deletion packages/wallets/portkey-discover/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aelf-web-login/wallet-adapter-portkey-discover",
"version": "0.1.3-alpha.19",
"version": "0.1.3-alpha.21",
"type": "module",
"main": "dist/esm/index.js",
"module": "dist/esm/index.js",
Expand Down
15 changes: 10 additions & 5 deletions packages/wallets/portkey-discover/src/detectProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ export default async function detectDiscoverProvider(): Promise<IPortkeyProvider
const detectProviderModule = detectProvider as any;
detectProviderFunc = detectProviderModule.default;
}
const res = await detectProviderFunc({
timeout: 6000,
providerName: 'Portkey',
});
return res;
try {
const res = await detectProviderFunc({
timeout: 6000,
providerName: 'Portkey',
});
return res;
} catch (e) {
console.log('detectDiscoverProvider error', e);
return null;
}
}

0 comments on commit 74a7f5a

Please sign in to comment.