// a WalletBridge is implemented on renderer side.
// this is an abstraction on top of libcore / ethereumjs / ripple js / ...
// that would directly be called from UI needs.
exporttypeDeviceId=string// for now it's just usb path
exporttypeObserver<T>={
next:T=>void,
complete:()=>void,
error:(?Error)=>void,
}
exporttypeSubscription={
unsubscribe:()=>void,
}
exporttypeEditProps<Transaction>={
account:Account,
value:Transaction,
onChange:Transaction=>void,
}
exportinterfaceWalletBridge<Transaction>{
// in "import"/"recover" step, we need a way to scan all accounts from the device
// for a given currency.
// deviceId currently is the device path.
// observer is an Observer of Account object. Account are expected to be `archived` by default because we want to import all and opt-in on what account to use.
// the scan can stop once all accounts are discovered.
// the function returns a Subscription and you MUST stop everything if it is unsubscribed.
scanAccountsOnDevice(
currency:Currency,
deviceId:DeviceId,
observer:Observer<Account>,
):Subscription;
// synchronize an account. meaning updating the account object with latest state.
// function receives the initialAccount object so you can actually know what the user side currently have
// then you must emit one or more updater functions to inform data changes.
// an update function is just a Account => Account that perform the changes (to avoid race condition issues)
// this can emit new version of the account. typically these field can change over time:
// operations if there are new ones (prepended), balance, blockHeight, ...
// the synchronize can stop once everything is up to date. it is the user side responsability to start it again.
// we should be able to interrupt the Subscription but we'll leave this usecase for later. if you don't support interruption, please `console.warn`
// Implement an optimistic response for signAndBroadcast.
// you likely should add the operation in account.pendingOperations but maybe you want to clean it (because maybe some are replaced / cancelled by this one?)