Skip to content

Commit

Permalink
Merge pull request #116 from CityOfZion/CU-86a5qpcbh
Browse files Browse the repository at this point in the history
CU-86a5qpcbh-BS Lib - Update endpoint reference for Swaps to point to…
  • Loading branch information
thiagocbalducci authored Dec 2, 2024
2 parents 99d57b2 + 5abe0a6 commit 610eca6
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@cityofzion/bs-swap",
"comment": "Remove the API key param",
"type": "patch"
}
],
"packageName": "@cityofzion/bs-swap"
}
5 changes: 2 additions & 3 deletions packages/bs-swap/src/__tests__/SimpleSwapService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ describe('SimpleSwapService', () => {
}

simpleSwapService = new SimpleSwapService({
apiKey: process.env.TEST_SIMPLE_SWAP_API_KEY!,
blockchainServicesByName,
chainsByServiceName: {
neo3: ['neo3'],
Expand Down Expand Up @@ -309,8 +308,8 @@ describe('SimpleSwapService', () => {

it('Should be able to set a valid address', async () => {
await simpleSwapService.init()
const tokenUse = availableTokensToUse.value![0]
const tokenReceive = availableTokensToUse.value![1]
const tokenUse = availableTokensToUse.value![1]
const tokenReceive = availableTokensToUse.value![0]
await simpleSwapService.setTokenToUse(tokenUse)

const account = blockchainServicesByName.neo3.generateAccountFromKey(process.env.TEST_PRIVATE_KEY as string)
Expand Down
10 changes: 4 additions & 6 deletions packages/bs-swap/src/apis/SimpleSwapApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ export class SimpleSwapApi<BSName extends string = string> {
#axios: AxiosInstance
#allCurrenciesMap: Map<string, SimpleSwapApiCurrency<BSName>> = new Map()

constructor(apiKey: string) {
this.#axios = axios.create({ baseURL: 'https://api.simpleswap.io/v3', headers: { 'X-API-KEY': apiKey } })
constructor() {
this.#axios = axios.create({ baseURL: 'https://4b6s1fv9b6.execute-api.us-east-1.amazonaws.com/Prod' })
}

#getTokenFromCurrency(
currency: SimpleSwapApiCurrencyResponse,
options: Omit<SimpleSwapServiceInitParams<BSName>, 'apiKey'>
options: SimpleSwapServiceInitParams<BSName>
): SimpleSwapApiCurrency<BSName> | undefined {
if (!currency.ticker || !currency.network || !currency.image || !currency.name || !currency.validationAddress) {
return
Expand Down Expand Up @@ -70,9 +70,7 @@ export class SimpleSwapApi<BSName extends string = string> {
}
}

async getCurrencies(
options: Omit<SimpleSwapServiceInitParams<BSName>, 'apiKey'>
): Promise<SimpleSwapApiCurrency<BSName>[]> {
async getCurrencies(options: SimpleSwapServiceInitParams<BSName>): Promise<SimpleSwapApiCurrency<BSName>[]> {
if (this.#allCurrenciesMap.size) {
return Array.from(this.#allCurrenciesMap.values())
}
Expand Down
4 changes: 2 additions & 2 deletions packages/bs-swap/src/helpers/SimpleSwapServiceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { SimpleSwapApi } from '../apis/SimpleSwapApi'
export class SimpleSwapServiceHelper<BSName extends string = string> implements SwapServiceHelper {
#api: SimpleSwapApi<BSName>

constructor(apiKey: string) {
this.#api = new SimpleSwapApi(apiKey)
constructor() {
this.#api = new SimpleSwapApi()
}

async getStatus(id: string): Promise<SwapServiceStatusResponse> {
Expand Down
2 changes: 1 addition & 1 deletion packages/bs-swap/src/services/SimpleSwapService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export class SimpleSwapService<BSName extends string = string> implements SwapSe

constructor(params: SimpleSwapServiceInitParams<BSName>) {
this.eventEmitter = new EventEmitter() as TypedEmitter<SwapServiceEvents>
this.#api = new SimpleSwapApi(params.apiKey)
this.#api = new SimpleSwapApi()
this.#blockchainServicesByName = params.blockchainServicesByName
this.#chainsByServiceName = params.chainsByServiceName
}
Expand Down
1 change: 0 additions & 1 deletion packages/bs-swap/src/types/simpleSwap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { BlockchainService, SwapServiceToken } from '@cityofzion/blockchain-service'

export type SimpleSwapServiceInitParams<BSName extends string = string> = {
apiKey: string
blockchainServicesByName: Record<BSName, BlockchainService<BSName>>
chainsByServiceName: Partial<Record<BSName, string[]>>
}
Expand Down

0 comments on commit 610eca6

Please sign in to comment.