Skip to content

refactor(react): workarounds to allow react native projects to import #156

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
32 changes: 26 additions & 6 deletions react/src/components/Loaders/InlineLoadingBar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,36 @@
import './inlineLoading.css';
import { useEffect, useState } from 'react';

export const InlineLoadingBar = () => {
const [width, setWidth] = useState(0);

/**
* This is a simple animation that will animate the width of the loading bar.
* It will animate from 0 to 100% in 1 second.
* We avoid using CSS animations because they are not supported in React Native.
*/
useEffect(() => {
let animationFrame: number;
let startTime: number;

const animate = (timestamp: number) => {
if (!startTime) startTime = timestamp;
const progress = (timestamp - startTime) % 1000; // 1000ms = 1 second
const newWidth = (progress / 1000) * 100; // Convert to percentage
setWidth(newWidth);
animationFrame = requestAnimationFrame(animate);
};

animationFrame = requestAnimationFrame(animate);
return () => cancelAnimationFrame(animationFrame);
}, []);

return (
<div className="block w-[40px] h-[10px] rounded-[5px] border-darkBlue-80 border-solid p-[1px] bg-transparent">
<div
className="bg-static-emphasized h-full rounded-[5px]"
style={{
animationName: `progress-loading`,
animationDuration: '1000ms',
animationTimingFunction: 'ease-in-out',
animationPlayState: 'running',
animationIterationCount: 'infinite',
width: `${width}%`,
transition: 'width 16ms linear',
}}
/>
</div>
Expand Down
56 changes: 39 additions & 17 deletions react/src/constants/wallets.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,46 @@
import {
CloverWalletAdapter,
Coin98WalletAdapter,
CoinbaseWalletAdapter,
MathWalletAdapter,
PhantomWalletAdapter,
SolflareWalletAdapter,
} from '@solana/wallet-adapter-wallets';

/**
* A list of wallets to display in the wallet connection list.
*
* On SAGA the mobile wallet adapter will be added to the list automatically.
*
* The Wallet Provider should also be smart enough to add any other detected wallets to the list too.
*/
export const DRIFT_WALLET_PROVIDERS = [
new PhantomWalletAdapter(),
new SolflareWalletAdapter(),
new CoinbaseWalletAdapter(),
new MathWalletAdapter(),
new Coin98WalletAdapter(),
new CloverWalletAdapter(),
];
export const DRIFT_WALLET_PROVIDERS = async () => {
const [
{ PhantomWalletAdapter },
{ SolflareWalletAdapter },
{ CoinbaseWalletAdapter },
{ MathWalletAdapter },
{ Coin98WalletAdapter },
{ CloverWalletAdapter },
] = await Promise.all([
// wallet adapters are dynamically imported to prevent mobile from importing it statically, where it is not supported
import('@solana/wallet-adapter-wallets').then((m) => ({
PhantomWalletAdapter: m.PhantomWalletAdapter,
})),
import('@solana/wallet-adapter-wallets').then((m) => ({
SolflareWalletAdapter: m.SolflareWalletAdapter,
})),
import('@solana/wallet-adapter-wallets').then((m) => ({
CoinbaseWalletAdapter: m.CoinbaseWalletAdapter,
})),
import('@solana/wallet-adapter-wallets').then((m) => ({
MathWalletAdapter: m.MathWalletAdapter,
})),
import('@solana/wallet-adapter-wallets').then((m) => ({
Coin98WalletAdapter: m.Coin98WalletAdapter,
})),
import('@solana/wallet-adapter-wallets').then((m) => ({
CloverWalletAdapter: m.CloverWalletAdapter,
})),
]);

return [
new PhantomWalletAdapter(),
new SolflareWalletAdapter(),
new CoinbaseWalletAdapter(),
new MathWalletAdapter(),
new Coin98WalletAdapter(),
new CloverWalletAdapter(),
];
};