blob: e322c6727ce8e48797fbe71c5400248b5bfd6f81 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
  | 
import { useEffect, useState } from "preact/hooks";
import * as wxApi from "../wxApi";
export interface BackupDeviceName {
  name: string;
  update: (s:string) => Promise<void>
}
export function useBackupDeviceName(): BackupDeviceName {
  const [status, setStatus] = useState<BackupDeviceName>({
    name: '',
    update: () => Promise.resolve()
  })
  useEffect(() => {
    async function run() {
      //create a first list of backup info by currency
      const status = await wxApi.getBackupInfo()
      async function update(newName: string) {
        await wxApi.setWalletDeviceId(newName)
        setStatus(old => ({ ...old, name: newName }))  
      }
      setStatus({ name: status.deviceId, update })
    }
    run()
  }, [])
  return status
}
 
  |