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

Implement SupportedAssetStore for bityProvider #5226

Merged
merged 3 commits into from
Nov 13, 2024

Conversation

samholmes
Copy link
Contributor

@samholmes samholmes commented Aug 30, 2024

CHANGELOG

Does this branch warrant an entry to the CHANGELOG?

  • Yes
  • No

Dependencies

none

Requirements

If you have made any visual changes to the GUI. Make sure you have:

  • Tested on iOS device
  • Tested on Android device
  • Tested on small-screen device (iPod Touch)
  • Tested on large-screen device (tablet)

Example JSON

Example is support store for bity.

{
  "*": {
    "AT": true,
    "BE": true,
    "BG": true,
    "CH": true,
    "CZ": true,
    "DK": true,
    "EE": true,
    "FI": true,
    "FR": true,
    "DE": true,
    "GR": true,
    "HU": true,
    "IE": true,
    "IT": true,
    "LV": true,
    "LT": true,
    "LU": true,
    "NL": true,
    "PL": true,
    "PT": true,
    "RO": true,
    "SK": true,
    "SI": true,
    "ES": true,
    "SE": true,
    "HR": true,
    "LI": true,
    "NO": true,
    "SM": true,
    "GB": true,
    "*": {
      "*": {
        "sepa": {
          "bitcoin:null": true,
          "ethereum:null": true,
          "ethereum:a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": true,
          "ethereum:dac17f958d2ee523a2206206994597c13d831ec7": true
        }
      }
    }
  },
  "sell": { "*": { "iso:CHF": { "sepa": true }, "iso:EUR": { "sepa": true } } }
}

@samholmes samholmes force-pushed the sam/fiat-plugin-asset-query branch 2 times, most recently from 4aa99da to 3b55978 Compare August 30, 2024 18:25
Copy link
Member

@paullinator paullinator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request architectural change per phone convo

@samholmes
Copy link
Contributor Author

@paullinator Our phone conversation resulted in the task to come up with the proposal for the ProviderSupportStore interface. I followed up later that day with the following interface proposals:

  1. Provider Asset Store (using Maps)
  2. Provider Asset Store (using objects)

Note: by using Map’s we can use keys like EdgeTokenId (which are not strictly a string type). This will require serialization to/from JSON for document storage on the info server.

Could you confirm that these proposals are approved to implement?

@@ -26,3 +26,77 @@ export const asMaybeContractLocation = asMaybe(
contractAddress: asString
})
)

export const asObjectIn = <K extends string | number | symbol, T>(asKey: Cleaner<K>, asT: Cleaner<T>): Cleaner<{ [k in K]: T }> => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

asKey not used

* @param query A query string used to search for nested nodes (e.g. 'US:CA', 'US:*', '*', etc)
* @returns an array of nodes that match the query
*/
function queryNodes(nodes: InternalTree[], query: string): InternalTree[] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: This routine should have some unit tests. That would've made it easier to review as well.

}
}

for (const tree of nodes) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tree should be node like the 1st for loop

'US:CA': true,
UK: true,
'*': {
'iso:USD': true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the queryGroup separator shouldn't be : since that's used for fiat currencies

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So long as we never have a "iso" entry, then "iso:USD" is treated the same as "isoUSD". The only difference is that you could query against "iso:*" or "iso". We could consider using another delimiter to group, but : matches the same character in JSON which makes it a nice grouping character. We could keep the group character as : and require that plugins use _ instead, so they'd add iso_USD.

'bitcoin:null': true
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a test for conflicting values. ie

{
    "*": {
        "US": true
    },
    "buy": {
        "US": false
    },
    "sell": {
        "US": false
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or

{
    "*": {
        "US": false,
        "US:": true
    }
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what should the API return in these cases. are we order dependent?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to just not allow false since only fromJson would allow that to happen, not the normal api. see comments below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation to having false: ability to disable entries in the info server temporarily. But this is a moot case since there is no way to disable an entire object structure without removing it. So this "feature" is only applicable to leaf nodes. I no longer think the benefit for this feature is worth the tradeoff in ambiguity, so I'll remove false from the data type.

// The JSON-serializable object structure for the provider support tree
type ProviderSupportObject = {
[direction in DirectionKey]:
| boolean
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be | true since it can never really be false

}
}

export const asObjectInOrBoolean = <K extends string | number | symbol, T>(asKey: Cleaner<K>, asT: Cleaner<T>) => asEither(asObjectIn(asKey, asT), asBoolean)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really you want asObjectInOrTrue since you can't create a false entry using the API anyway

for (const fiatKey of fiatNode.keys()) {
if (fiatKey === '*') continue
// Add fiat to fiat map:
fiatProviderAssetMap.fiat[fiatKey] = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fiat values aren't filtered by the payment types

return allowedCurrencyCodes[direction]
return supportedAssets.getFiatProviderAssetMap({
direction,
region: `*`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the actual region

return allowedCurrencyCodes[direction]
return supportedAssets.getFiatProviderAssetMap({
direction,
region: `*`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the actual region

return supportedAssets.getFiatProviderAssetMap({
direction,
region: `*`,
payment: supportedPaymentType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the actually passed in paymentTypes[0]

return supportedAssets.getFiatProviderAssetMap({
direction,
region: `*`,
payment: supportedPaymentType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be the actually passed in paymentTypes[0]

// Unhandled combination not caught by cleaner. Skip to be safe.
if (!isAddCurrencySuccess) console.log('Unhandled Bity supported currency: ', currency)
const crypto = `${pluginId}:${tokenId}`
supportedAssets.add.direction('*').region('*').fiat('*').payment(supportedPaymentType).crypto(crypto)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

direction should be the passed in direction

allowedCurrencyCodes[direction].fiat['iso:' + currency.code.toUpperCase()] = currency
isAddCurrencySuccess = true
const fiatCurrencyCode = 'iso:' + currency.code.toUpperCase()
supportedAssets.add.direction(direction).region('*').fiat(fiatCurrencyCode).payment(supportedPaymentType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're insistently using * for direction vs the actual passed in direction. seems like this will cause issues since you'll add the direction on the first call to getSupportedAssets but on a subsequent call for the opposite direction, you'll return false vs re-querying and filling in the cache

@samholmes samholmes force-pushed the sam/fiat-plugin-asset-query branch 2 times, most recently from f843675 to dcec68e Compare November 5, 2024 23:43
@samholmes samholmes merged commit 85e0a74 into develop Nov 13, 2024
2 checks passed
@samholmes samholmes deleted the sam/fiat-plugin-asset-query branch November 13, 2024 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants