本文整理汇总了TypeScript中jQuery.Deferred.reject方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Deferred.reject方法的具体用法?TypeScript Deferred.reject怎么用?TypeScript Deferred.reject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jQuery.Deferred
的用法示例。
在下文中一共展示了Deferred.reject方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: importWallet
/**
* import an account wallet from server using a private key
* @param {string} privateKey - the private key of the account being imported
* @returns {Promise} Promise object containing boolean - if imported successfully or not
*/
importWallet(privateKey): Promise<any> {
this.startLoading()
var deferred = new $.Deferred()
if (!!(privateKey.match(/[0-9a-fA-F]{64}/)) == false) {
deferred.reject({
error: 'Invalid private key.'
})
return deferred.promise()
}
if (typeof(privateKey) == 'string') privateKey = new Buffer(privateKey, 'hex')
// check if private key valid
try {
if (secp256k1.privateKeyVerify(privateKey)) {
let addr = this.getAddressFromPrivateKey(privateKey)
// get balance from API
let that = this
this.node.getBalance({address: addr}, function(err, data) {
if (err || data.error) {
deferred.reject({error: err})
} else {
that.userWallet = {
address: addr,
balance: data.result.balance,
nonce: data.result.nonce,
privateKey: privateKey.toString('hex')
}
deferred.resolve({
result: true
})
}
that.endLoading()
})
} else {
deferred.reject({
error: 'Invalid private key.'
})
this.endLoading()
}
} catch (e) {
deferred.reject({
error: e
})
this.endLoading()
}
return deferred.promise()
}
示例2:
that.node.getLatestTxBlock(function(err, data2) {
if (err || !data2.result) {
deferred.reject(err)
} else {
deferred.resolve({
networkId: data1.result,
latestTxBlock: data2.result.header.BlockNum
})
}
})
示例3: function
this.node.createTransaction(txn, function(err, data) {
if (err || data.error) {
deferred.reject(err)
} else {
deferred.resolve({
txId: data.result
})
}
that.endLoading()
})