Skip to content

浏览器缓存

为避免用户每次使用都要重复导入Keystore文件,JingchangWallet提供了以下方法,通过浏览器的localStorageAPI来实现保存、获得、清空Keystore文件

save

ts
/**
 * save jingchang wallet to local storage.
 *
 * @static
 * @param {IJingchangWalletModel} wallet
 * @memberof JingchangWallet
 */
public static function save(wallet: IJingchangWalletModel): void
/**
 * save jingchang wallet to local storage.
 *
 * @static
 * @param {IJingchangWalletModel} wallet
 * @memberof JingchangWallet
 */
public static function save(wallet: IJingchangWalletModel): void
点我运行代码
const { JingchangWallet } = require('jcc_wallet')

JingchangWallet.save(testKeyStore)
//请去 DevTools -> Appication -> Local Storage 中查看

get

ts
/**
 * get jingchang wallet from local storage
 *
 * @static
 * @returns {(IJingchangWalletModel | null)} return jingchang wallet or null
 * @memberof JingchangWallet
 */
public static function get(): IJingchangWalletModel | null
/**
 * get jingchang wallet from local storage
 *
 * @static
 * @returns {(IJingchangWalletModel | null)} return jingchang wallet or null
 * @memberof JingchangWallet
 */
public static function get(): IJingchangWalletModel | null
点我运行代码
const { JingchangWallet } = require('jcc_wallet')

const keystore = JingchangWallet.get()

console.log(keystore)

clear

ts
/**
 * clear jingchang wallet from local storage
 *
 * @static
 * @memberof JingchangWallet
 */
public static function clear(): void
/**
 * clear jingchang wallet from local storage
 *
 * @static
 * @memberof JingchangWallet
 */
public static function clear(): void
点我运行代码
const { JingchangWallet } = require('jcc_wallet')

JingchangWallet.save(testKeyStore)
let jcKeystore = JingchangWallet.get()
console.log(jcKeystore)

setTimeout(() => {
  JingchangWallet.clear()
  console.log('keystore clear!!!')
  jcKeystore = JingchangWallet.get()
  console.log(jcKeystore)
},1500)

Released under the MIT License.