coinbase / coinbase-ios-sdk

Integrate bitcoin into your iOS application with Coinbase
https://www.coinbase.com/
Apache License 2.0
171 stars 67 forks source link

Not all accounts returned #26

Closed imougy closed 2 years ago

imougy commented 7 years ago

The current API only returns one account. We need a way to control that and return all the accounts. I tried hacking it by passing &account=all but I had those issues:- I didn't get the LTC and ETH wallets. The USD wallet was marked with BTC as currency instead of USD. The sample app indicates that very easily. Thanks,

dmitryamiller commented 6 years ago

This is due to 'account' param not being provided in the URL for OAuth authentication page. (more on this here https://developers.coinbase.com/docs/wallet/coinbase-connect/permissions)

I had to enhance coinbase-idk to include this param.

maakle commented 6 years ago

What is the correct scope to access all accounts at once? I so far use this one here from the example app but it only returns me 1 account (BTC).

CoinbaseOAuth.startAuthentication(withClientId: Constants.coinbaseClientID, scope: "balance transactions user", redirectUri: "your.app.coinbase-oauth://coinbase-oauth", meta: nil)

How to I have to set the scope since the syntax from @dmitryamiller link seems like it doesn't apply here and also I haven't found any documentation for the iOS SDK about that?

imougy commented 6 years ago

Known bug. Company is busy counting the money.

maakle commented 6 years ago

@imougy Haha probably, but I mean is this really a bug or is this just bad SDK documentation and there is actually a way?

imougy commented 6 years ago

It is a bug, I only get BTC and USD wallets.

jimijon commented 6 years ago

So what is a developer to do to list the accounts and then all the transactions?

dmitryamiller commented 6 years ago

I have looked more into the official SDK and it turns out that their SDK is using v1 of coinbase API. I had to modify the Pod to point to v2 endpoints and that's the only way you can get it to work

imougy commented 6 years ago

@dmitryamiller Can you post your solution in details please. You mentioned you modified their SDK too, where is that modification. Thanks!

dmitryamiller commented 6 years ago

@imougy since I only modified OAuth and 2 API calls just to suit my needs I have that modified version of SDK locally. Attaching what I have. I assume you know how to add local pods into your project coinbase-sdk.zip

maakle commented 6 years ago

@dmitryamiller would be cool if you could give a bit more instructions and which functions you changed. Maybe we can all learn from that and then use it for our own purposes? Thanks for sharing and the effort!

jimijon commented 6 years ago

I see you changed the string to have v1 to v2. However I am getting an error regarding scopes. How are you configuring yours?

 errors =     (
                {
            id = "invalid_scope";
            message = "Scopes don't match current API version.";
            url = "https://developers.coinbase.com/api#permissions-scopes";
dmitryamiller commented 6 years ago

You are probably using scopes for v1 API. I am hitting v2 API endpoints, so you have to adhere to API v2 standards. All of the permissions can be found here https://developers.coinbase.com/docs/wallet/permissions. I am using the following:

static let scope = "wallet:accounts:read,wallet:user:read,wallet:user:email,wallet:transactions:read"

CoinbaseOAuth.startAuthentication(withClientId: CoinbaseManager.clientId, scope: CoinbaseManager.scope, accountAccess: .all, redirectUri: CoinbaseManager.redirectUrl, meta: nil, layout: nil)

Hope this helps

jimijon commented 6 years ago

Just tried it on the demo app. Swapped out via pods theres with yours. I get the scope error. Did you miss something in your changes that you committed?

jimijon commented 6 years ago

hmm, I re-read your entries and see you only changed certain functions. Indeed, your accounts function does seem to work, however, the example app, only lists one. But the authentication page showed all the wallets.

maakle commented 6 years ago

Actually a shame that after such a long time, still nobody from this company has joined the conversation and helped us. So this is where I'm currently at. First of all thanks @dmitryamiller for your help. It works and I am able to get back all my accounts, though no all info. I uploaded a version of yours here with an edited podspec, so everyone can more easily use v2 with this one here: https://github.com/mattk90/coinbase-v2

For other readers, just put that here into your podfile instead of the official sdk: pod 'coinbase-v2', :git => 'https://github.com/mattk90/coinbase-v2'

Regarding my question, I'm using your scopes as well since I just want to read the account balance. My function looks like this:

    private func retrieveCoinbaseUserDate() {
        let apiClient = Coinbase(oAuthAccessToken: UserDefaultsHelper.coinbaseAuthToken!)

        apiClient?.getAccountsList({ (_ result: Any, nil, _ error: Error?) in

            if error != nil {
                // Could not authenticate.
                print("Could not login in with error \(String(describing: error))")
            } else {
                if let result = result as? [CoinbaseAccount] {
                    for acc in result {
                        let accountName = acc.name
                        let accountBalance = acc.balance
                        let accountID = acc.accountID
                        let nativeBalance = acc.nativeBalance

                        print("Account \(accountID!): \(accountName!): \(accountBalance!) \(accountBalance!.currency!) worth: \(nativeBalance!.amount) \(nativeBalance!.currency)")
//                        self.totalBalance = self.totalBalance + Double(nativeBalance!.amount!)!
//                        self.fiatLabelTotal.text = "\(self.totalBalance) \(nativeBalance!.currency!)"
                    }
                    self.embedvc?.allCoinbaseAccounts = result
                    self.embedvc?.tableView.reloadData()
                }
                self.loadHelper.removeLoadingSpinner(spinner: self.spinner)
            }
        })
    }

But my print statements gives me back nil for all the account balances (I put XXX for the successful retried IDs). See:

Account XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: BCH Wallet: <CoinbaseBalance: 0x1cc031960> BCH worth: nil nil
Account XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: EUR Wallet: <CoinbaseBalance: 0x1cc0310e0> EUR worth: nil nil
Account XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: LTC Wallet: <CoinbaseBalance: 0x1cc02f620> LTC worth: nil nil
Account XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: ETH Wallet: <CoinbaseBalance: 0x1cc030580> ETH worth: nil nil
Account XXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX: BTC Wallet: <CoinbaseBalance: 0x1cc02f280> BTC worth: nil nil

Did something change on the permission or return values? How do you retrieve all the accounts and their information? Maybe you can also share your integrated function to retrieve all the accounts with the information.

maakle commented 6 years ago

@dmitryamiller maybe you could also post your code for retrieving the accounts? That would help a lot!

dmitrymiller commented 6 years ago

@mattk90 i was meaning to reply. I am a bit swamped at work at the moment. But I will post something next week I swear. Meanwhile, I briefly looked at your code. Are you setting the right scope for OAuth?

ahernama commented 6 years ago

I have found a possible solution to this problem by changing the oAuth endpoint (adding the account=all parameter), https://coinbase.com/oauth/authorize?**account=all**&response_type=code.‌..

Found in: (https://stackoverflow.com/questions/48123361/retrieving-all-user-wallets-through-coinbase-ios-sdk)

jwitcig commented 2 years ago

Glad you were able to resolve this one!