Skip to content

Commit

Permalink
fix kujira factory IBC tokens (#466)
Browse files Browse the repository at this point in the history
* fix kujira factory IBC tokens

* fix send back and use prefix to detect kujira
  • Loading branch information
alecande11 authored Jul 11, 2023
1 parent efee91d commit a0736a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
8 changes: 7 additions & 1 deletion src/data/queries/ibc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export const useIBCBaseDenoms = (data: { denom: Denom; chainID: string }[]) => {
ibcDenom: denom,
baseDenom: base_denom.startsWith("cw20:")
? base_denom.replace("cw20:", "")
: // fix for kujira factory tokens
base_denom.startsWith("factory:")
? base_denom.replaceAll(":", "/")
: base_denom,
chainIDs: chains,
channels,
Expand All @@ -110,7 +113,10 @@ export const useIBCBaseDenoms = (data: { denom: Denom; chainID: string }[]) => {
}

export function calculateIBCDenom(baseDenom: string, path: string) {
if (!path) return baseDenom
if (!path)
return baseDenom.startsWith("factory:")
? baseDenom.replaceAll(":", "/")
: baseDenom

const assetString = [
path,
Expand Down
13 changes: 10 additions & 3 deletions src/pages/wallet/IbcSendBackTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ function IbcSendBackTx({ token, chainID }: Props) {
const { errors } = formState
const { input } = watch()
const queryClient = useQueryClient()
const networks = useNetwork()

const [step, setStep] = useState<number>(0)
const [isLoading, setIsLoading] = useState<boolean>(false)
Expand Down Expand Up @@ -122,6 +123,8 @@ function IbcSendBackTx({ token, chainID }: Props) {
}
}

const isKujira = networks[ibcDetails?.chainIDs[0] ?? ""]?.prefix === "kujira"

useEffect(() => {
// around 3 minutes with a 10 seconds interval
let maxIterations = 18
Expand Down Expand Up @@ -160,7 +163,9 @@ function IbcSendBackTx({ token, chainID }: Props) {
() =>
ibcDetails &&
calculateIBCDenom(
ibcDetails.baseDenom,
isKujira
? ibcDetails.baseDenom?.replaceAll("/", ":")
: ibcDetails.baseDenom,
ibcDetails.channels
.slice(0, ibcDetails.channels.length - step)
.reduce(
Expand All @@ -171,7 +176,7 @@ function IbcSendBackTx({ token, chainID }: Props) {
""
)
),
[step, ibcDetails]
[step, ibcDetails, isKujira]
)

const chains = useMemo(
Expand Down Expand Up @@ -234,7 +239,9 @@ function IbcSendBackTx({ token, chainID }: Props) {
onChangeMax,
onPost: () => {
const nextDenom = calculateIBCDenom(
ibcDetails?.baseDenom ?? "",
(isKujira
? ibcDetails?.baseDenom?.replaceAll("/", ":")
: ibcDetails?.baseDenom) ?? "",
(ibcDetails?.channels ?? [])
.slice(0, (ibcDetails?.channels.length ?? 0) - step - 1)
.reduce(
Expand Down

0 comments on commit a0736a3

Please sign in to comment.