diff --git a/lib/ui/settings/bank_accounts.dart b/lib/ui/settings/bank_accounts.dart index b8ece29ff..526cf92b1 100644 --- a/lib/ui/settings/bank_accounts.dart +++ b/lib/ui/settings/bank_accounts.dart @@ -112,7 +112,7 @@ class _BankAccountsState extends State { Expanded( child: AppButton( label: localization.refresh.toUpperCase(), - onPressed: () => viewModel.onConnectAccounts(), + onPressed: () => viewModel.onRefreshAccounts(), iconData: Icons.refresh, ), ), diff --git a/lib/ui/settings/bank_accounts_vm.dart b/lib/ui/settings/bank_accounts_vm.dart index 34a35253b..ccdf0ca95 100644 --- a/lib/ui/settings/bank_accounts_vm.dart +++ b/lib/ui/settings/bank_accounts_vm.dart @@ -48,6 +48,7 @@ class BankAccountsVM { @required this.onCompanyChanged, @required this.onSavePressed, @required this.onConnectAccounts, + @required this.onRefreshAccounts, }); static BankAccountsVM fromStore(Store store) { @@ -58,6 +59,22 @@ class BankAccountsVM { company: state.uiState.settingsUIState.company, onCompanyChanged: (company) => store.dispatch(UpdateCompany(company: company)), + onRefreshAccounts: () { + final webClient = WebClient(); + final credentials = state.credentials; + final url = '${credentials.url}/bank_integrations/refresh_accounts'; + + store.dispatch(StartSaving()); + + webClient.post(url, credentials.token).then((dynamic response) { + store.dispatch(StopSaving()); + print('## RESPONSE: $response'); + }).catchError((dynamic error) { + store.dispatch(StopSaving()); + showErrorDialog( + context: navigatorKey.currentContext, message: '$error'); + }); + }, onConnectAccounts: () { final webClient = WebClient(); final credentials = state.credentials; @@ -96,4 +113,5 @@ class BankAccountsVM { final CompanyEntity company; final Function(CompanyEntity) onCompanyChanged; final Function onConnectAccounts; + final Function onRefreshAccounts; }