-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update client to use injected Axios Instance #22
base: main
Are you sure you want to change the base?
Conversation
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.
2안) class형태로 작성하는 케이스입니다.
이 경우
export const client = new CosmosQueryClient({
baseURL: lcdList["osmosis-1"],
});
위처럼 선언하고 다른 파일에서 import해서 사용할 수 있습니다.
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.
1안은 이전처럼 사용하면됩니다. 다만 baseURL을 받는것이 아니라 axiosConfig를 인자로 받습니다.
baseURL 만 넘기는 경우에는 번거롭진 않겟지만 복잡한 header를 계속 선언하는 경우에는 조금더 번거로울 수 있을거같아요
저는 axios instance 자체를 optional 인 인자로 받고, 이 값이 없을 때만 미리 선언된 |
좋은 의견감사합니다. |
@gnujoow 와 구두로 논의한 내용 정리합니다. Axios Client
사용 예(1안 vs 2안) 👉 1안으로 합의 |
구두로 전달받았습니다! AxiosInstance 를 받는 형태로 간다면 큰 이견 없습니다. 정말 문제가 있더라도 최대 3시간, 보통 그보다 적은 시간 내에 다 해결할 수 있을것 같습니다. dashboard의 client 에서는 Keplr-wallet에서 기존 axios 를 constructor에 추가하는 코드를 전부 날려두어 다른 의존성에 의한 문제가 발생할 것 같지는 않습니다. client 형태로 만드는 것도 매력적이지만, 기존 사용법과 큰 괴리가 없는 형태로 작업하는게 지금은 더 중요할 것 같습니다. RPC 쿼리를 지원해야 할 때 아마 Cosmjs QueryClient(Custom query 등록)를 활용하는 편이 아마 좀 더 빠르게 구현하는 방법이 될 것 같은데 그 때 client 형태로 한 번 만들어봐도 좋을것 같습니다! 뭔가 Cosmjs base 로 작업하다 나중에 좀 더 여유가 생기면 제거하는 방식으로? 작업해보면 좋을것 같아요. |
@junhoyeo @dongwu-kim |
fa65775
to
0667737
Compare
0667737
to
7397596
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.
update된 내용입니다. 중복되는 내용들이 많아서 아래 코멘트를 확인해주세요
todo
- test
- default instance가 필요한 경우를 결정하고 반영하기
discussion
- 2-3개의 쿼리만 동작확인을 했습니다. 전부다 동작하는지 확인하려면 시간이 꽤 걸릴거 같네요.. 테스트코드가 있으면 어떨까 합니다.
- default instance가 필요한 경우가 있을까요?
const client = axios.create({ | ||
baseURL: lcdList["osmosis-1"], | ||
paramsSerializer: { | ||
serialize: (params: Record<string, any>) => { | ||
return stringify(params, { allowDots: true }); | ||
}, | ||
}, | ||
}); | ||
const { getAccounts } = getCosmosQuery(client); |
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.
사용법이 앞으로 위와 같은 방식으로 변경됩니다.
사용되는 서비스에서 AxiosInstance를 만들고 parameter로 전달해주세요.
Axios는 v1.x를 사용해야합니다.
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.
paramsSerializer를 덮어쓰는 방법이 있을지
const msg = JSON.stringify(contractQueryInterface); | ||
const query = Buffer.from(msg).toString("base64"); | ||
|
||
if (isWasmd) { | ||
return ( | ||
await instance.get( | ||
`/cosmwasm/wasm/v1/contract/${contractAddress}/smart/${query}` | ||
) | ||
).data; | ||
} | ||
|
||
return ( | ||
await instance(baseURL).get( | ||
isWasmd | ||
? getWasmDUrlFromObj(contractAddress, contractQueryInterface) | ||
: getUrlFromObj(contractAddress, contractQueryInterface) | ||
) | ||
await instance.get(`/wasm/v1/contract/${contractAddress}/smart/${query}`) |
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.
fyi. @dongwu-kim 정확한 이유는 밝히지 못했는데 getWasmDUrlFromObj
, getUrlFromObj
를 사용헀을 경우 window.formdata를 못찾는다는 런타임에러가 계속 발생하더라구요 해서 위처럼 변경했습니다.
왜 에러가 났는지 모르겠네요 -__ -
const setInstance = <T>(callback: (queryInstance: AxiosInstance) => T) => { | ||
return callback(instance); | ||
}; |
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.
기존 getOsmosisHistoricalQuery
에서는 default instance를 사용하도록 강제되었었는데 다른 query와 마찬가지로 instance를 받아서 사용하도록 변경합니다.
/** | ||
* todo | ||
* make axios call with default instance when instance is not given | ||
*/ |
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.
default instance를 넘겨주려고 헀는데 런타임 에러가 계속 발생해서 이유를 파악중입니다.
2안과 1안에 대해서 각각 코멘트 남겨두었습니다. 아래로 내려가면서 읽어보시면 되겠습니다.
보시고 자유롭게 의견주세요