-
Notifications
You must be signed in to change notification settings - Fork 258
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
Conversation
4aa99da
to
3b55978
Compare
There was a problem hiding this 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
@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: 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? |
3b55978
to
0860244
Compare
@@ -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 }> => { |
There was a problem hiding this comment.
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[] { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
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
}
}
There was a problem hiding this comment.
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
}
}
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
src/util/cleaners.ts
Outdated
} | ||
} | ||
|
||
export const asObjectInOrBoolean = <K extends string | number | symbol, T>(asKey: Cleaner<K>, asT: Cleaner<T>) => asEither(asObjectIn(asKey, asT), asBoolean) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: `*`, |
There was a problem hiding this comment.
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: `*`, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
f843675
to
dcec68e
Compare
dcec68e
to
ffb97f9
Compare
ffb97f9
to
75220b7
Compare
75220b7
to
0fd52f5
Compare
CHANGELOG
Does this branch warrant an entry to the CHANGELOG?
Dependencies
noneRequirements
If you have made any visual changes to the GUI. Make sure you have:
Example JSON
Example is support store for bity.