|
|
@ -1,34 +1,30 @@ |
|
|
|
export default function getRestrictedMethods ({ getIdentities, getKeyringAccounts }) { |
|
|
|
export default function getRestrictedMethods ({ getIdentities, getKeyringAccounts }) { |
|
|
|
return { |
|
|
|
return { |
|
|
|
'eth_accounts': { |
|
|
|
'eth_accounts': { |
|
|
|
method: (_, res, __, end) => { |
|
|
|
method: async (_, res, __, end) => { |
|
|
|
getKeyringAccounts() |
|
|
|
try { |
|
|
|
.then((accounts) => { |
|
|
|
const accounts = await getKeyringAccounts() |
|
|
|
const identities = getIdentities() |
|
|
|
const identities = getIdentities() |
|
|
|
res.result = accounts |
|
|
|
res.result = accounts.sort((firstAddress, secondAddress) => { |
|
|
|
.sort((firstAddress, secondAddress) => { |
|
|
|
if (!identities[firstAddress]) { |
|
|
|
if (!identities[firstAddress]) { |
|
|
|
throw new Error(`Missing identity for address ${firstAddress}`) |
|
|
|
throw new Error(`Missing identity for address ${firstAddress}`) |
|
|
|
} else if (!identities[secondAddress]) { |
|
|
|
} else if (!identities[secondAddress]) { |
|
|
|
throw new Error(`Missing identity for address ${secondAddress}`) |
|
|
|
throw new Error(`Missing identity for address ${secondAddress}`) |
|
|
|
} else if (identities[firstAddress].lastSelected === identities[secondAddress].lastSelected) { |
|
|
|
} else if (identities[firstAddress].lastSelected === identities[secondAddress].lastSelected) { |
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
} else if (identities[firstAddress].lastSelected === undefined) { |
|
|
|
} else if (identities[firstAddress].lastSelected === undefined) { |
|
|
|
return 1 |
|
|
|
return 1 |
|
|
|
} else if (identities[secondAddress].lastSelected === undefined) { |
|
|
|
} else if (identities[secondAddress].lastSelected === undefined) { |
|
|
|
return -1 |
|
|
|
return -1 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return identities[secondAddress].lastSelected - identities[firstAddress].lastSelected |
|
|
|
return identities[secondAddress].lastSelected - identities[firstAddress].lastSelected |
|
|
|
}) |
|
|
|
|
|
|
|
end() |
|
|
|
|
|
|
|
}) |
|
|
|
}) |
|
|
|
.catch( |
|
|
|
end() |
|
|
|
(err) => { |
|
|
|
} catch (err) { |
|
|
|
res.error = err |
|
|
|
res.error = err |
|
|
|
end(err) |
|
|
|
end(err) |
|
|
|
}, |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
}, |
|
|
|
} |
|
|
|
} |
|
|
|