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

CU-86a5qpcbh-BS Lib - Update endpoint reference for Swaps to point to… #116

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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