This repository has been archived by the owner on Feb 22, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
310 additions
and
139 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
README.md | ||
RELEASE.md |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,39 @@ | ||
import { DEFAULT_WEIGHT } from './set-pointer-multiple' | ||
|
||
export const defaultAddressNotFound = | ||
'Fundme.js: default address not found. Use setDefaultAddress(str: string) to set it first.' | ||
export const invalidAddress = 'Fundme.js: Invalid Web Monetization pointer address is given.' | ||
export const addressNotFound = 'Fundme.js: address not found.' | ||
export const addressIsNotAString = 'Fundme.js: address must be a string.' | ||
export const weightNotFound = 'Fundme.js: entries .weight not found.' | ||
export function FundmeError(err: string): string { | ||
return 'Fundme.js: ' + err | ||
} | ||
|
||
export const defaultAddressNotFound = 'default address not found. Use setDefaultAddress(str: string) to set it first.' | ||
export const invalidAddress = 'Invalid Web Monetization pointer address is given.' | ||
export const addressNotFound = 'address not found.' | ||
export const addressIsNotAString = 'address must be a string.' | ||
export const getCurrentPointerAddressMustClientSide = "can't use getCurrentPointerAddress() server-side." | ||
export const weightNotFound = 'entries .weight not found.' | ||
export function weightIsNotANumber(str: string) { | ||
return `Fundme.js: ${str} has weight that is not a number. It has been set to ${DEFAULT_WEIGHT} (default).` | ||
return `${str} has weight that is not a number. It has been set to ${DEFAULT_WEIGHT} (default).` | ||
} | ||
|
||
// about meta tag for Web Monetization API | ||
export const metaTagNotFound = 'Fundme.js: web monetization meta tag is not found.' | ||
export const metaTagNotFound = 'web monetization meta tag is not found.' | ||
export const metaTagMultipleIsFound = | ||
'Fundme.js: multiple <meta name="monetization" /> found - Web Monetization API only support a single meta tag.' | ||
'multiple <meta name="monetization" /> found - Web Monetization API only support a single meta tag.' | ||
|
||
// pointers template | ||
export const noTemplateFound = 'Fundme.js: no monetization template is found.' | ||
export const failParsingTemplate = 'Fundme.js: fails to parse address from <template data-fund></template>.' | ||
export const noTemplateFound = 'no monetization template is found.' | ||
export const failParsingTemplate = 'fails to parse address from <template data-fund></template>.' | ||
export const templateSinglePointerHasWeight = | ||
'Fundme.js: found single <template data-fund></template> but has weight - only address will be parsed.' | ||
'found single <template data-fund></template> but has weight - only address will be parsed.' | ||
|
||
// script json template | ||
export const cannotParseScriptJson = | ||
'Fundme.js: cannot parse JSON from <script fundme>. Make sure it contains a valid JSON.' | ||
export const jsonTemplateIsInvalid = "Fundme.js: found <script fundme> but it's not valid." | ||
export const scriptFundmeIsNotApplicationJson = | ||
'Fundme.js: found <script fundme> but its type is not "application/json"' | ||
export const cannotParseScriptJson = 'cannot parse JSON from <script fundme>. Make sure it contains a valid JSON.' | ||
export const jsonTemplateIsInvalid = "found <script fundme> but it's not valid." | ||
export const scriptFundmeIsNotApplicationJson = 'found <script fundme> but its type is not "application/json"' | ||
|
||
/***************************** | ||
* * | ||
* Server-side fund() * | ||
* * | ||
*****************************/ | ||
export const noUndefinedFundOnServerSide = "can't use fund() with empty parameters in server side." | ||
export const invalidFundmeServerSide = 'invalid fundme parameters on the server-side.' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { isMultiplePointer } from './utils' | ||
import { setPointerSingle } from './set-pointer-single' | ||
import { setPointerFromTemplates } from './set-pointer-template' | ||
import { setPointerMultiple } from './set-pointer-multiple' | ||
import { defaultAddressNotFound, invalidAddress, FundmeError } from './errors' | ||
import { defaultAddress, FundType, setFundType } from './main' | ||
|
||
export function clientSideFund(pointer?: WMAddress, options: fundOptions = {}): FundType { | ||
if (typeof pointer === 'string') { | ||
if (pointer === 'default') { | ||
if (defaultAddress !== undefined) { | ||
if (typeof defaultAddress === 'string') { | ||
setPointerSingle(defaultAddress, options) | ||
} else { | ||
setPointerMultiple(defaultAddress, options) | ||
} | ||
return setFundType(FundType.isDefault) | ||
} else { | ||
throw FundmeError(defaultAddressNotFound) | ||
} | ||
} | ||
setPointerSingle(pointer, options) | ||
return setFundType(FundType.isSingle) | ||
} | ||
|
||
if (isMultiplePointer(pointer)) { | ||
setPointerMultiple(pointer, options) | ||
return setFundType(FundType.isMultiple) | ||
} | ||
|
||
if (pointer === undefined) { | ||
setPointerFromTemplates() | ||
return setFundType(FundType.isFromTemplate) | ||
} | ||
throw FundmeError(invalidAddress) | ||
} | ||
|
||
let forceBrowser: boolean = false | ||
export function forceFundmeOnBrowser() { | ||
forceBrowser = true | ||
} | ||
|
||
export const isBrowser = (options: fundOptions = {}): boolean => { | ||
if (options.force === 'server') return false | ||
|
||
if (forceBrowser || options.force === 'client') { | ||
forceBrowser = false | ||
return true | ||
} | ||
|
||
return require === undefined && module === undefined | ||
} |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { setCurrentPointer } from './main' | ||
import { isMultiplePointer } from './utils' | ||
import { setPointerMultiple } from './set-pointer-multiple' | ||
import { FundmeError, invalidFundmeServerSide } from './errors' | ||
|
||
export function serverSideFund(pointer: WMAddress): string { | ||
if (typeof pointer === 'string') { | ||
setCurrentPointer(pointer) | ||
return pointer | ||
} | ||
|
||
if (isMultiplePointer(pointer)) { | ||
return setPointerMultiple(pointer) | ||
} | ||
|
||
throw FundmeError(invalidFundmeServerSide) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { setWebMonetizationPointer } from './utils' | ||
import { setCurrentPointer } from './main' | ||
import { setCurrentPointer, isBrowser } from './main' | ||
|
||
export function setPointerSingle(pointer: string): void { | ||
export function setPointerSingle(pointer: string, options: fundOptions = {}): void { | ||
setCurrentPointer(pointer) | ||
setWebMonetizationPointer(pointer) | ||
if (isBrowser(options)) { | ||
setWebMonetizationPointer(pointer) | ||
} | ||
} |
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.