Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for v2 apis #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h1 class="panel-title">Personal Auth</h1>
<div class="panel-body">
<p>You can get your personal auth token from the <a href="https://developer.starlingbank.com">Starling Bank developer portal</a>.</p>
<p>You'll be asked to create an account if you don't already have one, and tie it to your Starling account.</p>
<p>It requires <code>account:read</code> and <code>balance:read</code> scopes.</p>
<form id="personal-auth-form">
<div class="form-group">
<input type="text" id="access-token-input" placeholder="Token" class="form-control">
Expand Down
43 changes: 26 additions & 17 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,13 @@ const loadConfig = () => {

if (config.starling.accessToken) {
starling = new Starling({accessToken: config.starling.accessToken})
starling.getBalance().catch(() => {
starling = null
loadPreAuthTray()
}).then(() => {
loadTray()
})

starling.account.getAccounts()
.then(loadTray)
.catch(() => {
starling = null;
loadPreAuthTray()
});
} else {
loadPreAuthTray()
}
Expand Down Expand Up @@ -72,9 +73,14 @@ const updateTray = () => {
return
}

starling.getBalance().then(({data}) => {
starling.account.getAccounts()
.then(({ data: { accounts } }) => accounts[0].accountUid)
.then(accountUid => starling.account.getAccountBalance({ accountUid }))
.then(({ data: { effectiveBalance } }) => {
const effectiveBalanceText = `£${effectiveBalance.minorUnits / 100}`

if (config.starling.displayInStatusbar) {
tray.setTitle(`£${data.effectiveBalance}`)
tray.setTitle(effectiveBalanceText)
} else {
tray.setTitle('')
}
Expand All @@ -83,7 +89,7 @@ const updateTray = () => {
{type: 'checkbox', label: 'Display in statusbar', click: setDisplayInStatusbar, checked: config.starling.displayInStatusbar},
{type: 'separator'},
{label: `Balance`, enabled: false},
{label: ` - £${data.effectiveBalance}`, enabled: false},
{label: ` - ${effectiveBalanceText}`, enabled: false},
{type: 'separator'},
{label: 'Log out', click: logOut},
{label: 'Quit', role: 'quit'}
Expand Down Expand Up @@ -121,15 +127,18 @@ const doPersonalAuth = () => {

ipcMain.on('personal-auth-token', (event, token) => {
starling = new Starling({accessToken: token})
starling.getBalance().then(({data}) => {
config.starling.accessToken = token
storage.set('starling', config.starling, function(error) {
authWindow.hide()
loadTray()

starling.account.getAccounts()
.then(() => {
config.starling.accessToken = token
storage.set('starling', config.starling, (error) => {
authWindow.hide()
loadTray()
})
})
}).catch((error) => {
event.sender.send('personal-auth-error', 'Invalid auth token')
})
.catch(() => {
event.sender.send('personal-auth-error', 'Invalid auth token')
});
})

const logOut = () => {
Expand Down
Loading