-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NO CHANGELOG][Add Funds Widget] Add funds/squid config (#2178)
Co-authored-by: Mimi Tran <[email protected]>
- Loading branch information
1 parent
d2983af
commit 8796bda
Showing
6 changed files
with
71 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
packages/checkout/widgets-lib/src/widgets/add-funds/context/AddFundsContextProvider.tsx
This file was deleted.
Oops, something went wrong.
33 changes: 27 additions & 6 deletions
33
packages/checkout/widgets-lib/src/widgets/add-funds/hooks/useSquid.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,43 @@ | ||
import { Squid } from '@0xsquid/sdk'; | ||
import { useEffect, useState } from 'react'; | ||
import { Checkout, SquidConfig } from '@imtbl/checkout-sdk'; | ||
import { useCallback, useEffect, useState } from 'react'; | ||
import { SQUID_SDK_BASE_URL } from '../utils/config'; | ||
|
||
export const useSquid = () => { | ||
export const useSquid = (checkout: Checkout) => { | ||
const [squid, setSquid] = useState<Squid | null>(null); | ||
|
||
const squidConfig = useCallback(async (): Promise< | ||
SquidConfig | undefined | ||
> => { | ||
try { | ||
return (await checkout?.config?.remote.getConfig('squid')) as SquidConfig; | ||
} catch (err: any) { | ||
// eslint-disable-next-line no-console | ||
console.error('Unable to fetch squid config: ', err); | ||
} | ||
return undefined; | ||
}, [checkout]); | ||
|
||
useEffect(() => { | ||
if (squid) { | ||
if (squid || !squidConfig) { | ||
return; | ||
} | ||
|
||
const initialiseSquid = async () => { | ||
const squidSDK = null; | ||
const config = await squidConfig(); | ||
|
||
if (!config?.integratorId) return; | ||
|
||
const squidSDK = new Squid({ | ||
baseUrl: SQUID_SDK_BASE_URL, | ||
integratorId: config.integratorId, | ||
}); | ||
|
||
await squidSDK.init(); | ||
setSquid(squidSDK); | ||
}; | ||
|
||
initialiseSquid(); | ||
}, []); | ||
}, [squidConfig]); | ||
|
||
return squid; | ||
}; |