Commit 47f89d7a authored by 郑磊's avatar 郑磊

增加web3调用方法

parent baac2e4d
import { callNativeApi } from './native-api-base' import { callNativeApi, callNativeAsyncApi } from './native-api-base'
/** /**
* 关闭当前页面 * 关闭当前页面
...@@ -29,3 +29,99 @@ export function getBottomSafeHeight(): Promise<number> { ...@@ -29,3 +29,99 @@ export function getBottomSafeHeight(): Promise<number> {
callNativeApi('getBottomSafeHeight', (value: any) => resolve(parseFloat(value))), callNativeApi('getBottomSafeHeight', (value: any) => resolve(parseFloat(value))),
) )
} }
/**
* web3账户
*/
export interface Web3Account {
/**
* 账户索引
*/
index: number
/**
* 钱包地址
*/
address: string
/**
* 持有代币数据
*/
tokens: Web3Token[]
}
/**
* web3代币信息
*/
export interface Web3Token {
/**
* 代币合约地址
*/
token: string
/**
* 代币符号
*/
symbol: string
/**
* 代币余额
*/
balance: string
}
/**
* 获取钱包数据
*/
export function web3GetWallet(chain_id: number): Promise<Web3Account[]> {
console.log('调用框架方法', 'web3GetWallet', chain_id)
return new Promise<Web3Account[]>((resolve) =>
callNativeAsyncApi('web3GetWallet', { chain_id }, resolve),
)
}
/**
* 执行web3合约需要的参数
*/
export interface Web3ExecContractParams {
/**
* 链id
*/
chain_id: number
/**
* 代币合约地址
*/
token: string
/**
* 执行合约需要的代币余额
*/
amount: string
/**
* 账户索引(0表示主账户)
*/
index: number
/**
* 执行合约时需要传递的data参数
*/
data: string
}
/**
* 执行web3合约的结果
*/
export interface Web3ExecContractResult {
/**
* 执行结果,空字符串表示执行成功
*/
result: string
/**
* 执行完成的交易hash
*/
hash: string
}
/**
* 执行web3合约
*/
export function web3ExecContract(params: Web3ExecContractParams) {
console.log('调用框架方法', 'web3ExecContract', params)
return new Promise<Web3ExecContractResult>((resolve) =>
callNativeAsyncApi('web3ExecContract', params, resolve),
)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment