File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import { useWalletModal } from '@solana/wallet-adapter-react-ui';
1212import { Connection , VersionedTransaction } from '@solana/web3.js' ;
1313import bs58 from 'bs58' ;
1414import { useMemo } from 'react' ;
15+ import { decodeBase64 } from '../../utils/base64' ;
1516/**
1617 * Hook to create an action adapter using solana's wallet adapter.
1718 *
@@ -64,7 +65,7 @@ export function useActionSolanaWalletAdapter(
6465 signTransaction : async ( txData : string ) => {
6566 try {
6667 const tx = await wallet . sendTransaction (
67- VersionedTransaction . deserialize ( Buffer . from ( txData , 'base64' ) ) ,
68+ VersionedTransaction . deserialize ( decodeBase64 ( txData ) ) ,
6869 finalConnection ,
6970 ) ;
7071 return { signature : tx } ;
Original file line number Diff line number Diff line change 1+ // This approach is written in MDN.
2+ // btoa does not support utf-8 characters. So we need a little bit hack.
3+ export const encodeBase64 = ( buf : ArrayBufferLike ) : string => {
4+ let binary = '' ;
5+ const bytes = new Uint8Array ( buf ) ;
6+ for ( let i = 0 , len = bytes . length ; i < len ; i ++ ) {
7+ binary += String . fromCharCode ( bytes [ i ] ) ;
8+ }
9+ return btoa ( binary ) ;
10+ } ;
11+
12+ // atob does not support utf-8 characters. So we need a little bit hack.
13+ export const decodeBase64 = ( str : string ) : Uint8Array => {
14+ const binary = atob ( str ) ;
15+ const bytes = new Uint8Array ( new ArrayBuffer ( binary . length ) ) ;
16+ const half = binary . length / 2 ;
17+ for ( let i = 0 , j = binary . length - 1 ; i <= half ; i ++ , j -- ) {
18+ bytes [ i ] = binary . charCodeAt ( i ) ;
19+ bytes [ j ] = binary . charCodeAt ( j ) ;
20+ }
21+ return bytes ;
22+ } ;
You can’t perform that action at this time.
0 commit comments