-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(send): add unified onchain/lightning switch
- Loading branch information
Showing
46 changed files
with
1,733 additions
and
1,579 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,87 +1,82 @@ | ||
import { findlnurl } from '../src/utils/lnurl'; | ||
import { TBitcoinUrl, decodeQRData } from '../src/utils/scanner'; | ||
import { findLnUrl } from '../src/utils/lnurl'; | ||
import { parseUri } from '../src/utils/scanner/scanner'; | ||
import { TBitcoinData } from '../src/utils/scanner/types'; | ||
|
||
describe('QR codes', () => { | ||
it('decodes a bitcoin URI with params', async () => { | ||
const res = await decodeQRData( | ||
const res = await parseUri( | ||
'bitcoin:1P5ZEDWTKTFGxQjZphgWPQUpe554WKDfHQ?amount=0.0005&label=Nakamoto&message=Donation%20for%20project%20xyz', | ||
); | ||
if (res.isErr()) { | ||
throw res.error; | ||
} | ||
const qrData = res.value[0] as TBitcoinUrl; | ||
const qrData = res.value[0] as TBitcoinData; | ||
expect(qrData.network).toEqual('bitcoin'); | ||
expect(qrData.qrDataType).toEqual('bitcoinAddress'); | ||
expect(qrData.sats).toEqual(50000); | ||
expect(qrData.type).toEqual('onchain'); | ||
expect(qrData.amount).toEqual(50000); | ||
expect(qrData.message).toEqual('Donation for project xyz'); | ||
}); | ||
|
||
it('decodes a bitcoin legacy address URI', async () => { | ||
const res = await decodeQRData( | ||
'bitcoin:1P5ZEDWTKTFGxQjZphgWPQUpe554WKDfHQ', | ||
); | ||
const res = await parseUri('bitcoin:1P5ZEDWTKTFGxQjZphgWPQUpe554WKDfHQ'); | ||
if (res.isErr()) { | ||
throw res.error; | ||
} | ||
const qrData = res.value[0] as TBitcoinUrl; | ||
const qrData = res.value[0] as TBitcoinData; | ||
expect(qrData.network).toEqual('bitcoin'); | ||
expect(qrData.qrDataType).toEqual('bitcoinAddress'); | ||
expect(qrData.type).toEqual('onchain'); | ||
}); | ||
|
||
it('decodes a bitcoin wrapped segwit address URI', async () => { | ||
const res = await decodeQRData( | ||
'bitcoin:3DrziWGfPSYWZpmGxL4WytNeXA2mwzEwWJ', | ||
); | ||
const res = await parseUri('bitcoin:3DrziWGfPSYWZpmGxL4WytNeXA2mwzEwWJ'); | ||
if (res.isErr()) { | ||
throw res.error; | ||
} | ||
const qrData = res.value[0] as TBitcoinUrl; | ||
const qrData = res.value[0] as TBitcoinData; | ||
expect(qrData.network).toEqual('bitcoin'); | ||
expect(qrData.qrDataType).toEqual('bitcoinAddress'); | ||
expect(qrData.type).toEqual('onchain'); | ||
}); | ||
|
||
it('decodes a bitcoin native segwit address URI', async () => { | ||
const res = await decodeQRData( | ||
const res = await parseUri( | ||
'bitcoin:bc1qkk0vs43wzsundw37f8xslw69eddwfe24w9pyrg', | ||
); | ||
if (res.isErr()) { | ||
throw res.error; | ||
} | ||
const qrData = res.value[0] as TBitcoinUrl; | ||
const qrData = res.value[0] as TBitcoinData; | ||
expect(qrData.network).toEqual('bitcoin'); | ||
expect(qrData.qrDataType).toEqual('bitcoinAddress'); | ||
expect(qrData.type).toEqual('onchain'); | ||
}); | ||
|
||
it('decodes a plain bitcoin native segwit address', async () => { | ||
const res = await decodeQRData( | ||
'bc1qkk0vs43wzsundw37f8xslw69eddwfe24w9pyrg', | ||
); | ||
const res = await parseUri('bc1qkk0vs43wzsundw37f8xslw69eddwfe24w9pyrg'); | ||
if (res.isErr()) { | ||
throw res.error; | ||
} | ||
const qrData = res.value[0] as TBitcoinUrl; | ||
const qrData = res.value[0] as TBitcoinData; | ||
expect(qrData.network).toEqual('bitcoin'); | ||
expect(qrData.qrDataType).toEqual('bitcoinAddress'); | ||
expect(qrData.type).toEqual('onchain'); | ||
}); | ||
|
||
it('finds lnurl', async () => { | ||
const base = | ||
'lnurl1dp68gurn8ghj7mrww3uxymm59e3xjemnw4hzu7re0ghkcmn4wfkz7urp0ylh2um9wf5kg0fhxycnv9g9w58'; | ||
expect(findlnurl(base)).toEqual(base); | ||
expect(findlnurl(base.toUpperCase())).toEqual(base); | ||
expect(findlnurl('https://site.com/?lightning=' + base)).toEqual(base); | ||
expect(findLnUrl(base)).toEqual(base); | ||
expect(findLnUrl(base.toUpperCase())).toEqual(base); | ||
expect(findLnUrl('https://site.com/?lightning=' + base)).toEqual(base); | ||
expect( | ||
findlnurl('https://site.com/?lightning=' + base.toUpperCase()), | ||
findLnUrl('https://site.com/?lightning=' + base.toUpperCase()), | ||
).toEqual(base); | ||
expect(findlnurl('https://site.com/?nada=nada&lightning=' + base)).toEqual( | ||
expect(findLnUrl('https://site.com/?nada=nada&lightning=' + base)).toEqual( | ||
base, | ||
); | ||
expect( | ||
findlnurl('https://site.com/?nada=nada&lightning=' + base.toUpperCase()), | ||
findLnUrl('https://site.com/?nada=nada&lightning=' + base.toUpperCase()), | ||
).toEqual(base); | ||
expect(findlnurl('bs')).toEqual(null); | ||
expect(findlnurl('https://site.com')).toEqual(null); | ||
expect(findlnurl('https://site.com/?bs=' + base)).toEqual(null); | ||
expect(findlnurl('bitcoin:site.com/?lightning=' + base)).toEqual(base); | ||
expect(findLnUrl('bs')).toEqual(null); | ||
expect(findLnUrl('https://site.com')).toEqual(null); | ||
expect(findLnUrl('https://site.com/?bs=' + base)).toEqual(null); | ||
expect(findLnUrl('bitcoin:site.com/?lightning=' + base)).toEqual(base); | ||
}); | ||
}); |
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
Oops, something went wrong.