-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add did-ui-react as peerDependencies
- Loading branch information
Showing
11 changed files
with
92 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters